autofixture

AutoFixture - configure fixture to limit string generation length

淺唱寂寞╮ 提交于 2019-11-27 11:31:28
问题 When using autofixture Build method for some type, how can I limit the length of the strings generated to fill that objects string properties/fields? 回答1: With the Build method itself, there aren't that many options, but you can do something like this: var constrainedText = fixture.Create<string>().Substring(0, 10); var mc = fixture .Build<MyClass>() .With(x => x.SomeText, constrainedText) .Create(); However, personally, I don't see how this is any better or easier to understand that this:

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

Can AutoFixture execute a delegate at object creation time?

旧城冷巷雨未停 提交于 2019-11-27 06:56:23
问题 I'm looking to customize the creation-time behavior of AutoFixture such that I can set up some dependent objects after the properties of the fixture have been generated and assigned. For example, suppose I have a method that customizes a User because its IsDeleted property always has to be false for a certain set of tests: public class User { public int Id { get; set; } public string Name { get; set; } public bool IsDeleted { get; set; } } public static ObjectBuilder<User> BuildUser(this

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

。_饼干妹妹 提交于 2019-11-27 06:43:37
问题 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

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

旧巷老猫 提交于 2019-11-27 01:56:11
问题 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

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

我只是一个虾纸丫 提交于 2019-11-26 23:28:30
问题 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,

Customizing AutoFixture builder with seeded property

孤人 提交于 2019-11-26 20:54:26
问题 I've got a customized autofixture builder for an integration test. Code is below. Question 1 - At present the first transaction has a TransactionViewKey.TransactionId of 1, etc. How do I set the TransactionViewKey TransactionId so it is seeded from the method param beginningTransactionId ? eg returning an array of TransactionViews where the first TransactionId is 200, then each incrementing by 1? Question 2 - the lambda for determining transactiondate seems to be run once only - and so each

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