public async void WhenUsedToDeserializeShouldCreateCorrectObject()
        {
            var formatter = new ProtoBufFormatter();
            var item = new Item { Id = 1, Name = "Filip" };
            var content = new ObjectContent<Item>(item, formatter);

            var deserializedItem = await content.ReadAsAsync<Item>(new[] {formatter});
            Assert.Same(item, deserializedItem);
        }
Пример #2
0
        public async void WhenUsedToDeserializeShouldCreateCorrectObject()
        {
            var formatter = new ProtoBufFormatter();
            var item      = new Item {
                Id = 1, Name = "Filip"
            };
            var content = new ObjectContent <Item>(item, formatter);

            var deserializedItem = await content.ReadAsAsync <Item>(new[] { formatter });

            Assert.Same(item, deserializedItem);
        }
        public async void WhenWritingToStreamShouldSuccessfullyComplete()
        {
            var formatter = new ProtoBufFormatter();
            var item = new Item { Id = 1, Name = "Filip" };

            var ms = new MemoryStream();
            await formatter.WriteToStreamAsync(typeof (Item), item, ms, new ByteArrayContent(new byte[0]),
                new Mock<TransportContext>().Object);

            var deserialized = ProtoBufFormatter.Model.Deserialize(ms, null, typeof (Item));

            Assert.Same(deserialized, item);
        }
Пример #4
0
        public async void WhenWritingToStreamShouldSuccessfullyComplete()
        {
            var formatter = new ProtoBufFormatter();
            var item      = new Item {
                Id = 1, Name = "Filip"
            };

            var ms = new MemoryStream();
            await formatter.WriteToStreamAsync(typeof(Item), item, ms, new ByteArrayContent(new byte[0]),
                                               new Mock <TransportContext>().Object);

            var deserialized = ProtoBufFormatter.Model.Deserialize(ms, null, typeof(Item));

            Assert.Same(deserialized, item);
        }
Пример #5
0
        public async void WhenReadingFromStreamShouldSuccessfullyComplete()
        {
            var formatter = new ProtoBufFormatter();
            var item      = new Item {
                Id = 1, Name = "Filip"
            };

            var ms = new MemoryStream();

            ProtoBufFormatter.Model.Serialize(ms, item);

            var deserialized = await formatter.ReadFromStreamAsync(typeof(Item), ms, new ByteArrayContent(new byte[0]),
                                                                   new Mock <IFormatterLogger>().Object);

            Assert.Same(deserialized as Item, item);
        }
        public async void WhenReadingFromStreamShouldSuccessfullyComplete()
        {
            var formatter = new ProtoBufFormatter();
            var item = new Item { Id = 1, Name = "Filip" };

            var ms = new MemoryStream();
            ProtoBufFormatter.Model.Serialize(ms, item);

            var deserialized = await formatter.ReadFromStreamAsync(typeof(Item), ms, new ByteArrayContent(new byte[0]),
                new Mock<IFormatterLogger>().Object);

            Assert.Same(deserialized as Item, item);
        }
 public void WhenCallingCanWriteShouldBeAbleToWriteTypesItUnderstands()
 {
     var formatter = new ProtoBufFormatter();
     var canWrite = formatter.CanWriteType(typeof(Item));
     Assert.True(canWrite);
 }
 public void WhenCallingCanWriteShouldNotBeAbleToWriteTypesItDoesNotUnderstand()
 {
     var formatter = new ProtoBufFormatter();
     var canWrite = formatter.CanWriteType(typeof(EvilItem));
     Assert.False(canWrite);
 }