Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        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.");
        }
Esempio n. 3
0
        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.");
        }
Esempio n. 4
0
        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");
        }
Esempio n. 5
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");
        }
Esempio n. 6
0
        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");
        }