public void Nested_Lambda_Is_Applied_On_Nested_Builder() { var builder = new ExampleClassBuilder() .WithReferenceProp(x => x.WithStringProp("I am child")); ExampleClass res = builder.Create(); res.ReferenceProp.StringProp.Should().Be("I am child"); }
public void Setup_Is_Applied_On_Create() { var builder = new ExampleClassBuilder(); builder.Setup(x => x.WithStringProp("Foo")); ExampleClass res = builder.Create(); res.StringProp.Should().Be("Foo"); }
public void BuildUsing_Will_Use_The_Custom_Factory() { var factory = Substitute.For <IBuilderFactory>(); factory.Create <ExampleClassBuilder>().Returns(new ExampleClassBuilder()); var builder = new ExampleClassBuilder(); builder.BuildUsing <ExampleClassBuilder>(); builder.Should().BeOfType <ExampleClassBuilder>(); }
public void Setup_Overrides_On_Create() { var builder = new ExampleClassBuilder() .WithStringProp("Foo"); builder.Setup(x => x.WithStringProp("Bar")); var res = builder.Create(); res.StringProp.Should().Be("Bar"); }
public void The_Supplied_Factory_Is_Asked_For_Builder_Instance_Of_Nested_Builder() { var factory = Substitute.For <IBuilderFactory>(); factory.Create <ExampleReferencedClassBuilder>().Returns(new ExampleReferencedClassBuilder()); var builder = new ExampleClassBuilder(); builder.BuilderFactoryConvention.UseFactory(factory); builder .WithReferenceProp() .Create(); factory.Received().Create <ExampleReferencedClassBuilder>(); }
public void AddMany_With_Builder_Options_Will_Apply_These_Options_To_Each_Builder() { var parentBuilder = new ExampleClassBuilder(); var test = parentBuilder .WithChildren(c => c .AddOne()) .Create(); var t = new CollectionBuilder <ExampleChildClass, ExampleChildClassBuilder>(parentBuilder); t.AddMany(3, opts => opts.WithSomething("ploeh")); t.Builders.Should().OnlyContain(x => x.Something == "ploeh"); }
public void Nested_Lambda_With_Instance_Uses_The_Instance() { var something = "I am from instance"; var someDate = DateTime.Now.AddDays(-1); var exampleReferencedClass = new ExampleReferencedClassBuilder().WithDateTimeProp(someDate).WithStringProp(something).Create(); var builder = new ExampleClassBuilder() .WithReferenceProp(x => x.WithInstance(exampleReferencedClass)); var res = builder.Create(); res.ReferenceProp.StringProp.Should().Be(something); res.ReferenceProp.DateProp.Should().Be(someDate); }