autofixture

Autofixture test for invalid constructor parameter

浪子不回头ぞ 提交于 2019-12-05 00:48:43
I have the following class and test. I want to test passing a null value as a parameter to the constructor and are expecting an ArgumentNullException . But since I use the Autofixture's CreateAnonymous method I get a TargetInvocationException instead. What is the correct way to write those kinds of tests? public sealed class CreateObject : Command { // Properties public ObjectId[] Ids { get; private set; } public ObjectTypeId ObjectType { get; private set; } public UserId CreatedBy { get; private set; } // Constructor public CreateObject(ObjectId[] ids, ObjectTypeId objectType, UserId

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

让人想犯罪 __ 提交于 2019-12-04 22:34:23
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 Address { public string Street { get; set; } public int Number { get; set; } public string City { get; set; }

Generalised Func wrapping with Anonymous Values equivalent to AutoFixture 'With'

只愿长相守 提交于 2019-12-04 04:32:47
问题 In an AutoFixture-based test, I'm trying to express as cleanly as possible the following: When I pass <input> to the parameter x of this method, filling in the other parameters anonymously, the result is... Taking the example of a factory method:- class X { public static X Create( Guid a, Guid b, Guid c, String x, String y); I'm trying to express as a succinct series of tests: If I pass null for x , it should throw If I pass null for y , it should throw In order to express I can say: var

How to setup more complicated (IoC like) registration in AutoFixture

萝らか妹 提交于 2019-12-04 04:29:03
问题 Is it possible to reuse production IoC container registration in integration tests when using AutoFixture? The problem is that I need the following fixture setup to inject mocks if dependency is not registered and inject "real" database related dependencies var fixture = new Fixture().WithMocks().WithRealDatabase() The solution I've tried internal static Fixture WithMocks(this Fixture fixture) { fixture.Customize(new AutoMoqCustomization()); } internal static Fixture WithRealDatabase(this

AutoFixture in F# UnitTest Project Not Displaying Unit Tests in Test Explorer

删除回忆录丶 提交于 2019-12-04 03:51:41
问题 I have a Visual Studio 2012 Project and the following NuGet Packages installed: AutoFixture with Auto Mocking using Moq Autofixture with xUnit.net data theories AutoFixture Moq xUnit.net: Extensions xUnit.net: Runners xUnit.net Given the following contrived Logger class (Logger.fs): namespace FUnit type public ILoggerContext = abstract member LogPath :string type public LoggerContext (logPath :string) = member val LogPath = logPath with get, set interface ILoggerContext with member this

Does this test make proper use of AutoFixture and Moq?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 02:10:07
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.Customer; Assert.Equal(expected, actual); } Nikos Baxevanis It's looking good! However, you can also use it

AutoFixture: how to CreateAnonymous from a System.Type

左心房为你撑大大i 提交于 2019-12-03 22:40:08
I need to create an object from AutoFixture using nothing more than a System.Type. However, there doesn't appear to be an overload of CreateAnonymous() that simply takes a type. They all expect a compile time generic T. Is there a way to convert a System.Type to T? Edit with usage details: I'm using AutoMapper, which has a hook for injecting components to support complex mapping scenarios: void ConstructServicesUsing(System.Func<Type,object> constructor) As you can see from the signature, clients can register a Func which AutoMapper invokes anytime it needs an injected service (mostly

Autofixture customizations: provide constructor parameter

馋奶兔 提交于 2019-12-03 22:35:24
I have the following class: class Foo { public Foo(string str, int i, bool b, DateTime d, string str2) { ..... } } I'm creating a Foo with AutoFixture: var foo = fixture.Create<Foo>(); but I want AutoFixture to provide a known value for the str2 parameter and use the default behavior for every other parameter. I tried implementing a SpecimenBuilder but I can't find a way to get the metadata associated with the request to know that I'm being called from the Foo constructor. Is there any way to achieve this? Orlando William As answered here you can have something like public class FooArg :

How can I use custom ISpecimenBuilders with OmitOnRecursionBehavior?

与世无争的帅哥 提交于 2019-12-03 15:07:28
How can I use custom ISpecimenBuilder instances along with the OmitOnRecursionBehavior which I want applied globally to all fixture-created objects? I'm working with an EF Code First model with a foul-smelling circular reference that, for the purposes of this question, cannot be eliminated: public class Parent { public string Name { get; set; } public int Age { get; set; } public virtual Child Child { get; set; } } public class Child { public string Name { get; set; } public int Age { get; set; } public virtual Parent Parent { get; set; } } I'm familiar with the technique for side-stepping

What is AutoFixture AutoMoq?

旧时模样 提交于 2019-12-03 06:29:04
问题 I was looking at nuget and wanted to import moq when I noticed AutoFixture AutoMoq. I see that AutoFixture is to help write TDD faster but I can't find any examples of AutoMoq and how it is different then AutoFixture. Can someone point me to this AutoMoq so I can see what it is doing. 回答1: In short, AutoFixture.AutoMoq is an extension that turns AutoFixture into an Auto-Mocking Container using the Moq dynamic mock library. There's also a similar extension for AutoFixture that enables auto