autofixture

Can a particular constructor argument of an injected SUT using Autodata xUnit Theories?

最后都变了- 提交于 2019-12-23 16:31:23
问题 Consider the following test, [Theory, MyConventions] public void GetClientExtensionReturnsCorrectValue(BuilderStrategy sut) { var expected = ""; // <--??? the value injected into BuilderStrategy var actual = sut.GetClientExtension(); Assert.Equal(expected, actual); } and the custom attribute I'm using: public class MyConventionsAttribute : AutoDataAttribute { public MyConventionsAttribute() : base(new Fixture().Customize(new AutoMoqCustomization())) {} } and the SUT: class BuilderStrategy {

Verifying a set of objects have been mapped correctly

纵饮孤独 提交于 2019-12-23 13:24:36
问题 I'm looking for a clean set of ways to manage Test Specific Equality in F# unit tests . 90% of the time, the standard Structural Equality fits the bill and I can leverage it with unquote to express the relation between my result and my expected . TL;DR "I can't find a clean way to having a custom Equality function for one or two properties in a value which 90% of is well served by Structural Equality, does F# have a way to match an arbitrary record with custom Equality for just one or two of

Autofixture generate custom list

笑着哭i 提交于 2019-12-23 12:14:40
问题 Here's my object: public class Symbol { private readonly string _identifier; private readonly IList<Quote> _historicalQuotes; public Symbol(string identifier, IEnumerable<Quote> historicalQuotes = null) { _identifier = identifier; _historicalQuotes = historicalQuotes; } } public class Quote { private readonly DateTime _tradingDate; private readonly decimal _open; private readonly decimal _high; private readonly decimal _low; private readonly decimal _close; private readonly decimal

Autofixture generate custom list

ぃ、小莉子 提交于 2019-12-23 12:13:19
问题 Here's my object: public class Symbol { private readonly string _identifier; private readonly IList<Quote> _historicalQuotes; public Symbol(string identifier, IEnumerable<Quote> historicalQuotes = null) { _identifier = identifier; _historicalQuotes = historicalQuotes; } } public class Quote { private readonly DateTime _tradingDate; private readonly decimal _open; private readonly decimal _high; private readonly decimal _low; private readonly decimal _close; private readonly decimal

Autofixture and WebApi Controller

一曲冷凌霜 提交于 2019-12-23 12:04:12
问题 I am using AutoFixture to try to test my controllers for a WebApi site. I am using the AutoData feature with Moq as noted on Ploeh's blog. My controller takes an IDepartmentManager in the constructor. Here is my test: [Theory, AutoMoqData] public void GetCallsManagerCorrectly( [Frozen]Mock<IDepartmentManager> departmentManagerMock, DepartmentsController sut) { // Fixture setup // Exercise system sut.Get(); // Verify outcome departmentManagerMock.Verify(d => d.GetAllDepartments(), Times

Technique for using AutoFixture to integration test an application using Castle Windsor

时光毁灭记忆、已成空白 提交于 2019-12-23 09:38:31
问题 I'm new to AutoFixture, so I don't know if the following idea is going to make sense or be a reasonable thing to do. I've got an application that I'm in charge of integration testing , and it makes heavy use of Castle Windsor. To simplify dependency management and make my tests more like the application code, I've been building the Windsor container in my test initialize method and the using container.Resolve to instantiate the code I'm testing. I'd like to move away from that approach since

How to generate a stub object of an arbitrary Type not known at compile time using AutoFixture

五迷三道 提交于 2019-12-23 09:27:27
问题 I can get type of constructor parameter like this: Type type = paramInfo.ParameterType; Now I want to create stub object from this type. Is is possible? I tried with autofixture: public TObject Stub<TObject>() { Fixture fixture = new Fixture(); return fixture.Create<TObject>(); } .. but it doesn't work: Type type = parameterInfo.ParameterType; var obj = Stub<type>();//Compile error! ("cannot resolve symbol type") Could you help me out? 回答1: AutoFixture does have a non-generic API to create

AutoFixture and private properties

空扰寡人 提交于 2019-12-23 07:27:24
问题 Can I instruct AutoFixture to fill also private properties, annotated with a specific attribute such as Ninject.Inject , of all classes? The source seems to scan for public properties only: 1. This question provides a solution for specific MyClass with private setter, but not for private property or all classes: 2. I'm using Moq to mock the services and in the end I'd like to fill the properties with those mocks. The following setup works fine if I expose the MyService dependency as public .

How can I instruct AutoFixture to not bother filling out some properties?

耗尽温柔 提交于 2019-12-23 06:49:08
问题 I have a set of Data Access classes that are nested fairly deep. To construct a list of 5 of them takes AutoFixture more than 2 minutes. 2 minutes per Unit test is way to long. If I was coding them by hand, I would only code up the ones I need, so it would initialize quicker. Is there a way to tell AutoFixture to only do some of the properties so it can not spend time with areas of my structure I don't need? For example: public class OfficeBuilding { public List<Office> Offices {get; set;} }

How can I instruct AutoFixture to not bother filling out some properties?

余生颓废 提交于 2019-12-23 06:48:30
问题 I have a set of Data Access classes that are nested fairly deep. To construct a list of 5 of them takes AutoFixture more than 2 minutes. 2 minutes per Unit test is way to long. If I was coding them by hand, I would only code up the ones I need, so it would initialize quicker. Is there a way to tell AutoFixture to only do some of the properties so it can not spend time with areas of my structure I don't need? For example: public class OfficeBuilding { public List<Office> Offices {get; set;} }