autofixture

Why doesn't simple test pass using AutoFixture Freeze, SemanticComparison Likeness and CreateProxy?

梦想与她 提交于 2020-03-01 01:55:57
问题 I'm trying to understand how to use the CreateProxy() feature of Likeness<T>() using two instances of a simple class. public class Band { public string Strings { get; set; } public string Brass { get; set; } } With the following test, I use a Fixture to Create<T> a Band instance with values for the two string properties. [Fact] public void Equality_Behaves_As_Expected() { // arrange var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var original = fixture.Create<Band>

How to use AutoFixture to build with customized properties while keeping type customizations?

一笑奈何 提交于 2020-01-31 06:51:20
问题 I am trying to use autofixture to create an object but there are certain properties that I want to always be defaulted (while the rest could be auto generated). However, whenever I setup an customization it gets overwritten when I build with customizations. void Main() { var fixture = new Fixture(); fixture.Customize<Person>(composer => composer.With(p => p.Name, "Ben")); var person = fixture.Build<Person>() .With(p => p.DateOfBirth, new DateTime(1900, 1, 1)) .Create(); /* RESULT OF person

Are integer numbers generated with AutoFixture 3 unique?

大城市里の小女人 提交于 2020-01-24 02:16:13
问题 Are integer numbers generated with IFixture.Create<int>() unique? The Wiki says that numbers are random, but it also tells us this The first numbers are generated within the range of [1, 255], as this is a set of values that are valid for all numeric data types. The smallest numeric data type in .NET is System.Byte, which fits in this range. When the first 255 integers have been used, numbers are subsequently picked from the range [256, 32767], which corresponds to the remaining positive

How can I create and populate my mock classes with Autofixture?

与世无争的帅哥 提交于 2020-01-22 11:03:49
问题 Currently I'm using EF6 to implement my repositories inside a UnitOfWork. I also have created an In-Memory mock implementations (MockUnitOfWork & MockRepository) so that I can use them in unit tests, however I now have to deal with the tedious setup of the objects. Isn't this what Autofixture is designed to do? How would I go about getting a MockUnitOfWork that I can use in my tests that contains Foo and Barr repositories that are populated? I'm using NSubstitute for my mocking framework.

need to create convention for ApiControllers

风格不统一 提交于 2020-01-20 04:10:19
问题 I have a set of working imperative code in test and I'm trying to boil it down to an essential test convention. My test looks like the following: [Theory, BasicConventions] public void GetVersionOnSiteVersionControllerReturnsASiteVersion(IFixture fixture) { fixture.OmitAutoProperties = true; SiteVersion expected = fixture.Create<SiteVersion>(); SiteVersion actual = null; var sut = fixture.Create<SiteVersionController>(); var response = sut .GetSiteVersion() .ExecuteAsync(new CancellationToken

need to create convention for ApiControllers

不打扰是莪最后的温柔 提交于 2020-01-20 04:08:36
问题 I have a set of working imperative code in test and I'm trying to boil it down to an essential test convention. My test looks like the following: [Theory, BasicConventions] public void GetVersionOnSiteVersionControllerReturnsASiteVersion(IFixture fixture) { fixture.OmitAutoProperties = true; SiteVersion expected = fixture.Create<SiteVersion>(); SiteVersion actual = null; var sut = fixture.Create<SiteVersionController>(); var response = sut .GetSiteVersion() .ExecuteAsync(new CancellationToken

How to fix a range on some properties when create a TestClass by AutoFixture

社会主义新天地 提交于 2020-01-14 07:51:12
问题 Does anyone know how can I tell AutoFixture to specify a range (min and max) on some properties when doing MyDataClass obj = fixture.Create<MyDataClass>(); where MyDataClass has property Diameter and I only want min:1 and max:60 on this property. 回答1: Data Annotations The easiest approach is probably adorning the property itself with a Data Annotation, although I'm not myself a huge fan of this: public class MyDataClass { [Range(1, 60)] public decimal Diameter { get; set; } } AutoFixture will

How can I register a generic object factory?

本秂侑毒 提交于 2020-01-04 02:26:04
问题 I have the following two classes: public class KeyedEntity<TEntity> { internal KeyedEntity() { } public Identifier Key { get; set; } public TEntity Entity { get; set; } } public static class KeyedEntity { public static KeyedEntity<TEntity> Create<TEntity>(Identifier key, TEntity entity) { return new KeyedEntity<TEntity> { Key = key, Entity = entity, }; } } The reason the constructor is internal and the second class exists is I want to enforce the more highly-maintainable KeyedEntity.Create(x,

Why isn't AutoFixture working with the StringLength data annotation?

为君一笑 提交于 2020-01-03 21:01:56
问题 I'm trying again to upgrade to AutoFixture 2, and I'm running into a problem with the data annotations on my objects. Here's an example object: public class Bleh { [StringLength(255)] public string Foo { get; set; } public string Bar { get; set; } } I'm attempting to create an anonymous Bleh , but the property with the annotation is coming up empty rather than being populated with an anonymous string. [Test] public void GetAll_HasContacts() { var fix = new Fixture(); var bleh = fix

AutoFixture - how do I call a method, how to set a private setter of an autoproperty?

醉酒当歌 提交于 2020-01-03 18:51:29
问题 Here's my class: public MyClass { public int Id { get; private set; } public SetAssignableId (int id) { this.Id = id; } } I would like to have AutoFixture set the Id via SetAssignableId or the private setter. 回答1: There's no way to invoke a private setter with AutoFixture today. Although it uses reflection internally, by design it respects a type's public API. There's an outstanding request on the Issue Board to make this more customizable - if you read the work item closely you will see that