daveoftheparty / speedy-moq

Generate boilerplate code for Moq in C#
MIT License
1 stars 0 forks source link

generated return setup needs a value #17

Closed daveoftheparty closed 3 years ago

daveoftheparty commented 3 years ago

Currently, the code generator returns a block that looks something like this:

var diagnoser = new Mock<IDiagnoser>();
Expression<Func<IDiagnoser, Task<IEnumerable<Diagnostic>>>> getDiagnosticsAsync = x => x.GetDiagnosticsAsync(It.IsAny<TextDocumentItem>());
diagnoser
    .Setup(getDiagnosticsAsync)
    .Returns((TextDocumentItem item) =>
    {
        return;
    }
    );

diagnoser.Verify(getDiagnosticsAsync, Times.Once);

That leads to lots of red squiggly lines, and, 3 errors (may be different depending on the generated text.) Currently those errors are:

It looks like we'll simply be able to change the generator to add the word "default", as in the example below. That should also save us from having to actually do symbol parsing on nested generic or nullable types.

var diagnoser = new Mock<IDiagnoser>();
Expression<Func<IDiagnoser, Task<IEnumerable<Diagnostic>>>> getDiagnosticsAsync = x => x.GetDiagnosticsAsync(It.IsAny<TextDocumentItem>());
diagnoser
    .Setup(getDiagnosticsAsync)
    .Returns((TextDocumentItem item) =>
    {
        return default;
    }
    );

diagnoser.Verify(getDiagnosticsAsync, Times.Once);