autofixture

How do I use Autofixture (v3) with ICustomization, ISpecimenBuilder to deal with constructor parameter?

孤街醉人 提交于 2019-11-28 12:04:33
I'm trying to overcome a scenario in which a class has a string constructor parameter which cannot be satisfied by any old string generated by Autofixture (the Guid-y looking value). Before you're tempted to answer simply with a link to Mark Seemann's Ploeh blog entry on Convention-based Customizations , let me say that I've been referencing it and other blog entries of his for this test, which I can't get to pass. When I step through in debug, I can see that at some point the constructor parameter is passed in with the valid value, but the test still fails with the Guid-y Color value. I think

AutoFixture: PropertyData and heterogeneous parameters

拥有回忆 提交于 2019-11-28 08:00:36
问题 Given the following test: [Theory] [PropertyData("GetValidInputForDb")] public void GivenValidInputShouldOutputCorrectResult( string patientId , string patientFirstName ) { var fixture = new Fixture(); var sut = fixture.Create<HtmlOutputBuilder>(); sut.DoSomething(); // More code } I want to encapsulate fixture creation in its own class, something akin to: [Theory] [CustomPropertyData("GetValidInputForDb")] public void GivenValidInputShouldOutputCorrectResult( string patientId , string

Applying [AutoFixture] SemanticComparison OfLikeness to sequences / collections / arrays / IEnumerable

拥有回忆 提交于 2019-11-28 07:41:15
We have written a test which looks like the following. This test requires that we have created en Equal -overload for the CodeTableItem -class: ICollection<CodeTableItem> expectedValutaList = new List<CodeTableItem>(); expectedValutaList.Add(new CodeTableItem("DKK", "DKK")); expectedValutaList.Add(new CodeTableItem("EUR", "EUR")); RepoDac target = new RepoDac(); var actual = target.GetValutaKd(); CollectionAssert.AreEqual(expectedValutaList.ToList(),actual.ToList()); The test works fine, but has the unfortunate dependency to the Equality -function, meaning if I extend the CodeTableItem -class

What does CreateMany with seed do?

自古美人都是妖i 提交于 2019-11-28 07:26:26
问题 What does the CreateMany overload with the T seed parameter actually do? I've tried to seed, but the seed seems to have no effect on the created objects. For example, I was expecting that if my seed had a property of type string , that either: the string value would be used to populate that property in all newly created objects or the string value would be used as a prefix when setting that property in all newly created objects 回答1: tl;dr As a general rule, AutoFixture does not guarantee how

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 =

Use value of a parent property when creating a complex child in AutoFixture

杀马特。学长 韩版系。学妹 提交于 2019-11-28 01:05:16
I'm using AutoFixture to generate data for a structure involving a parent object and complex child objects, like this: public class Parent { public int Id { get; set; } public string Name { get; set; } public Child[] Children { get; set; } } public class Child { public string Name { get; set; } public int ParentId { get; set; } } Is there a way to automatically set the property ParentId of the generated Child object to the id assigned to the parent? Right now my solution looks like this, which isn't very pretty: var parent = fixture.Build<Parent>().Without(p => p.Children).CreateAnonymous();

How to let Autofixture create an instance of a type that contains properties with an interface type?

两盒软妹~` 提交于 2019-11-28 00:05:21
问题 I have such a class: public class ViewModel { public IPagination<Data> List { get; set; } // interface! public SearchFilter SearchFilter { get; set; } public string Test { get; set; } } public class SearchFilter { public string Name { get; set; } } A dynamic proxy shall be created around the IPagination interface and the proxy shall be filled with test data. Now is it possible to let AutoFixture create an instance of the ViewModel type? Be aware that I only know the type at runtime ( typeof

Easy way to specify the value of a single constructor parameter?

和自甴很熟 提交于 2019-11-27 14:46:33
Is there some easy way in Autofixture to new-up an object using it's constructor, but hard-code/specify the value to use for a single parameter in the constructor? I see that this can be done with properties, using something like: fixture.Build<MyObj>().With(x=x.Val,"hard coded value").Create() From the discussion about this question in the comments: Often I want to new-up an object, but I'm only concerned about a single parameter. Maybe the parameter value drives a calculation or transform of some sort. I want the value itself to be random, but the test needs to know what random value was

AutoFixture.AutoMoq supply a known value for one constructor parameter

偶尔善良 提交于 2019-11-27 14:31:23
问题 I've just started to use AutoFixture.AutoMoq in my unit tests and I'm finding it very helpful for creating objects where I don't care about the specific value. After all, anonymous object creation is what it is all about. What I'm struggling with is when I care about one or more of the constructor parameters. Take ExampleComponent below: public class ExampleComponent { public ExampleComponent(IService service, string someValue) { } } I want to write a test where I supply a specific value for

Creating recursive tree with AutoFixture

你。 提交于 2019-11-27 14:24:18
I have just started using AutoFixture and have this semi-complex data structure that I would like to create some specimen for. In the tests I am working with I don't care too much about content of the data structure. I just want reasonable default values. Part of this data structure is a recursive tree. More specific, one class holds a collection of some other class that contains a list of children of itself. Something akin to: public class A { private IEnumerable<B> bNodes; public A(IEnumerable<B> bNodes) { this.bNodes = bNodes; } } public class B { private IEnumerable<B> children; public B