Exemplo n.º 1
0
        public void MultipleGetInstance_ShouldThrowException_EvenWithModificationEnabled()
        {
            var builder = new InstanceBuilder <TestClass>(true);

            builder.GetInstance();

            Action action = () => builder.GetInstance();

            action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.InstanceAlreadyGivenAwayId);
        }
Exemplo n.º 2
0
            public static MyClassWithComplexField Deserialize(IShapeshifterReader reader)
            {
                var builder = new InstanceBuilder <MyClassWithComplexField>(reader);

                builder.SetMember("_myIntField", 44);
                return(builder.GetInstance());
            }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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());
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        public void InstancePopulatedFromReader()
        {
            var objectProperties = new ObjectProperties(new Dictionary <string, object>()
            {
                { Constants.TypeNameKey, "TestClass" },
                { Constants.VersionKey, (long)1 },
                { "_basePrivateField", "Hello" },
                { "BasePrivateProperty", 42 },
                { "_childPrivateField", "Seeya" },
                { "ChildPrivateProperty", 43 },
            });
            var reader = new ShapeshifterReader(objectProperties);

            var builder  = new InstanceBuilder <TestClass>(reader);
            var instance = builder.GetInstance();

            instance.GetBasePrivateField().Should().Be("Hello");
            instance.GetBasePrivateProperty().Should().Be(42);
            instance.GetChildPrivateField().Should().Be("Seeya");
            instance.GetChildPrivateProperty().Should().Be(43);
        }