public void The_Concrete_Builder_Is_Asked_To_Construct_With_The_Given_Seed() { var builder = new BuilderForTesting <ExampleClass>(); builder.Create(42); builder.WasAskedToConstructWithSeeds.Should().Contain(42); }
public void The_Created_Instance_Matches_The_Factory_Generic() { var builder = new BuilderForTesting <ExampleClass>(); object instance = builder.Create(); instance.Should().BeOfType <ExampleClass>(); }
public void CreateMany_Builds_Different_Instances() { var builderForTesting = new BuilderForTesting <ExampleClass>(); ExampleClass[] results = builderForTesting.CreateMany(3).ToArray(); results.Should().OnlyHaveUniqueItems(); }
public void The_Concrete_Builder_Is_Asked_To_Construct() { var builder = new BuilderForTesting <ExampleClass>(); builder.Create(); builder.WasAskedToConstruct.Should().BeTrue(); }
public void CreateMany_Pass_Sequental_Seeds_To_Build_Method() { var builderForTesting = new BuilderForTesting <ExampleClassBuilder>(); builderForTesting.CreateMany(3); builderForTesting.WasAskedToConstructWithSeeds.Should().ContainInOrder(new[] { 0, 1, 2 }); }
public void AddOne_Will_Return_The_Builder_It_Just_Added_To_Builders() { var parentBuilder = new BuilderForTesting <ExampleClass>(); var t = new CollectionBuilder <ExampleChildClass, ExampleChildClassBuilder>(parentBuilder); var res = t.AddOne(); t.Builders.Should().OnlyContain(x => x == res); }
public void A_Property_Can_Be_Set_Using_Arbitrary_Key() { var builder = new BuilderForTesting <ExampleClass>(); builder.SetProperty(Key, "my opt in"); var res = builder.GetProperty(Key, "default"); res.Should().Be("my opt in"); }
public void Second_Create_Builds_A_Different_Instance() { var builderForTesting = new BuilderForTesting <ExampleClass>(); ExampleClass result1 = builderForTesting.Create(); ExampleClass result2 = builderForTesting.Create(); result1.Should().NotBeSameAs(result2); }
public void Multiple_Creates_Pass_Seeds_To_Build_Method() { var builderForTesting = new BuilderForTesting <ExampleClass>(); builderForTesting.Create(42); builderForTesting.Create(1); builderForTesting.WasAskedToConstructWithSeeds.Should().ContainInOrder(new[] { 42, 1 }); }
public void GetProperty_Default_Func_Is_Invoked_If_SetProperty_Does_Not_Exist() { var builder = new BuilderForTesting <ExampleClass>(); var wasInvoked = false; builder.GetProperty(x => x.StringProp, () => { wasInvoked = true; return(string.Empty); }); wasInvoked.Should().BeTrue("Opt in was not present, so default func should be invoked"); }
public void Customizations_Are_Performed_On_Built_Instance() { string customString = Generate.RandomString(50); ExampleClass result = new BuilderForTesting <ExampleClass>() .Customize(b => b.StringProp = customString) .Create(); result.StringProp.Should().Be(customString, "customize was used to set the property."); }
public void Can_Use_Nested_Builder() { var builder = new BuilderForTesting <ExampleClass>(); builder.SetProperty <ExampleReferencedClassBuilder>(x => x.ReferenceProp); var res = builder.GetProperty(x => x.ReferenceProp, () => null); res.Should().NotBeNull("Nested builder should create an instance."); }
public void AddMany_Will_Reuse_Same_Item_Builder() { var parentBuilder = new BuilderForTesting <ExampleClass>(); var t = new CollectionBuilder <ExampleChildClass, ExampleChildClassBuilder>(parentBuilder); t.AddMany(3); t.Builders.Count.Should().Be(3); t.Builders.Should().OnlyContain(x => x == t.Builders[0]); }
public void A_String_Prop_Can_Be_Set() { var builder = new BuilderForTesting <ExampleClass>(); const string str = "abc"; builder.SetProperty(x => x.StringProp, str); var res = builder.GetProperty(x => x.StringProp, string.Empty); res.Should().Be(str, "String prop should be set on the created class"); }
public void AddOne_Will_Add_Item_Builder_To_Builders() { var parentBuilder = new BuilderForTesting <ExampleClass>(); var t = new CollectionBuilder <ExampleChildClass, ExampleChildClassBuilder>(parentBuilder); t.AddOne(); t.Builders.Count.Should().Be(1, "only one builder should be added"); t.Builders.Should().ContainItemsAssignableTo <ExampleChildClassBuilder>(); }
public void Can_Use_Nested_Builder_With_SetProperty() { var builder = new BuilderForTesting <ExampleClass>(); builder.SetProperty <ExampleReferencedClassBuilder>(x => x.ReferenceProp, opts: o => o.WithStringProp("abc")); var res = builder.GetProperty(x => x.ReferenceProp, () => null); res.Should().NotBeNull("Nested builder should create an instance."); res.StringProp.Should().Be("abc", "Nested builder should create an instance with applied opt-ins for the builder."); }
public void A_DateTime_Prop_Can_Be_Set() { var builder = new BuilderForTesting <ExampleClass>(); var now = DateTime.Now; builder.SetProperty(x => x.DateProp, now); var res = builder.GetProperty(x => x.DateProp, DateTime.MinValue); res.Should().Be(now, "DateTime prop should be set on the created class"); }
public void GetProperty_Default_Func_Is_Not_Ivoked_If_SetProperty_Exists() { var builder = new BuilderForTesting <ExampleClass>(); string str = Generate.RandomString(10); bool wasInvoked = false; builder.SetProperty(x => x.StringProp, str); builder.GetProperty(x => x.StringProp, () => { wasInvoked = true; return(String.Empty); }); wasInvoked.Should().BeFalse("Opt in was present, so default func should not be invoked"); }
public void AddOne_With_Instance_Will_Add_Item_Builder_With_That_Instance_To_Builders() { var parentBuilder = new BuilderForTesting <ExampleClass>(); var t = new CollectionBuilder <ExampleChildClass, ExampleChildClassBuilder>(parentBuilder); var c = new ExampleChildClass(); t.AddOne(c); t.Builders.Count.Should().Be(1); t.CreateAll().Should().OnlyContain(x => x == c); }
public void AddMany_With_Instances_Will_Add_Item_Builders_With_These_Instances_To_Builders() { var parentBuilder = new BuilderForTesting <ExampleClass>(); var t = new CollectionBuilder <ExampleChildClass, ExampleChildClassBuilder>(parentBuilder); var c = new[] { new ExampleChildClass(), new ExampleChildClass(), new ExampleChildClass() }; t.AddMany(c); t.Builders.Count.Should().Be(3); t.CreateAll().Should().Contain(c); }