public void ShouldBeAbleToAddCustomExtension() { var builderSetup = new BuilderSetup(); var list = new Builder <MyClass>(builderSetup).CreateListOfSize(10).AllEven().With(x => x.StringOne = theString).Build(); Assert.That(list.Count(x => x.StringOne == theString), Is.EqualTo(5)); }
protected void SetMemberValue <T>(MemberInfo memberInfo, T instance) { if (memberInfo is PropertyInfo && BuilderSetup.ShouldIgnoreProperty((PropertyInfo)memberInfo)) { return; } var currentValue = memberInfo.GetFieldOrPropertyValue(instance); if (!currentValue.IsDefaultValue()) { return; } var handler = GetTypeHandler(memberInfo); if (handler == null) { return; } var value = handler.Method.GetParameters().Length == 1 ? handler.DynamicInvoke(memberInfo) : handler.DynamicInvoke(); memberInfo.SetFieldOrPropertyValue(instance, value); }
public void ShouldBeAbleToSpecifyACustomPropertyNamerForASpecificType() { try { IPropertyNamer propertyNamer = mocks.DynamicMock <IPropertyNamer>(); BuilderSetup.SetPropertyNamerFor <MyClass>(propertyNamer); using (mocks.Record()) { propertyNamer.Expect(x => x.SetValuesOfAllIn(Arg <IList <MyClass> > .Is.TypeOf)).Repeat.Once(); } using (mocks.Playback()) { Builder <MyClass> .CreateListOfSize(10).Build(); Builder <SimpleClass> .CreateListOfSize(10).Build(); } mocks.VerifyAll(); } finally { BuilderSetup.ResetToDefaults(); } }
public void ShouldBeAbleToCreateAClassThatHasANullCharConstant() { var builderSetup = new BuilderSetup(); var mc = new Builder <MyClassWithCharConst>(builderSetup).CreateNew().Build(); Assert.That(mc.GetNullCharConst(), Is.EqualTo(MyClassWithCharConst.NullCharConst)); }
public void NBuilderCannotBeUsedToBuildInterfaces() { var builderSetup = new BuilderSetup(); var ex = Assert.Throws <TypeCreationException>(() => new Builder <IMyInterface>(builderSetup).CreateNew().Build()); Assert.That(ex.Message, Is.EqualTo("Cannot build an interface")); }
public void NBuilderCannotBeUsedToBuildAbstractClasses() { var builderSetup = new BuilderSetup(); var ex = Assert.Throws <TypeCreationException>(() => new Builder <MyAbstractClass>(builderSetup).CreateNew().Build(), "Cannot build an abstract class"); Assert.That(ex.Message, Is.EqualTo("Cannot build an abstract class")); }
public void ShouldBeAbleToSpecifyADefaultCustomPropertyNamer() { BuilderSetup.SetDefaultPropertyNamer(new MockPropertyNamerTests()); Builder <MyClass> .CreateNew().Build(); Assert.That(MockPropertyNamerTests.SetValuesOf_obj_CallCount, Is.EqualTo(1)); }
public RandomContactGenerator() { BuilderSetup.DisablePropertyNamingFor <Contact, int>(x => x.Id); _nameGenerator = new NameGenerator(); _surnameGenerator = new SurnameGenerator(); }
public void NBuilderIsNotAMockingFramework() // (!) { var builderSetup = new BuilderSetup(); new Builder <IProduct>(builderSetup).CreateNew().Build(); // ^ }
public void WhenUsedInContextRandomItemPickerShouldPickDifferentItems() { var builderSetup = new BuilderSetup(); var stringList = new List <string>(); for (int i = 0; i < 100; i++) { stringList.Add("string" + i); } var strings = stringList.ToArray(); var vehicles = new Builder <MyClass>(builderSetup) .CreateListOfSize(10) .All() .With(x => x.StringOne = Pick <string> .RandomItemFrom(strings)) .Build(); var list = vehicles.Select(x => x.StringOne); var distinctList = list.Distinct(); Assert.That(distinctList.Count(), Is.GreaterThan(1)); }
public void CreatingAList() { var builderSetup = new BuilderSetup(); var products = new Builder<Product>(builderSetup).CreateListOfSize(10).Build(); // Note: The asserts here are intentionally verbose to show how NBuilder works // It sets strings to their name plus their 1-based sequence number Assert.That(products[0].Title, Is.EqualTo("Title1")); Assert.That(products[1].Title, Is.EqualTo("Title2")); Assert.That(products[2].Title, Is.EqualTo("Title3")); Assert.That(products[3].Title, Is.EqualTo("Title4")); Assert.That(products[4].Title, Is.EqualTo("Title5")); Assert.That(products[5].Title, Is.EqualTo("Title6")); Assert.That(products[6].Title, Is.EqualTo("Title7")); Assert.That(products[7].Title, Is.EqualTo("Title8")); Assert.That(products[8].Title, Is.EqualTo("Title9")); Assert.That(products[9].Title, Is.EqualTo("Title10")); // Ints are set to their 1-based sequence number Assert.That(products[0].Id, Is.EqualTo(1)); // ... 2, 3, 4, 5, 6, 7, 8 ... Assert.That(products[9].Id, Is.EqualTo(10)); // Any other numeric types are set to their 1-based sequence number Assert.That(products[0].PriceBeforeTax, Is.EqualTo(1m)); // ... 2m, 3m, 4m, 5m, 6m, 7m, 8m ... Assert.That(products[9].PriceBeforeTax, Is.EqualTo(10m)); }
public void UsingSequentialGenerators() { var builderSetup = new BuilderSetup(); // Arrange var decimalGenerator = new SequentialGenerator <decimal> { Increment = 10, Direction = GeneratorDirection.Descending }; decimalGenerator.StartingWith(2000); var intGenerator = new SequentialGenerator <int> { Increment = 10000 }; // Act var list = new Builder <Product>(builderSetup).CreateListOfSize(3) .All() .With(x => x.PriceBeforeTax = decimalGenerator.Generate()) .And(x => x.Id = intGenerator.Generate()) .Build(); // Assert Assert.That(list[0].PriceBeforeTax, Is.EqualTo(2000)); Assert.That(list[1].PriceBeforeTax, Is.EqualTo(1990)); Assert.That(list[2].PriceBeforeTax, Is.EqualTo(1980)); Assert.That(list[0].Id, Is.EqualTo(0)); Assert.That(list[1].Id, Is.EqualTo(10000)); Assert.That(list[2].Id, Is.EqualTo(20000)); }
public void DifferentPartsOfTheListCanBeConstructedDifferently() { var builderSetup = new BuilderSetup(); var basket1 = new ShoppingBasket(); var product1 = new Product(); const int quantity1 = 5; var basket2 = new ShoppingBasket(); var product2 = new Product(); const int quantity2 = 7; var items = new Builder <BasketItem>(builderSetup) .CreateListOfSize(4) .TheFirst(2) .AreConstructedWith(basket1, product1, quantity1) .TheNext(2) .AreConstructedWith(basket2, product2, quantity2) .Build(); Assert.That(items[0].Basket, Is.EqualTo(basket1)); Assert.That(items[0].Basket, Is.EqualTo(basket1)); Assert.That(items[0].Basket, Is.EqualTo(basket1)); Assert.That(items[0].Basket, Is.EqualTo(basket1)); Assert.That(items[0].Basket, Is.EqualTo(basket1)); Assert.That(items[0].Basket, Is.EqualTo(basket1)); }
protected Declaration(IListBuilderImpl <T> listBuilderImpl, IObjectBuilder <T> objectBuilder) { this.listBuilderImpl = listBuilderImpl; this.objectBuilder = objectBuilder; MasterListAffectedIndexes = new List <int>(); BuilderSetup = listBuilderImpl.BuilderSetup; }
public void ShouldBeAbleToCreateAClassThatHasANullCharConstant() { var builderSetup = new BuilderSetup(); var mc = new Builder<MyClassWithCharConst>(builderSetup).CreateNew().Build(); Assert.That(mc.GetNullCharConst(), Is.EqualTo(MyClassWithCharConst.NullCharConst)); }
public void ShouldBeAbleToCreateAnObject() { var builderSetup = new BuilderSetup(); var obj = new Builder <MyClass>(builderSetup).CreateNew(); Assert.That(obj, Is.Not.Null); }
public void SetUp() { var builderSetup = new BuilderSetup(); reflectionUtil = Substitute.For<IReflectionUtil>(); generator = Substitute.For<IRandomGenerator>(); propertyNamer = new RandomValuePropertyNamer(generator, reflectionUtil, false,builderSetup); }
public void Lists_9() { BuilderSetup builderSetup = new BuilderSetup(); var products = new Builder <Product>(builderSetup).CreateListOfSize(5).Build(); Pick <Product> .UniqueRandomList(With.Between(5).And(10).Elements).From(products); }
public void UsingSection() { var builderSetup = new BuilderSetup(); var list = new Builder <Product>(builderSetup) .CreateListOfSize(30) .All() .With(x => x.Title = "Special Title 1") .Section(12, 14) .With(x => x.Title = "Special Title 2") .Section(16, 18) .With(x => x.Title = "Special Title 3") .Build(); // All Assert.That(list[0].Title, Is.EqualTo("Special Title 1")); Assert.That(list[1].Title, Is.EqualTo("Special Title 1")); // ... Assert.That(list[29].Title, Is.EqualTo("Special Title 1")); // Section 1 - 12 - 14 Assert.That(list[12].Title, Is.EqualTo("Special Title 2")); Assert.That(list[13].Title, Is.EqualTo("Special Title 2")); Assert.That(list[14].Title, Is.EqualTo("Special Title 2")); // Section 2 - 16 - 18 Assert.That(list[16].Title, Is.EqualTo("Special Title 3")); Assert.That(list[17].Title, Is.EqualTo("Special Title 3")); Assert.That(list[18].Title, Is.EqualTo("Special Title 3")); }
public ScriptRunner() { setup = new BuilderSetup { LoggerType = typeof (AssertingMsBuildLogger).AssemblyQualifiedName }; }
public void CreatingAList() { var builderSetup = new BuilderSetup(); var products = new Builder <Product>(builderSetup).CreateListOfSize(10).Build(); // Note: The asserts here are intentionally verbose to show how NBuilder works // It sets strings to their name plus their 1-based sequence number Assert.That(products[0].Title, Is.EqualTo("Title1")); Assert.That(products[1].Title, Is.EqualTo("Title2")); Assert.That(products[2].Title, Is.EqualTo("Title3")); Assert.That(products[3].Title, Is.EqualTo("Title4")); Assert.That(products[4].Title, Is.EqualTo("Title5")); Assert.That(products[5].Title, Is.EqualTo("Title6")); Assert.That(products[6].Title, Is.EqualTo("Title7")); Assert.That(products[7].Title, Is.EqualTo("Title8")); Assert.That(products[8].Title, Is.EqualTo("Title9")); Assert.That(products[9].Title, Is.EqualTo("Title10")); // Ints are set to their 1-based sequence number Assert.That(products[0].Id, Is.EqualTo(1)); // ... 2, 3, 4, 5, 6, 7, 8 ... Assert.That(products[9].Id, Is.EqualTo(10)); // Any other numeric types are set to their 1-based sequence number Assert.That(products[0].PriceBeforeTax, Is.EqualTo(1m)); // ... 2m, 3m, 4m, 5m, 6m, 7m, 8m ... Assert.That(products[9].PriceBeforeTax, Is.EqualTo(10m)); }
public BuilderSetup DoSetup() { BuilderSetup builderSetup = new BuilderSetup(); EnsureActiveRecordInitialized(); if (setup) { return(builderSetup); } setup = true; var productRepository = Dependency.Resolve <IProductRepository>(); var taxTypeRepository = Dependency.Resolve <ITaxTypeRepository>(); var categoryRepository = Dependency.Resolve <ICategoryRepository>(); builderSetup.SetCreatePersistenceMethod <Product>(productRepository.Create); builderSetup.SetCreatePersistenceMethod <IList <Product> >(productRepository.CreateAll); builderSetup.SetCreatePersistenceMethod <TaxType>(taxTypeRepository.Create); builderSetup.SetCreatePersistenceMethod <IList <TaxType> >(taxTypeRepository.CreateAll); builderSetup.SetCreatePersistenceMethod <Category>(categoryRepository.Create); builderSetup.SetCreatePersistenceMethod <IList <Category> >(categoryRepository.CreateAll); builderSetup.SetUpdatePersistenceMethod <Category>(categoryRepository.Save); builderSetup.SetUpdatePersistenceMethod <IList <Category> >(categoryRepository.SaveAll); return(builderSetup); }
public void SetUp() { mocks = new MockRepository(); persistenceService = mocks.DynamicMock<IPersistenceService>(); repository = mocks.DynamicMock<IMyClassRepository>(); builderSetup = new BuilderSetup(); builderSetup.SetPersistenceService(this.persistenceService); }
public void ShouldChooseCorrectConstructor() { var builderSetup = new BuilderSetup(); var obj = new Builder<MyClassWithConstructor>(builderSetup).CreateNew().WithConstructorArgs(theInt, theFloat).Build(); Assert.That(obj.Int, Is.EqualTo(theInt)); Assert.That(obj.Float, Is.EqualTo(theFloat)); }
public void Building_single_objects_2() { BuilderSetup builderSetup = new BuilderSetup(); var product = new Builder <Product>(builderSetup) .CreateNew() .With(x => x.Description = "A custom description here") .Build(); }
public void HomePage_1() { BuilderSetup builderSetup = new BuilderSetup(); var products = new Builder <Product>(builderSetup).CreateListOfSize(10) .TheFirst(2) .With(x => x.Title = "special title") .Build(); }
public void ShouldBeAbleToDisableAutomaticPropertyNaming() { var builderSetup = new BuilderSetup(); builderSetup.AutoNameProperties = false; var obj = new Builder<MyClass>(builderSetup).CreateNew().Build(); Assert.That(obj.Int, Is.EqualTo(0)); }
public void Building_single_objects_5() { BuilderSetup builderSetup = new BuilderSetup(); var child = new Category(); var category = new Builder <Category>(builderSetup).CreateNew() .Do(x => x.AddChild(child)) .Build(); }
public void ShouldBeAbleToCreateAList() { BuilderSetup builderSetup = new BuilderSetup(); var list = new Builder <MyClass>(builderSetup).CreateListOfSize(10).Build(); Assert.That(list.Count, Is.EqualTo(10)); }
public void ShouldBeAbleToCreateAnObject() { var builderSetup = new BuilderSetup(); var obj = new Builder<MyClassWithConstructor>(builderSetup).CreateNew().WithConstructorArgs(theString, theDecimal).Build(); Assert.That(obj.String, Is.EqualTo(theString)); Assert.That(obj.Decimal, Is.EqualTo(theDecimal)); }
public void SetUp() { var builderSetup = new BuilderSetup(); reflectionUtil = Substitute.For <IReflectionUtil>(); generator = Substitute.For <IRandomGenerator>(); propertyNamer = new RandomValuePropertyNamer(generator, reflectionUtil, false, builderSetup); }
public void ShouldBeAbleToCreateAnObject() { var builderSetup = new BuilderSetup(); var obj = new Builder <MyClassWithConstructor>(builderSetup).CreateNew().WithConstructorArgs(theString, theDecimal).Build(); Assert.That(obj.String, Is.EqualTo(theString)); Assert.That(obj.Decimal, Is.EqualTo(theDecimal)); }
public void ShouldChooseCorrectConstructor() { var builderSetup = new BuilderSetup(); var obj = new Builder <MyClassWithConstructor>(builderSetup).CreateNew().WithConstructorArgs(theInt, theFloat).Build(); Assert.That(obj.Int, Is.EqualTo(theInt)); Assert.That(obj.Float, Is.EqualTo(theFloat)); }
public void SetUp() { mocks = new MockRepository(); persistenceService = mocks.DynamicMock <IPersistenceService>(); repository = mocks.DynamicMock <IMyClassRepository>(); builderSetup = new BuilderSetup(); builderSetup.SetPersistenceService(this.persistenceService); }
public void ShouldBeAbleToCreateAList() { BuilderSetup builderSetup = new BuilderSetup(); var list = new Builder<MyClass>(builderSetup).CreateListOfSize(10).Build(); Assert.That(list.Count, Is.EqualTo(10)); }
public void RegisteringACustomPersistenceService() { BuilderSetup.SetPersistenceService(new MockCustomPersistenceService()); Builder <Product> .CreateNew().Persist(); Assert.That(MockCustomPersistenceService.ProductPersisted, Is.True); }
public void Just_the_date() { var builderSetup = new BuilderSetup(); var product = new Builder<Product>(builderSetup).CreateNew() .With(x => x.Created = On.May.The14th) .Build(); Assert.That(product.Created, Is.EqualTo(new DateTime(DateTime.Now.Year, 05, 14, 00, 00, 00))); }
public void SetUp() { BuilderSetup builderSetup = new BuilderSetup(); IReflectionUtil reflectionUtil = MockRepository.GenerateStub <IReflectionUtil>(); reflectionUtil.Stub(p => p.IsDefaultValue(Arg <int> .Is.Anything)).Return(true); propertyNamer = new PropertyNamerStub(reflectionUtil, builderSetup); }
public void WillComplainIfYouDoNotSupplyArgsMatchingOneOfTheConstructors() { var builderSetup = new BuilderSetup(); new Builder <BasketItem>(builderSetup) .CreateListOfSize(10) .All() .AreConstructedWith().Build(); }
public void ShouldBeAbleToDisableAutomaticPropertyNamingForASpecificFieldOfASpecificType() { BuilderSetup.DisablePropertyNamingFor <MyClass, int>(x => x.Int); var obj = Builder <MyClass> .CreateNew().Build(); Assert.That(obj.Int, Is.EqualTo(0)); Assert.That(obj.Long, Is.EqualTo(1)); }
public void Do() { var builderSetup = new BuilderSetup(); new Builder<Product>(builderSetup) .CreateListOfSize(10) .All() .WithLongTitles() .Build(); }
public void PropertiesShouldBeGivenDefaultValues() { var builderSetup = new BuilderSetup(); var obj = new Builder<MyClass>(builderSetup).CreateNew().Build(); Assert.That(obj.Int, Is.EqualTo(1)); Assert.That(obj.StringOne, Is.EqualTo("StringOne1")); Assert.That(obj.StringTwo, Is.EqualTo("StringTwo1")); Assert.That(obj.EnumProperty, Is.EqualTo(MyEnum.EnumValue1)); }
public void PropertiesShouldBeSetSequentially() { BuilderSetup builderSetup = new BuilderSetup(); var list = new Builder<MyClass>(builderSetup).CreateListOfSize(10).Build(); Assert.That(list[0].StringOne, Is.EqualTo("StringOne1")); Assert.That(list[9].StringOne, Is.EqualTo("StringOne10")); Assert.That(list[0].EnumProperty, Is.EqualTo(MyEnum.EnumValue1)); Assert.That(list[9].EnumProperty, Is.EqualTo(MyEnum.EnumValue5)); }
public void ShouldBeAbleToDisableAutomaticPropertyNamingForASpecificFieldOfASpecificType() { var builderSetup = new BuilderSetup(); builderSetup.DisablePropertyNamingFor<MyClass, int>(x => x.Int); var obj = new Builder<MyClass>(builderSetup).CreateNew().Build(); Assert.That(obj.Int, Is.EqualTo(0)); Assert.That(obj.Long, Is.EqualTo(1)); }
public void ShouldBeAbleToCreateAListOfAClassThatHasANullCharConstant() { var builderSetup = new BuilderSetup(); var list = new Builder<MyClassWithCharConst>(builderSetup).CreateListOfSize(2).Build(); foreach (var item in list) { Assert.That(item.GetNullCharConst(), Is.EqualTo(MyClassWithCharConst.NullCharConst)); } }
public void SetUp() { builderSetup = new BuilderSetup(); mocks = new MockRepository(); listBuilderImpl = mocks.DynamicMock<IListBuilderImpl<SimpleClass>>(); objectBuilder = mocks.StrictMock<IObjectBuilder<SimpleClass>>(); listBuilderImpl.Stub(x => x.Capacity).Return(2); listBuilderImpl.Stub(x => x.BuilderSetup).Return(builderSetup); objectBuilder.Stub(x => x.BuilderSetup).Return(builderSetup).Repeat.Any(); ; }
public void ShouldBeAbleToUseAndToSetPrivateProperties() { var builderSetup = new BuilderSetup(); using (mocks.Record()) { operable.Expect(x => x.ObjectBuilder).Return(new ObjectBuilder<MyClass>(null, builderSetup)); objectBuilder.Expect(x => x.With(propertyExpression, 100)); } OperableExtensions.And((IOperable<MyClass>)operable, propertyExpression, 100); }
public void ShouldBeAbleToUseAnd() { var builderSetup = new BuilderSetup(); using (mocks.Record()) { operable.Expect(x => x.ObjectBuilder).Return(new ObjectBuilder<MyClass>(null, builderSetup)); objectBuilder.Expect(x => x.With(func)); } OperableExtensions.And((IOperable<MyClass>)operable, func); }
public void Not_specifying_the_year() { // (Defaults to current year) var builderSetup = new BuilderSetup(); var product = new Builder<Product>(builderSetup).CreateNew() .With(x => x.Created = On.July.The21st.At(07, 00)) .Build(); Assert.That(product.Created, Is.EqualTo(new DateTime(DateTime.Now.Year, 07, 21, 07, 00, 00))); }
public void ShouldBeAbleToUseAndWithAnIndex() { var builderSetup = new BuilderSetup(); Action<MyClass, int> funcWithIndex = (x, idx) => x.StringOne = "String" + (idx + 5); using (mocks.Record()) { operable.Expect(x => x.ObjectBuilder).Return(new ObjectBuilder<MyClass>(null, builderSetup)); objectBuilder.Expect(x => x.With(funcWithIndex)); } OperableExtensions.And((IOperable<MyClass>)operable, funcWithIndex); }
public void should_be_able_to_create_a_list_using_legacy_syntax() { var builderSetup = new BuilderSetup(); var list = new Builder<MyClassWithConstructor>(builderSetup) .CreateListOfSize(10) .All() .AreConstructedWith(theString, theDecimal) .Build(); Assert.That(list.Count, Is.EqualTo(10)); }
public void Fluent_dates_example() { var builderSetup = new BuilderSetup(); var product = new Builder<Product>(builderSetup) .CreateNew() .With(x => x.Created = The.Year(2006).On.May.The10th.At(09, 00)) .With(x => x.LastEdited = On.August.The15th.At(15, 43)) .Build(); Assert.That(product.Created, Is.EqualTo(new DateTime(2006, 5, 10, 09, 00, 00))); Assert.That(product.LastEdited, Is.EqualTo(new DateTime(DateTime.Now.Year, 8, 15, 15, 43, 00))); }
public void should_be_able_to_use_WithConstructor() { var builderSetup = new BuilderSetup(); var list = new Builder<MyClassWithConstructor>(builderSetup) .CreateListOfSize(10) .All() .WithConstructor(() => new MyClassWithConstructor(1, 2f)) .Build(); Assert.That(list.Count, Is.EqualTo(10)); }
public void should_be_able_to_use_IsConstructedUsing() { var builderSetup = new BuilderSetup(); var list = new Builder<MyClassWithConstructor>(builderSetup) .CreateListOfSize(1) .TheFirst(1) .IsConstructedUsing(() => new MyClassWithConstructor(1, 2f)) .Build(); Assert.That(list.Count, Is.EqualTo(1)); }
public void should_set_properties_through_constructor_args_using_legacy_syntax() { var builderSetup = new BuilderSetup(); var list = new Builder<MyClassWithConstructor>(builderSetup) .CreateListOfSize(10) .All() .AreConstructedWith(theString, theDecimal) .Build(); Assert.That(list[0].String, Is.EqualTo(theString)); Assert.That(list[0].Decimal, Is.EqualTo(theDecimal)); }
public void ShouldBeAbleToPickUsingExactlyConstraint() { var builderSetup = new BuilderSetup(); var simpleClasses =new Builder<SimpleClass>(builderSetup).CreateListOfSize(10).Build(); var products = new Builder<MyClass>(builderSetup) .CreateListOfSize(10) .All() .With(x => x.SimpleClasses = Pick<SimpleClass>.UniqueRandomList(With.Exactly(1).Elements).From(simpleClasses)).Build(); for (int i = 0; i < products.Count; i++) Assert.That(products[i].SimpleClasses.Count, Is.EqualTo(1)); }
public void Static_month_names() { // You can use the month names on their own without On // which one you use is just a matter of preference or one or the other // might read better in different contexts. var builderSetup = new BuilderSetup(); var product = new Builder<Product>(builderSetup).CreateNew() .With(x => x.Created = December.The10th.At(09, 00)) .Build(); Assert.That(product.Created, Is.EqualTo(new DateTime(DateTime.Now.Year, 12, 10, 09, 00, 00))); }
public void should_be_able_to_use_legacy_singular_syntax() { var builderSetup = new BuilderSetup(); var list = new Builder<MyClassWithConstructor>(builderSetup) .CreateListOfSize(1) .TheFirst(1) .IsConstructedWith(theString, theDecimal) .Build(); Assert.That(list[0].String, Is.EqualTo(theString)); Assert.That(list[0].Decimal, Is.EqualTo(theDecimal)); }
public void AutomaticPropertyAndPublicFieldNamingCanBeSwitchedOff() { var builderSetup = new BuilderSetup(); builderSetup.AutoNameProperties = false; var products = new Builder<Product>(builderSetup).CreateListOfSize(10).Build(); Assert.That(products[0].Title, Is.Null); Assert.That(products[9].Title, Is.Null); Assert.That(products[0].Id, Is.EqualTo(0)); Assert.That(products[9].Id, Is.EqualTo(0)); }
public void CallingMultipleMethods() { var builderSetup = new BuilderSetup(); var child = new Builder<Category>(builderSetup).CreateNew().Build(); var anotherChild = new Builder<Category>(builderSetup).CreateNew().Build(); var category = new Builder<Category>(builderSetup) .CreateNew() .Do(x => x.AddChild(child)) .And(x => x.AddChild(anotherChild)) .Build(); Assert.That(category.Children[0], Is.EqualTo(child)); Assert.That(category.Children[1], Is.EqualTo(anotherChild)); }