public void WriteObject_ThrowsArgumentNull_WriteContext()
 {
     ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());
     Assert.ThrowsArgumentNull(
         () => serializer.WriteObject(graph: null, type: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: null),
         "writeContext");
 }
 public void WriteObject_ThrowsArgumentNull_MessageWriter()
 {
     ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());
     Assert.ThrowsArgumentNull(
         () => serializer.WriteObject(graph: null, type: null, messageWriter: null, writeContext: new ODataSerializerContext()),
         "messageWriter");
 }
        public void WriteDeltaFeedInline_Can_WriteCollectionOfIEdmChangedObjects()
        {
            // Arrange
            IEdmTypeReference           edmType   = new EdmEntityTypeReference(new EdmEntityType("NS", "Name"), isNullable: false);
            IEdmCollectionTypeReference feedType  = new EdmCollectionTypeReference(new EdmCollectionType(edmType));
            Mock <IEdmChangedObject>    edmObject = new Mock <IEdmChangedObject>();

            edmObject.Setup(e => e.GetEdmType()).Returns(edmType);

            var mockWriter = new Mock <ODataDeltaWriter>();

            Mock <ODataResourceSerializer> customerSerializer = new Mock <ODataResourceSerializer>(_serializerProvider);

            customerSerializer.Setup(s => s.WriteDeltaObjectInline(edmObject.Object, edmType, mockWriter.Object, _writeContext)).Verifiable();

            Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>();

            serializerProvider.Setup(s => s.GetEdmTypeSerializer(edmType)).Returns(customerSerializer.Object);

            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(serializerProvider.Object);

            // Act
            serializer.WriteDeltaFeedInline(new[] { edmObject.Object }, feedType, mockWriter.Object, _writeContext);

            // Assert
            customerSerializer.Verify();
        }
        public void WriteObject_ThrowsArgumentNull_WriteContext()
        {
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: null, type: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: null),
                "writeContext");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultODataSerializerProvider"/> class.
 /// </summary>
 public DefaultODataSerializerProvider()
 {
     _feedSerializer = new ODataFeedSerializer(this);
     _deltaFeedSerializer = new ODataDeltaFeedSerializer(this);
     _collectionSerializer = new ODataCollectionSerializer(this);
     _complexTypeSerializer = new ODataComplexTypeSerializer(this);
     _entityTypeSerializer = new ODataEntityTypeSerializer(this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultODataSerializerProvider"/> class.
 /// </summary>
 public DefaultODataSerializerProvider()
 {
     _feedSerializer        = new ODataFeedSerializer(this);
     _deltaFeedSerializer   = new ODataDeltaFeedSerializer(this);
     _collectionSerializer  = new ODataCollectionSerializer(this);
     _complexTypeSerializer = new ODataComplexTypeSerializer(this);
     _entityTypeSerializer  = new ODataEntityTypeSerializer(this);
 }
Exemple #7
0
        public void WriteDeltaFeedInline_ThrowsArgumentNull_Writer()
        {
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());

            Assert.ThrowsArgumentNull(
                () => serializer.WriteDeltaFeedInline(graph: null, expectedType: null, writer: null, writeContext: new ODataSerializerContext()),
                "writer");
        }
        public void WriteObject_ThrowsArgumentNull_MessageWriter()
        {
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: null, type: null, messageWriter: null, writeContext: new ODataSerializerContext()),
                "messageWriter");
        }
        public void WriteDeltaFeedInline_ThrowsArgumentNull_WriteContext()
        {
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);

            Assert.ThrowsArgumentNull(
                () => serializer.WriteDeltaFeedInline(graph: null, expectedType: null, writer: new Mock <ODataDeltaWriter>().Object, writeContext: null),
                "writeContext");
        }
        public void WriteObject_ThrowsEntitySetMissingDuringSerialization()
        {
            object graph = new object();
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);

            Assert.Throws <SerializationException>(
                () => serializer.WriteObject(graph: graph, type: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: new ODataSerializerContext()),
                "The related entity set could not be found from the OData path. The related entity set is required to serialize the payload.");
        }
        public void WriteDeltaFeedInline_ThrowsSerializationException_IfGraphIsNotEnumerable()
        {
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);

            Assert.Throws <SerializationException>(
                () => serializer.WriteDeltaFeedInline(graph: 42, expectedType: _customersType,
                                                      writer: new Mock <ODataDeltaWriter>().Object, writeContext: _writeContext),
                "ODataDeltaFeedSerializer cannot write an object of type 'System.Int32'.");
        }
        public void WriteDeltaFeedInline_ThrowsSerializationException_CannotSerializerNull()
        {
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);

            Assert.Throws <SerializationException>(
                () => serializer.WriteDeltaFeedInline(graph: null, expectedType: _customersType,
                                                      writer: new Mock <ODataDeltaWriter>().Object, writeContext: _writeContext),
                "Cannot serialize a null 'deltafeed'.");
        }
        public void WriteDeltaFeedInline_Throws_NullElementInCollection_IfFeedContainsNullElement()
        {
            // Arrange
            IEnumerable instance = new object[] { null };
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);

            // Act
            Assert.Throws <SerializationException>(
                () => serializer.WriteDeltaFeedInline(instance, _customersType, new Mock <ODataDeltaWriter>().Object, _writeContext),
                "Collections cannot contain null elements.");
        }
        public void CreateODataDeltaFeed_Sets_NextPageLinkForPageResult()
        {
            // Arrange
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(_serializerProvider);
            Uri        expectedNextLink         = new Uri("http://nextlink.com");
            const long ExpectedCountValue       = 1000;

            var result = new PageResult <Customer>(_customers, expectedNextLink, ExpectedCountValue);

            // Act
            ODataDeltaResourceSet feed = serializer.CreateODataDeltaFeed(result, _customersType, new ODataSerializerContext());

            // Assert
            Assert.Equal(expectedNextLink, feed.NextPageLink);
        }
        public void WriteDeltaFeedInline_Throws_TypeCannotBeSerialized_IfFeedContainsEntityThatCannotBeSerialized()
        {
            // Arrange
            Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>();
            HttpRequestMessage             request            = new HttpRequestMessage();

            serializerProvider.Setup(s => s.GetODataPayloadSerializer(typeof(int), request)).Returns <ODataSerializer>(null);
            IEnumerable instance = new object[] { 42 };
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(serializerProvider.Object);

            // Act
            Assert.Throws <SerializationException>(
                () => serializer.WriteDeltaFeedInline(instance, _customersType, new Mock <ODataDeltaWriter>().Object, _writeContext),
                "ODataDeltaFeedSerializer cannot write an object of type 'System.Object[]'.");
        }
        public void WriteDeltaFeedInline_WritesEachEntityInstance()
        {
            // Arrange
            Mock <ODataResourceSerializer> customerSerializer = new Mock <ODataResourceSerializer>(_serializerProvider);
            ODataSerializerProvider        provider           = ODataTestUtil.GetMockODataSerializerProvider(customerSerializer.Object);
            var mockWriter = new Mock <ODataDeltaWriter>();

            customerSerializer.Setup(s => s.WriteDeltaObjectInline(_deltaFeedCustomers[0], _customersType.ElementType(), mockWriter.Object, _writeContext)).Verifiable();
            _serializer = new ODataDeltaFeedSerializer(provider);

            // Act
            _serializer.WriteDeltaFeedInline(_deltaFeedCustomers, _customersType, mockWriter.Object, _writeContext);

            // Assert
            customerSerializer.Verify();
        }
 public void WriteDeltaFeedInline_ThrowsArgumentNull_WriteContext()
 {
     ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());
     Assert.ThrowsArgumentNull(
         () => serializer.WriteDeltaFeedInline(graph: null, expectedType: null, writer: new Mock<ODataDeltaWriter>().Object, writeContext: null),
         "writeContext");
 }
        public void WriteDeltaFeedInline_Throws_TypeCannotBeSerialized_IfFeedContainsEntityThatCannotBeSerialized()
        {
            // Arrange
            Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>();
            HttpRequestMessage request = new HttpRequestMessage();
            serializerProvider.Setup(s => s.GetODataPayloadSerializer(_model, typeof(int), request)).Returns<ODataSerializer>(null);
            IEnumerable instance = new object[] { 42 };
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(serializerProvider.Object);

            // Act
            Assert.Throws<SerializationException>(
                () => serializer.WriteDeltaFeedInline(instance, _customersType, new Mock<ODataDeltaWriter>().Object, _writeContext),
                "ODataDeltaFeedSerializer cannot write an object of type 'System.Object[]'.");
        }
        public void WriteDeltaFeedInline_Can_WriteCollectionOfIEdmChangedObjects()
        {
            // Arrange
            IEdmTypeReference edmType = new EdmEntityTypeReference(new EdmEntityType("NS", "Name"), isNullable: false);
            IEdmCollectionTypeReference feedType = new EdmCollectionTypeReference(new EdmCollectionType(edmType));
            Mock<IEdmChangedObject> edmObject = new Mock<IEdmChangedObject>();
            edmObject.Setup(e => e.GetEdmType()).Returns(edmType);

            var mockWriter = new Mock<ODataDeltaWriter>();

            Mock<ODataEntityTypeSerializer> customerSerializer = new Mock<ODataEntityTypeSerializer>(new DefaultODataSerializerProvider());
            customerSerializer.Setup(s => s.WriteDeltaObjectInline(edmObject.Object, edmType, mockWriter.Object, _writeContext)).Verifiable();

            Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>();
            serializerProvider.Setup(s => s.GetEdmTypeSerializer(edmType)).Returns(customerSerializer.Object);

            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(serializerProvider.Object);

            // Act
            serializer.WriteDeltaFeedInline(new[] { edmObject.Object }, feedType, mockWriter.Object, _writeContext);

            // Assert
            customerSerializer.Verify();
        }
        public void WriteDeltaFeedInline_WritesEachEntityInstance()
        {
            // Arrange
            Mock<ODataEntityTypeSerializer> customerSerializer = new Mock<ODataEntityTypeSerializer>(new DefaultODataSerializerProvider());
            ODataSerializerProvider provider = ODataTestUtil.GetMockODataSerializerProvider(customerSerializer.Object);
            var mockWriter = new Mock<ODataDeltaWriter>();
            customerSerializer.Setup(s => s.WriteDeltaObjectInline(_deltaFeedCustomers[0], _customersType.ElementType(), mockWriter.Object, _writeContext)).Verifiable();
            _serializer = new ODataDeltaFeedSerializer(provider);

            // Act
            _serializer.WriteDeltaFeedInline(_deltaFeedCustomers, _customersType, mockWriter.Object, _writeContext);

            // Assert
            customerSerializer.Verify();
        }
        public void CreateODataDeltaFeed_Sets_NextPageLinkForPageResult()
        {
            // Arrange
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());
            Uri expectedNextLink = new Uri("http://nextlink.com");
            const long ExpectedCountValue = 1000;

            var result = new PageResult<Customer>(_customers, expectedNextLink, ExpectedCountValue);

            // Act
            ODataDeltaFeed feed = serializer.CreateODataDeltaFeed(result, _customersType, new ODataSerializerContext());

            // Assert
            Assert.Equal(expectedNextLink, feed.NextPageLink);
        }
 public void WriteDeltaFeedInline_ThrowsSerializationException_CannotSerializerNull()
 {
     ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());
     Assert.Throws<SerializationException>(
         () => serializer.WriteDeltaFeedInline(graph: null, expectedType: _customersType,
             writer: new Mock<ODataDeltaWriter>().Object, writeContext: _writeContext),
         "Cannot serialize a null 'deltafeed'.");
 }
 public void WriteDeltaFeedInline_ThrowsSerializationException_IfGraphIsNotEnumerable()
 {
     ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());
     Assert.Throws<SerializationException>(
         () => serializer.WriteDeltaFeedInline(graph: 42, expectedType: _customersType,
             writer: new Mock<ODataDeltaWriter>().Object, writeContext: _writeContext),
         "ODataDeltaFeedSerializer cannot write an object of type 'System.Int32'.");
 }
 public void WriteObject_ThrowsEntitySetMissingDuringSerialization()
 {
     object graph = new object();
     ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());
     Assert.Throws<SerializationException>(
         () => serializer.WriteObject(graph: graph, type: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: new ODataSerializerContext()),
         "The related entity set could not be found from the OData path. The related entity set is required to serialize the payload.");
 }
        public void WriteDeltaFeedInline_Throws_NullElementInCollection_IfFeedContainsNullElement()
        {
            // Arrange
            IEnumerable instance = new object[] { null };
            ODataDeltaFeedSerializer serializer = new ODataDeltaFeedSerializer(new DefaultODataSerializerProvider());

            // Act
            Assert.Throws<SerializationException>(
                () => serializer.WriteDeltaFeedInline(instance, _customersType, new Mock<ODataDeltaWriter>().Object, _writeContext),
                "Collections cannot contain null elements.");
        }