autofixture

How to configure AutoFixture to use an enum value as seed when creating many of a certain type?

风流意气都作罢 提交于 2019-12-07 01:59:35
问题 I have the following types: public enum Status { Online, Offline } public class User { private readonly Status _status; public User(Status status) { _status = status; } public Status Status {get {return _status; }} public string Name {get;set;} } Now, when executing fixture.CreateMany<User> I want AutoFixture to return two Users , one per status. All other properties - like Name - should be filled with anonymous data. Question: How to configure AutoFixture to do this? I tried the following

Setting property value on child instance to a fixed value with Autofixture

て烟熏妆下的殇ゞ 提交于 2019-12-06 17:00:25
问题 Is it possible to assign a fixed value to a property on a child instance when building a parent with Autofixture? It will add default values to all the properties on the child instance like a charm, but I would like to override and assign a specific value to one of the properties on the child instance. Given this parent/child relationship: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public Address Address { get; set; } } public class

Fixture.CreateAnonymous method kills test runner process with an error (AutoFixture) when using AutoMoq to create a Controller

不打扰是莪最后的温柔 提交于 2019-12-06 15:00:23
I'm trying to use the AutoMoqCustomization with AutoFixture to create an ASP.NET MVC2 Controller in a unit test via the Fixture.CreateAnonymous method. I've tried in both xUnit under TestDriven.NET, the xUnit test GUI and in MSTest and all have the same result: a massive failure of the process running the test. On Windows 7 x64 if that matters. To reproduce, simply create a new ASP.NET MVC2 project, add the references to AutoFixture, AutoMoq and Moq (3.1, as per the AutoMoq source) and try the below (repro VS2010 MVC2 project link below): [TestMethod] public void Index() { var fixture = new

How to use AutoFixture in this case?

心不动则不痛 提交于 2019-12-06 10:49:02
I have the following code: var boundArgument = new BoundArgumentOption { PatientId = patientId }; var mockRepositoryFactory = A.Fake<IRepositoryFactory>(); var sut = new HtmlOutputBuilder(mockRepositoryFactory); var patientRecord = // Some record; var mockRepository = A.Fake<IRepository>(); A.CallTo(() => mockRepository.Get(boundArgument)).Returns(patientRecord); A.CallTo(() => mockRepositoryFactory.Create(boundArgument)).Returns(mockRepository); string actualResult = sut.BuildReport(boundArgument); actualResult.Should().Be(expectedHtmlContent); and that passes the test. Then I tried using

Does this test make proper use of AutoFixture and Moq?

半腔热情 提交于 2019-12-05 18:19:42
问题 Does this test make proper use of AutoFixture and Moq? Is it written as concisely as possible? The test fails, as expected, and passes after writing the correct implementation. [Fact] public void CustomerPropertyIsCorrect() { var fixture = new AutoMoqFixture(); var expected = fixture.Create<CardHolderCustomer>(); var builderMock = fixture .Freeze<Mock<ICustomerAdapter>>() .Setup(x => x.BuildCustomer()).Returns(expected); var sut = fixture.Create<CardHolderViewModel>(); var actual = sut

Testing With A Fake DbContext and Autofixture and Moq

自古美人都是妖i 提交于 2019-12-05 17:42:29
SO follow this example example and how make a fake DBContex For test my test using just this work fine [Test] public void CiudadIndex() { var ciudades = new FakeDbSet<Ciudad> { new Ciudad {CiudadId = 1, EmpresaId =1, Descripcion ="Santa Cruz", FechaProceso = DateTime.Now, MarcaBaja = null, UsuarioId = 1}, new Ciudad {CiudadId = 2, EmpresaId =1, Descripcion ="La Paz", FechaProceso = DateTime.Now, MarcaBaja = null, UsuarioId = 1}, new Ciudad {CiudadId = 3, EmpresaId =1, Descripcion ="Cochabamba", FechaProceso = DateTime.Now, MarcaBaja = null, UsuarioId = 1} }; //// Create mock unit of work var

What are the differences between MOQ and AutoFixture?

喜夏-厌秋 提交于 2019-12-05 16:43:12
问题 I have a fair amount of experience using MOQ, while I've recently have stumbled into AutoFixture. What are the differences between these frameworks? 回答1: The FAQ explains the difference. In short AutoFixture uses Reflection to create 'well-behaved' instances of public types. It auto-generates instances of other types if necessary to fill in arguments for a constructor, and also assigns values to public writable properties. In essence, it simply uses the requested type's public API to

How to configure AutoFixture to use an enum value as seed when creating many of a certain type?

霸气de小男生 提交于 2019-12-05 06:09:07
I have the following types: public enum Status { Online, Offline } public class User { private readonly Status _status; public User(Status status) { _status = status; } public Status Status {get {return _status; }} public string Name {get;set;} } Now, when executing fixture.CreateMany<User> I want AutoFixture to return two Users , one per status. All other properties - like Name - should be filled with anonymous data. Question: How to configure AutoFixture to do this? I tried the following this: Register collection that news up the User object: fixture.Register( () => Enum.GetValues(typeof

Invoke Dispose method on AutoFixture customization

只谈情不闲聊 提交于 2019-12-05 05:49:34
I'm using an AutoFixture customization to test a repository which access to a SQL Compact DB. Would be very helpful to me to delete this database as soon as the test is completed. Because the db is created in the customization constructor I think that the best place to delete it is in the dispose method. The code which I'm thinking is: internal class ProjectRepositoryCustomization : ICustomization { private readonly String _dbLocation; public ProjectRepositoryCustomization() { var tempDbLocation = Path.Combine(Path.GetTempPath(), "TempDbToDelete"); if (!Directory.Exists(tempDbLocation)) {

How to get AutoFixture create an integer that is >0, and not another number?

心不动则不痛 提交于 2019-12-05 02:15:13
I want AutoFixture to generate two integers, and for the second one, I don't want it to be 0, or the previous generated number. Is there a way to tell AutoFixture to honor that "requirement". Looking at RandomNumericSequenceGenerator , I looks like the lower limit is 1 , so I might not have to specify the first requirement. Next, I was looking at the "seeding" option, but as indicated in this answer , it won't be used for a number, by default. Is there something I'm overlooking here? Here's a way to do this with plain AutoFixture: [Fact] public void