Using AutoMoq Methods with Common Signatures

I am currently using a test environment that I have selected using xUnit, AutoMoq, AutoFixture and AutoFixture.XUnit2. I am facing problems with bullying methods with common signatures.

AutoFixture seems to do a great job with the overall details. If I ask CustomeObject<Task<List<Task<string>>>> or some other ridiculous nested generic type, it seems to generate them as expected, right down to the last node.

However, if I have an interface like this:

 public interface ITestInterface{ T Get<T>(); } 

and then try calling the method from the layout I got from AutoMoq, it just returns null. So for example:

 [Theory] [MyAutoDaqaAttribute] public async Task ATest( Mock<ITestInterface> service ) { var result = service.Object.Get<string>(); } 

As a result, the code will be zero. It seems strange to me. Should I go to auto-alignment and try to create a value of type T, i.e. New line? It looks like Autofixture has already shown that it can do a great job with generics.

Or do you always need to manually configure some mock method that has a common signature?

+2
source share
1 answer

Marked objects do not go through AutoFixture by default. You can use AutoConfiguredMoqCustomization for this.

However, in your case, the method is general. AutoConfiguredMoqCustomization does not work with general methods, you will have to manually configure the method.

Extracted from here :

AutoConfiguredMoqCustomization does not configure common methods either. However, you can easily install them using the ReturnsUsingFixture extension ReturnsUsingFixture :

 converter.Setup(x => x.Convert<double>("10.0")) .ReturnsUsingFixture(fixture); 
+4
source

Source: https://habr.com/ru/post/1440645/


All Articles