public void AddForConcreteVersion_Resolve_Success()
        {
            var myDeserializer = new CustomDeserializer("MyPackformatName", 1, null);

            var deserializerCollection = (DeserializerCollection)DeserializerCollection.New.Add(myDeserializer);

            deserializerCollection.ResolveDeserializer(new DeserializerKey("MyPackformatName", 1)).Should().Be(myDeserializer);
        }
        public void AddForConcreteVersion_ResolveForAnotherVersion_ReturnsNull()
        {
            var myDeserializer = new CustomDeserializer("MyPackformatName", 1, null);

            var deserializerCollection = (DeserializerCollection)DeserializerCollection.New.Add(myDeserializer);

            deserializerCollection.ResolveDeserializer(new DeserializerKey("MyPackformatName", 2)).Should().BeNull();
        }
Exemplo n.º 3
0
        public void Copy_RootElement_From_Request_To_IWithRootElement_Deserializer()
        {
            _server.SetHandler(Handlers.Generic <ResponseHandler>());
            RestRequest request = new RestRequest("success")
            {
                RootElement = "Success"
            };
            var deserializer = new CustomDeserializer();

            _client.AddHandler(ContentType.Xml, () => deserializer);
            _client.Execute <Response>(request);

            Assert.AreEqual(deserializer.RootElement, request.RootElement);
        }
        public void AddTwoCustomDeserializersForTheSameMethod_NotThrows()
        {
            var myCustomDeserializer1 = new CustomDeserializer("MyPackformatName", 1, null);
            var myCustomDeserializer2 = new CustomDeserializer("MyPackformatName", 1, null);

            Action action = () =>
            {
                var deserializerCollection = (DeserializerCollection)DeserializerCollection.New
                                             .Add(myCustomDeserializer1)
                                             .Add(myCustomDeserializer2);
            };

            action.ShouldNotThrow <ShapeshifterException>();
        }
Exemplo n.º 5
0
        public void Copy_RootElement_From_Request_To_IWithRootElement_Deserializer()
        {
            using var server = HttpServerFixture.StartServer("success", Handle);

            var client = new RestClient(server.Url);

            var request = new RestRequest("success")
            {
                RootElement = "Success"
            };

            var deserializer = new CustomDeserializer();

            client.AddHandler(ContentType.Xml, () => deserializer);
            client.Execute <Response>(request);

            Assert.AreEqual(request.RootElement, deserializer.RootElement);
        public void AddTwoCustomDeserializersForDifferentMethods_Throws()
        {
            var method1 = typeof(DeserializerCollectionTests).GetMethod("Method1", BindingFlags.Instance | BindingFlags.NonPublic);
            var method2 = typeof(DeserializerCollectionTests).GetMethod("Method2", BindingFlags.Instance | BindingFlags.NonPublic);

            var myCustomDeserializer1 = new CustomDeserializer("MyPackformatName", 1, method1);
            var myCustomDeserializer2 = new CustomDeserializer("MyPackformatName", 1, method2);

            Action action = () =>
            {
                var deserializerCollection = (DeserializerCollection)DeserializerCollection.New
                                             .Add(myCustomDeserializer1)
                                             .Add(myCustomDeserializer2);
            };

            action.ShouldThrow <ShapeshifterException>().Where(i => i.Id == Exceptions.DeserializerAlreadyExistsId);
        }
Exemplo n.º 7
0
        static DictionaryConverter()
        {
            CustomSerializer.TryAdd(typeof(byte), DefaultSerializer);
            CustomSerializer.TryAdd(typeof(bool), DefaultSerializer);
            CustomSerializer.TryAdd(typeof(short), DefaultSerializer);
            CustomSerializer.TryAdd(typeof(int), DefaultSerializer);
            CustomSerializer.TryAdd(typeof(long), DefaultSerializer);
            CustomSerializer.TryAdd(typeof(float), DefaultSerializer);
            CustomSerializer.TryAdd(typeof(double), DefaultSerializer);
            CustomSerializer.TryAdd(typeof(string), DefaultSerializer);

            CustomDeserializer.TryAdd(typeof(byte), DefaultDeserializer <byte>);
            CustomDeserializer.TryAdd(typeof(bool), DefaultDeserializer <bool>);
            CustomDeserializer.TryAdd(typeof(short), DefaultDeserializer <short>);
            CustomDeserializer.TryAdd(typeof(int), DefaultDeserializer <int>);
            CustomDeserializer.TryAdd(typeof(long), DefaultDeserializer <long>);
            CustomDeserializer.TryAdd(typeof(float), DefaultDeserializer <float>);
            CustomDeserializer.TryAdd(typeof(double), DefaultDeserializer <double>);
            CustomDeserializer.TryAdd(typeof(string), DefaultDeserializer <string>);
        }
        public void AddCustomAndDefaultDeserializerForConcreteVersion_InAnyOrder_Resolve_CustomDeserializerIsReturned()
        {
            var myDefaultDeserializer = new DefaultDeserializer(new SerializableTypeInfo(null, "MyPackformatName", 1, new List <FieldOrPropertyMemberInfo>()));
            var myCustomDeserializer  = new CustomDeserializer("MyPackformatName", 1, null);

            {
                var deserializerCollection = (DeserializerCollection)DeserializerCollection.New
                                             .Add(myCustomDeserializer)
                                             .Add(myDefaultDeserializer);

                deserializerCollection.ResolveDeserializer(new DeserializerKey("MyPackformatName", 1)).Should().Be(myCustomDeserializer);
            }
            {
                var deserializerCollection = (DeserializerCollection)DeserializerCollection.New
                                             .Add(myDefaultDeserializer)
                                             .Add(myCustomDeserializer);

                deserializerCollection.ResolveDeserializer(new DeserializerKey("MyPackformatName", 1)).Should().Be(myCustomDeserializer);
            }
        }
        public void AddCustoDeserializerForDerivedType_OverridesCustomDeserializerCreatedFromBaseTypeForAllDescendants_WorksInAnyOrder()
        {
            var explicitDeserializer = new CustomDeserializer("MyPackformatName", 1, null, CustomSerializerCreationReason.Explicit);
            var implicitDeserializer = new CustomDeserializer("MyPackformatName", 1, null, CustomSerializerCreationReason.ImplicitByBaseType, typeof(int));

            {
                var deserializerCollection = (DeserializerCollection)DeserializerCollection.New
                                             .Add(explicitDeserializer)
                                             .Add(implicitDeserializer);

                deserializerCollection.ResolveDeserializer(new DeserializerKey("MyPackformatName", 1)).Should().Be(explicitDeserializer);
            }
            {
                var deserializerCollection = (DeserializerCollection)DeserializerCollection.New
                                             .Add(implicitDeserializer)
                                             .Add(explicitDeserializer);

                deserializerCollection.ResolveDeserializer(new DeserializerKey("MyPackformatName", 1)).Should().Be(explicitDeserializer);
            }
        }