autofixture

Nuget cannot find newer dependency

拜拜、爱过 提交于 2019-12-01 17:06:06
I've just created a new project in ASP 5 MVC 6 beta8 and a compatible class library for tests. The problem occurs in this new "Web Class Library" project that I intended to use for tests. This is what my project.json looks like: { "version": "1.0.0-*", "description": "ClassLibrary1 Class Library", "authors": [ "Me" ], "tags": [ "" ], "projectUrl": "", "licenseUrl": "", "frameworks": { "dnx451": { } }, "dependencies": { "AutoFixture": "3.36.9", "AutoFixture.AutoMoq": "3.36.9", "Moq": "4.2.1510.2205" } } During compilation I get the following error: Severity Code Description Project File Line

Nuget cannot find newer dependency

别说谁变了你拦得住时间么 提交于 2019-12-01 16:34:20
问题 I've just created a new project in ASP 5 MVC 6 beta8 and a compatible class library for tests. The problem occurs in this new "Web Class Library" project that I intended to use for tests. This is what my project.json looks like: { "version": "1.0.0-*", "description": "ClassLibrary1 Class Library", "authors": [ "Me" ], "tags": [ "" ], "projectUrl": "", "licenseUrl": "", "frameworks": { "dnx451": { } }, "dependencies": { "AutoFixture": "3.36.9", "AutoFixture.AutoMoq": "3.36.9", "Moq": "4.2.1510

Can AutoFixture generate random strings/text from a provided data set?

泄露秘密 提交于 2019-12-01 09:26:12
问题 It is possible to use AutoFixture to generate random data for a string property .. but it's from a fixed data source? For example: I have 30 street names hardcoded into a memory collection (array/list/whatever). Then, for my Address instance, the StreetName property isn't just a random string value (which is the default result from AutoFixture) but one of the street names from that hardcoded collection. My first thought was to use a random number which AutoFixture might be able to create..

AutoFixture IEnumerable<T> behavior with CreateMany()

本小妞迷上赌 提交于 2019-12-01 03:35:17
When looking at the post here , it looks like I should be able to create several objects using CreateMany() , iterate over them using foreach , and then return them as an array. What I'm seeing is that each iteration seems to create new objects each time. Is this expected behavior? Entity to create: public class TestEntity { public int Id { get; private set; } public string SomeString { get; set; } public void SetId(int value) { this.Id = value; } } Sample Program.cs: private static int id; static void Main(string[] args) { var fixture = new Fixture(); IEnumerable<TestEntity> testEntities =

AutoFixture CompositeDataAttribute does not work with PropertyDataAttribute

此生再无相见时 提交于 2019-12-01 01:43:25
问题 I'm trying to create AutoPropertyDataAttribute based on CompositeDataAttribute from this example AutoFixture: PropertyData and heterogeneous parameters. It works with single set of parameters, but fails with more sets of parameters. Here is code: public static IEnumerable<object[]> NumericSequence { get { yield return new object[] {1}; //yield return new object[] {2}; } } [Theory] [AutoPropertyData("NumericSequence")] public void Test(int? p1, int? p2, int? p3) { Assert.NotNull(p1); Assert

How to combine PropertyData and AutoNSubstituteData attributes in xunit/autofixture?

折月煮酒 提交于 2019-11-30 21:26:00
I am using the [AutoNSubstituteData] attribute, which was posted here: AutoFixture, xUnit.net, and Auto Mocking I would like to combine this with the [PropertyData("")] attribute from xunit extensions. This is my test: public static IEnumerable<string[]> InvalidInvariant { get { yield return new string[] { null }; yield return new [] { string.Empty }; yield return new [] { " " }; } } [Theory, AutoNSubstituteData, PropertyData("InvalidInvariant")] public void TestThatGuardsAreTriggeredWhenConnectionStringArgumentIsInvalid( IDeal deal, IDbConnection conn, IDb db, ISender sender, string

AutoFixture: Configuring an Open Generics Specimen Builder

非 Y 不嫁゛ 提交于 2019-11-30 19:47:12
I have an object model that uses Open Generics (Yes, yes, now I have two problems; that's why I'm here :) :- public interface IOGF<T> { } class C { } class D { readonly IOGF<C> _ogf; public D( IOGF<C> ogf ) { _ogf = ogf; } } I'm trying to get AutoFixture to generate Anonymous instances of D above. However, on its own, AutoFixture doesn't have a built in strategy for building an IOGF<> and hence we observe: public class OpenGenericsBinderDemo { [Fact] public void X() { var fixture = new Fixture(); Assert.Throws<Ploeh.AutoFixture.ObjectCreationException>( () => fixture.CreateAnonymous<D>() ); }

Why does Autofixture w/ AutoMoqCustomization stop complaining about lack of parameterless constructor when class is sealed?

£可爱£侵袭症+ 提交于 2019-11-30 19:19:24
When I use Moq directly to mock IBuilderFactory and instantiate BuilderService myself in a unit test, I can get a passing test which verifies that the Create() method of IBuilderFactory is called exactly once. However, when I use Autofixture with AutoMoqCustomization , freezing a mock of IBuilderFactory and instantiating BuilderService with fixture.Create<BuilderService> , I get the following exception: System.ArgumentException: Can not instantiate proxy of class: OddBehaviorTests.CubeBuilder. Could not find a parameterless constructor. Parameter name: constructorArguments If I make

How to implement date restrictions with AutoFixture?

假装没事ソ 提交于 2019-11-30 18:20:23
I'm currently having a model class which contains several properties. A simplified model could look like this: public class SomeClass { public DateTime ValidFrom { get; set; } public DateTime ExpirationDate { get; set; } } Now I'm implementing some unit tests by using NUnit and use AutoFixture to create some random data: [Test] public void SomeTest() { var fixture = new Fixture(); var someRandom = fixture.Create<SomeClass>(); } This works perfect so far. But there is the requirement that the date of ValidFrom is always before ExpirationDate . I have to ensure this since I'm implementing some

Force AutoFixture to use the greediest constructor

旧巷老猫 提交于 2019-11-30 13:39:58
问题 I have a data type with multiple constructors and I need AutoFixture to choose the greediest (one with the most parameters). The default behaviour is to choose the constructor with the smallest number. The author's blog post, http://blog.ploeh.dk/2009/03/24/HowAutoFixtureCreatesObjects.aspx doesn't seem to imply there's a way of overriding this behaviour, so is it possible, and if so, how? 回答1: This is certainly possible. To change the strategy for a single type ( MyClass ): fixture.Customize