예제 #1
0
        public void IfValueIsOverwrittenTheNewValueIsRead()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.SetMember("_basePublicField", "Hello");
            builder.SetMember("_basePublicField", "Hi!");

            builder.GetMember <string>("_basePublicField").Should().Be("Hi!");
        }
예제 #2
0
        public void ValuesCanBeRead()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.SetMember("_basePublicField", "Hello");
            builder.SetMember("BasePublicProperty", 42);

            builder.GetMember <string>("_basePublicField").Should().Be("Hello");
            builder.GetMember <int>("BasePublicProperty").Should().Be(42);
        }
예제 #3
0
        public void BeforeInstantiation_ValueCanBeSetTwice()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.SetMember("_childPrivateField", "Ahoy");
            builder.SetMember("_childPrivateField", "Hello");

            var instance = builder.GetInstance();

            instance.GetChildPrivateField().Should().Be("Hello");
        }
예제 #4
0
        public void PrivateChildValuesCanBeSet()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.SetMember("_childPrivateField", "Hello");
            builder.SetMember("ChildPrivateProperty", 42);

            var instance = builder.GetInstance();

            instance.GetChildPrivateField().Should().Be("Hello");
            instance.GetChildPrivateProperty().Should().Be(42);
        }
예제 #5
0
        public void ValuesCanBeRead_AfterCreation()
        {
            var builder = new InstanceBuilder <TestClass>(true); //note that we enable after creation manipulation

            builder.SetMember("_basePublicField", "Hello");
            builder.SetMember("BasePublicProperty", 42);

            var instance = builder.GetInstance();

            builder.GetMember <string>("_basePublicField").Should().Be("Hello");
            builder.GetMember <int>("BasePublicProperty").Should().Be(42);
        }
예제 #6
0
        public void PublicBaseValuesCanBeSet()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.SetMember("_basePublicField", "Hello");
            builder.SetMember("BasePublicProperty", 42);

            var instance = builder.GetInstance();

            instance._basePublicField.Should().Be("Hello");
            instance.BasePublicProperty.Should().Be(42);
        }
예제 #7
0
        public static object DeserializerForOldVersion(IShapeshifterReader reader)
        {
            var builder = new InstanceBuilder <IndividualCustomer>();

            builder.SetMember("Name", reader.Read <string>("Name"));

            var oldAddress = reader.Read <string>("HomeAddress");

            builder.SetMember("HomeAddress", ConvertStringToAddress(oldAddress));

            builder.SetMember("Orders", reader.Read <List <Order> >("Orders"));
            return(builder.GetInstance());
        }
예제 #8
0
            public static MyClassWithComplexField Deserialize(IShapeshifterReader reader)
            {
                var builder = new InstanceBuilder <MyClassWithComplexField>(reader);

                builder.SetMember("_myIntField", 44);
                return(builder.GetInstance());
            }
예제 #9
0
        public void SetNonExistingMember_ShouldThrowException()
        {
            var builder = new InstanceBuilder <TestClass>();

            Action action = () => builder.SetMember("noSuchField", "Hello");

            action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.CannotFindFieldOrPropertyId);
        }
예제 #10
0
        public void SetMemberAfterGetInstance_EnabledModification_ShouldModifyTheValue()
        {
            var builder = new InstanceBuilder <TestClass>(true);

            var instance = builder.GetInstance();

            builder.SetMember("_childPrivateField", "Hello");
            instance.GetChildPrivateField().Should().Be("Hello");
        }
예제 #11
0
        public void SetWrongValue_ShouldThrowException()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.SetMember("_childPrivateField", 42);
            Action action = () => builder.GetInstance();

            action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.FailedToSetValueId);
        }
예제 #12
0
        public void SetMemberAfterGetInstance_ShouldThrowException()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.GetInstance();

            Action action = () => builder.SetMember("_childPrivateField", "Hello");

            action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.InstanceAlreadyGivenAwayId);
        }
예제 #13
0
        public void GetMember_AfterCreation_ShouldThrow()
        {
            var builder = new InstanceBuilder <TestClass>();

            builder.SetMember("_basePublicField", "Hello");

            var instance = builder.GetInstance();

            Action action = () => builder.GetMember <string>("_basePublicField");

            action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.InstanceAlreadyGivenAwayId);
        }
예제 #14
0
        public void InstancePopulatedFromReaderModifiedAfterwards_ButBeforeCreation()
        {
            var objectProperties = new ObjectProperties(new Dictionary <string, object>()
            {
                { Constants.TypeNameKey, "TestClass" },
                { Constants.VersionKey, (long)1 },
                { "_basePrivateField", "Hello" },
                { "BasePrivateProperty", "Invalid value" },
                { "_childPrivateField", "Seeya" },
                { "ChildPrivateProperty", 43 },
            });
            var reader  = new ShapeshifterReader(objectProperties);
            var builder = new InstanceBuilder <TestClass>(reader);

            builder.SetMember("BasePrivateProperty", 1);

            var instance = builder.GetInstance();

            instance.GetBasePrivateProperty().Should().Be(1);
        }