automoq

When setting up a custom AutoDataAttribute for auto mocking, what's the proper syntax to tell AutoFixture to ignore all recursive structures?

吃可爱长大的小学妹 提交于 2021-01-29 03:09:46
问题 I have xUnit/Moq/AutoFixture successfully working together so that I am auto mocking objects via test method input parameters. I created a custom [AutoMoqData] attribute which I use on every test. Here's the code for the attribute: using System.Linq; using AutoFixture; using AutoFixture.AutoMoq; using AutoFixture.Xunit2; namespace Shared.TestResources.AutoFixture { public class AutoMoqDataAttribute : AutoDataAttribute { public AutoMoqDataAttribute() : base(() => new Fixture().Customize(new

Automocking Web Api 2 controller

我的梦境 提交于 2019-12-17 21:56:35
问题 I am trying to auto mock ApiController class in my test cases. It worked perfectly when I was using WebApi1. I started to use WebApi2 on the new project and I am getting this exception thrown after I try to run my new tests: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: pCertContext is an invalid handle. at System.Security.Cryptography.CAPI.CertSetCertificateContextProperty

Using AutoMoq methods with generic signatures

拟墨画扇 提交于 2019-12-02 05:29:58
问题 I'm currently using a test framework I've thrown together using xUnit, AutoMoq, AutoFixture, and AutoFixture.XUnit2. I'm running into issues with mocking methods with generic signatures. AutoFixture seems to handle generic items just fine. If I ask for a CustomeObject<Task<List<Task<string>>>> , or some other ridiculous nested generic type, it seems to generate them as expected all the way down to the last node. However, if I have an interface like this: public interface ITestInterface{ T Get

Using AutoMoq methods with generic signatures

拜拜、爱过 提交于 2019-12-02 00:18:40
I'm currently using a test framework I've thrown together using xUnit, AutoMoq, AutoFixture, and AutoFixture.XUnit2. I'm running into issues with mocking methods with generic signatures. AutoFixture seems to handle generic items just fine. If I ask for a CustomeObject<Task<List<Task<string>>>> , or some other ridiculous nested generic type, it seems to generate them as expected all the way down to the last node. However, if I have an interface like this: public interface ITestInterface{ T Get<T>(); } and then try to call the method from the mock I got from AutoMoq it just returns null. So, for

Automocking Web Api 2 controller

纵饮孤独 提交于 2019-11-28 17:14:41
I am trying to auto mock ApiController class in my test cases. It worked perfectly when I was using WebApi1. I started to use WebApi2 on the new project and I am getting this exception thrown after I try to run my new tests: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: pCertContext is an invalid handle. at System.Security.Cryptography.CAPI.CertSetCertificateContextProperty(SafeCertContextHandle pCertContext, UInt32 dwPropId, UInt32 dwFlags, SafeLocalAllocHandle

AutoFixture with AutoMoq and concrete object injection

℡╲_俬逩灬. 提交于 2019-11-28 05:07:40
问题 I'm facing a strange problem related to AutoFixture and AutoMoqCustomization and how it deals with automocking of concrete classes. I suspect that I'm not using it very well but would like to know what's the problem. First of all her's some context. Let's say I have a class that I want to test : public class IdentityApplicationService { public IdentityApplicationService( TenantProvisioningService tenantProvisioningService) { // guard clause etc. _tenantProvisioningService =

AutoFixture fails to CreateAnonymous MVC Controller

妖精的绣舞 提交于 2019-11-27 09:16:39
The code: IFixture fixture = new Fixture().Customize(new AutoMoqCustomization()); fixture.Customize<ViewDataDictionary>(c => c.Without(x => x.ModelMetadata)); var target = fixture.CreateAnonymous<MyController>(); the Exception: System.Reflection.TargetInvocationException: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The method or operation is not implemented. MyController() takes 3 parameters. I've tried the fix described in the answer here but it wouldn't work. Nikos Baxevanis As it seems , when

AutoFixture fails to CreateAnonymous MVC Controller

狂风中的少年 提交于 2019-11-26 14:37:06
问题 The code: IFixture fixture = new Fixture().Customize(new AutoMoqCustomization()); fixture.Customize<ViewDataDictionary>(c => c.Without(x => x.ModelMetadata)); var target = fixture.CreateAnonymous<MyController>(); the Exception: System.Reflection.TargetInvocationException: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The method or operation is not implemented. MyController() takes 3 parameters. I've