예제 #1
0
        public static string DeserializeString(ReusableMemoryStream stream)
        {
            var len = BigEndianConverter.ReadInt16(stream);

            // per contract, null string is represented with -1 len.
            if (len == -1)
            {
                return(null);
            }

            return(_stringDeser.Deserialize(stream, len) as string);
        }
예제 #2
0
        /// <summary>
        /// Deserialize a byte array to an instance of <see cref="SubmitKey"/>.
        /// </summary>
        /// <param name="topic">The topic associated wih the data.</param>
        /// <param name="data">The serialized representation of an instance of <see cref="SubmitKey"/>.</param>
        /// <returns>A <see cref="SubmitKey"/> instance.</returns>
        public SubmitKey Deserialize(string topic, byte[] data)
        {
            var text   = InnerDeserializer.Deserialize(topic, data);
            var result = SubmitKey.FromString(text);

            return(result);
        }
		public void should_deserialize_Empty_xml_to_empty_object()
		{
			var deserializer = new StringDeserializer<TestEmptyObject>();

			var testObject = deserializer.Deserialize(EmptyXmlResponse);

			Assert.That(testObject, Is.Not.Null);
		}
        public void should_deserialize_Empty_xml_to_empty_object()
        {
            var deserializer = new StringDeserializer <TestEmptyObject>();

            var testObject = deserializer.Deserialize(EmptyXmlResponse);

            Assert.That(testObject, Is.Not.Null);
        }
예제 #5
0
        public void DeserializerConstructValueViaConfig()
        {
            string testString = "hello world";
            var    serialized = new StringSerializer(Encoding.UTF8).Serialize("mytopic", testString);
            var    config     = new Dictionary <string, object>();

            config.Add("dotnet.string.deserializer.encoding.value", "utf-8");
            var deserializer = new StringDeserializer();
            var newConfig    = deserializer.Configure(config, false);

            Assert.Equal(0, newConfig.Count());
            Assert.Equal(testString, deserializer.Deserialize("mytopic", serialized));
        }
		public void should_deserialize_well_formed_xml()
		{
			var deserializer = new StringDeserializer<TestObject>();

			var testObject = deserializer.Deserialize(TestObjectXmlResponse);

			Assert.That(testObject, Is.Not.Null);
			Assert.That(testObject.Id, Is.EqualTo(1));
			Assert.That(testObject.Name, Is.EqualTo( "A big test object"));

			Assert.That(testObject.StringList, Is.Not.Null);
			Assert.That(testObject.StringList.Count, Is.GreaterThan(0));
			
			Assert.That(testObject.ObjectList, Is.Not.Null);
			Assert.That(testObject.ObjectList.Count, Is.GreaterThan(0));
		}
        public void should_deserialize_well_formed_xml()
        {
            var deserializer = new StringDeserializer <TestObject>();

            var testObject = deserializer.Deserialize(TestObjectXmlResponse);

            Assert.That(testObject, Is.Not.Null);
            Assert.That(testObject.Id, Is.EqualTo(1));
            Assert.That(testObject.Name, Is.EqualTo("A big test object"));

            Assert.That(testObject.StringList, Is.Not.Null);
            Assert.That(testObject.StringList.Count, Is.GreaterThan(0));

            Assert.That(testObject.ObjectList, Is.Not.Null);
            Assert.That(testObject.ObjectList.Count, Is.GreaterThan(0));
        }
예제 #8
0
        public void TestStringSerialization()
        {
            using (var stream = new MemoryStream())
            {
                var serializer = new StringSerializer();
                Assert.That(() => serializer.Serialize(Value, stream), Throws.TypeOf <ArgumentException>());
                Assert.That(() => serializer.Serialize(TheValue, stream), Is.EqualTo(Value.Length));
                Assert.That(stream.Length, Is.EqualTo(Value.Length));
                CompareArrays(Value, stream.GetBuffer(), 0);

                var deserializer = new StringDeserializer();
                stream.Position = 0;
                var output = deserializer.Deserialize(stream, Value.Length) as string;
                Assert.That(output, Is.EqualTo(TheValue));
            }
        }
		public void should_throw_exception_when_deserialize_into_wrong_type()
		{
			var deserializer = new StringDeserializer<Status>();

			Assert.Throws<InvalidOperationException>(() => deserializer.Deserialize(TestObjectXmlResponse));
		}
		public void should_throw_exception_when_deserialize_into_wrong_type_such_as_one_that_is_not_wrapped_in_a_response_tag()
		{
			var deserializer = new StringDeserializer<Status>();

			Assert.Throws<UnexpectedXmlContentException>(() => deserializer.Deserialize(TestObjectXmlResponse.Replace("response", "rexponse")));
		}
        public void should_throw_exception_when_deserialize_into_wrong_type_such_as_one_that_is_not_wrapped_in_a_response_tag()
        {
            var deserializer = new StringDeserializer <Status>();

            Assert.Throws <UnexpectedXmlContentException>(() => deserializer.Deserialize(TestObjectXmlResponse.Replace("response", "rexponse")));
        }
        public void should_throw_exception_when_deserialize_into_wrong_type()
        {
            var deserializer = new StringDeserializer <Status>();

            Assert.Throws <UnexpectedXmlContentException>(() => deserializer.Deserialize(TestObjectXmlResponse));
        }