autofixture

AutoFixture: Unable to create an instance, probably no public constructor

扶醉桌前 提交于 2021-02-07 21:12:46
问题 I seem to be having an issue, I have a class (LoginService) that accepts in the constructor an IUser. This is for performing integration tests rather than unit tests, for that reason I don't want to MOCK these, I have some Unit Tests already and they are working great using Moq with fixture. I setup my fixture:- var fixture = new Fixture(); And then I want to be able to freeze a version of the IUser, I have tried the following but I couldn't get it to work, it complains that it can't create

AutoFixture: Unable to create an instance, probably no public constructor

时光怂恿深爱的人放手 提交于 2021-02-07 21:10:42
问题 I seem to be having an issue, I have a class (LoginService) that accepts in the constructor an IUser. This is for performing integration tests rather than unit tests, for that reason I don't want to MOCK these, I have some Unit Tests already and they are working great using Moq with fixture. I setup my fixture:- var fixture = new Fixture(); And then I want to be able to freeze a version of the IUser, I have tried the following but I couldn't get it to work, it complains that it can't create

AutoFixture: Unable to create an instance, probably no public constructor

丶灬走出姿态 提交于 2021-02-07 21:09:14
问题 I seem to be having an issue, I have a class (LoginService) that accepts in the constructor an IUser. This is for performing integration tests rather than unit tests, for that reason I don't want to MOCK these, I have some Unit Tests already and they are working great using Moq with fixture. I setup my fixture:- var fixture = new Fixture(); And then I want to be able to freeze a version of the IUser, I have tried the following but I couldn't get it to work, it complains that it can't create

AutoFixture and interfaces

此生再无相见时 提交于 2021-02-07 11:22:33
问题 Let's say I have interface: public interface IFoo { int Bar1 { get; set; } int Bar2 { get; set; } } If IFoo was class, I could write: fixture.CreateAnonymous<IFoo>(); and the result will have numbers set for Bar1 and Bar2 . But how to do this with interface? I tried to use AutoMoqCustomization but this seems to be for properties with interface type and not interfaces itself. I am looking for automated way like CreateAnonymous is for classes. Currenlty I am creating interface mock and setuping

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

Autofixture Constructer injection lazy loading

牧云@^-^@ 提交于 2021-01-28 03:22:34
问题 I am using autofixture in my unit tests and it is great the way that it works as an automocker. However I have a problem when injecting a lazy loaded object into my class. For example: public class MyClass : IMyClass { private Lazy<IMyInjectedClass> _myInjectedClassLazy; private IMyInjectedClass _myInjectedClass { get { return _myInjectedClassLazy.Value; } } public MyClass(Lazy<IMyInjectedClass> injectedClass) { _myInjectedClassLazy = _myInjectedClass; } public void DoSomething() {

.NET core write better unit tests with Xunit + Autofixture + Moq

◇◆丶佛笑我妖孽 提交于 2020-12-13 07:07:40
问题 In .NET Core for unit testing, I'm using Xunit, Moq, and Autofixture. But even with them, I see that my unit tests become complicated and take time. Maybe someone could tell me if there are any ways to make this test smaller? [Fact] public async Task Verify_NotAuthorised_NoServiceSendInvoked() { // Arrange var fixture = new Fixture() .Customize(new AutoMoqCustomization()); var sut = fixture.Create<VerificationService>(); var mockApiBuilder = fixture.Freeze<Mock<IApiEntityBuilder>>(); //init

.NET core write better unit tests with Xunit + Autofixture + Moq

自闭症网瘾萝莉.ら 提交于 2020-12-13 07:02:46
问题 In .NET Core for unit testing, I'm using Xunit, Moq, and Autofixture. But even with them, I see that my unit tests become complicated and take time. Maybe someone could tell me if there are any ways to make this test smaller? [Fact] public async Task Verify_NotAuthorised_NoServiceSendInvoked() { // Arrange var fixture = new Fixture() .Customize(new AutoMoqCustomization()); var sut = fixture.Create<VerificationService>(); var mockApiBuilder = fixture.Freeze<Mock<IApiEntityBuilder>>(); //init

Approach to generate Random specimen based on Customization

我是研究僧i 提交于 2020-06-28 02:05:51
问题 I want to be able to generate distinct values based on a ICustomization using ISpecimenBuilder.CreateMany . I was wondering what would be the best solution since AutoFixture will generate the same values for all entities. public class FooCustomization : ICustomization { public void Customize(IFixture fixture) { var specimen = fixture.Build<Foo>() .OmitAutoProperties() .With(x => x.CreationDate, DateTime.Now) .With(x => x.Identifier, Guid.NewGuid().ToString().Substring(0, 6)) // Should gen

Why doesn't simple test pass using AutoFixture Freeze, SemanticComparison Likeness and CreateProxy?

半世苍凉 提交于 2020-03-01 01:56:10
问题 I'm trying to understand how to use the CreateProxy() feature of Likeness<T>() using two instances of a simple class. public class Band { public string Strings { get; set; } public string Brass { get; set; } } With the following test, I use a Fixture to Create<T> a Band instance with values for the two string properties. [Fact] public void Equality_Behaves_As_Expected() { // arrange var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var original = fixture.Create<Band>