autofixture

AutoFixture as an Automocking container vs Automocking differences?

人走茶凉 提交于 2019-12-12 07:12:18
问题 I started to use moq but from my understanding I always have to mock up all the methods that could be called even if I really do not care about them. Sometimes it takes so long to mockup stuff you forget what you want to do. So I been looking at auto mocking but I am not sure what one I should use. AutoFixture as an auto-mocking container Automocking I don't get how to use the first one at all. I sort of get the second one but never really tried it. I am not sure if one is better than the

AutoFixture EF entity constraints

99封情书 提交于 2019-12-11 18:49:45
问题 Is it possbile to configure AutoFixture so that it adheres the entity constraints [from the EDMX file]? E.g. Consider a snippet from the CSDL section of my EDMX file: <EntityType Name="RndtAd"> ... <Property Name="AD" Type="Decimal" Precision="12" Scale="0" Nullable="false" /> <Property Name="USERNAME" Type="String" MaxLength="255" FixedLength="false" Unicode="true" /> <Property Name="VERSION" Type="Decimal" Precision="12" Scale="4" Nullable="false" /> <Property Name="EFFECTIVE_FROM" Type=

New to AutoFixture trying to get my head around it and I can't see it helping me

…衆ロ難τιáo~ 提交于 2019-12-11 12:37:40
问题 Currently, I'm using custom made fake objects that behind the scenes use NSubstitute which creates the actual objects but it's becoming very hard to maintain as the project grows, so I'm trying to find alternatives and I'm hoping that AutoFixture is the right tool for the job. I read the documentation and I'm struggling because there's very little to no documentation and I read most of the blog posts by Mark Seemann including the CheatSheet. One of the things that I'm having hard time to

SpecimenBuilder for a collection

浪子不回头ぞ 提交于 2019-12-11 04:25:23
问题 I have a need for customizing creation of a collection, with quite complicated relationships between the objects within it, and I can't figure out how to do it correctly. For the sake of this issue, let's assume I'm working on a todo app. It has Item s and SubItem s, and the items have a week number indicating when they should be done: public class Item { public string Name { get; set; } public int Week { get; set; } public ICollection<SubItem> SubItems { get; set; } } public class SubItem {

How do I create a specimen builder in AutoFixture to always return a string that matches a Regex?

*爱你&永不变心* 提交于 2019-12-11 02:22:00
问题 I am trying to use conventions in my unit tests which make use of AutoFixture. I have a Password value object as shown: public class Password : SemanticType<string> { private int _daysPasswordValid; public Password(string password) : base(IsValid, password) { Guard.NotNullOrEmpty(() => password, password); Guard.IsValid(() => password, password, IsValid, "Invalid Password"); DateCreated = DateTime.Now; } static bool IsValid(string candidate) { //password cannot contain be whitespace if

How do I create a list of classes which always have a predefined value set in AutoFixture?

两盒软妹~` 提交于 2019-12-10 20:44:25
问题 how do I create a collection of classes which always have a certain predefined value set in AutoFixture? Fixture.Register<IList<Child>>(() => Fixture.CreateMany<Child>().ToList()); Say the child class has the following: public class Child { public int ParentId { get; set; } public int ChildId { get; set; } public string ChildName { get; set; } public int ChildValue { get; set; } } How do I ensure the anonymous classes always have the same parent Id whilst all other properties can be random? I

How do I customize AutoFixture behaviours for specific classes

試著忘記壹切 提交于 2019-12-10 20:06:52
问题 I need to enable AutoFixture to create instances of types with circular references (from an API provided by a third party). To do this I can remove the default ThrowingRecursionBehavior as shown below: public class RecursiveObjectCustomization : ICustomization { public void Customize(IFixture fixture) { fixture.Behaviors.OfType<ThrowingRecursionBehavior>() .ToList() .ForEach(b => fixture.Behaviors.Remove(b)); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); } } However, I understand that

How to exclude certain enumerations from all enumeration types

久未见 提交于 2019-12-10 19:23:14
问题 I am trying to exclude certain enumeration values such as Unknown and Uninitialized from the set of values for any enumeration type . I can see that Enums are generated in a round robin fashion using the EnumGenerator from the set of all possible Enum values for a given Enum type. Based on that code, my first thought is to build an ISpecimenBuilder that checks for Type.IsEnum and does a context.Resolve(request) until Resolve returns a value that is not on the excluded list. The problem is

Autofixture: How to express the following code declaratively?

China☆狼群 提交于 2019-12-10 19:18:48
问题 I am having trouble expressing the following code in a declarative fashion: [Theory] [InlineData(@"-o=C:\Temp\someFile -p=1")] [InlineData(@"-p=1 -o=C:\Temp\someFile")] public void ParseMissingParameterShouldReturnCorrectResult( string argsString ) { ..... var fixture = new Fixture(); fixture.Register<IFoo>(fixture.Create<Foo>); fixture.Register<IBar>(fixture.Create<Bar>); var sut = fixture.Create<SomeClass>(); ..... } In my production code, I've got something like: new SomeClass(new Foo(new

AutoFixure, randomly choose from predefined list

…衆ロ難τιáo~ 提交于 2019-12-10 19:06:33
问题 I am wondering in AutoFixure, is there a way to randomly choose from the predefined list? For example, when I use fixture.Create or fixture.CreateMany , it randomly selects an object from the predefined list. I did not find anything similar from documentation and searching Stack Overflow, so I am not sure it is even possible. 回答1: You can use ElementsBuilder<T> : [Fact] public void Example() { var fixture = new Fixture(); fixture.Customizations.Add( new ElementsBuilder<MyObject>( new MyObject