コード例 #1
0
 public void WriteObject_ThrowsArgumentNull_WriteContext()
 {
     ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();
     Assert.ThrowsArgumentNull(
         () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: null),
         "writeContext");
 }
コード例 #2
0
 public void WriteObject_ThrowsArgumentNull_MessageWriter()
 {
     ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();
     Assert.ThrowsArgumentNull(
         () => serializer.WriteObject(graph: null, messageWriter: null, writeContext: new ODataSerializerContext()),
         "messageWriter");
 }
        public void WriteObject_ThrowsArgumentNull_WriteContext()
        {
            ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: null),
                "writeContext");
        }
        public void WriteObject_ThrowsArgumentNull_MessageWriter()
        {
            ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: null, messageWriter: null, writeContext: new ODataSerializerContext()),
                "messageWriter");
        }
        public void WriteObject_Throws_EntitySetMissingDuringSerialization()
        {
            ODataEntityReferenceLinkSerializer serializer   = new ODataEntityReferenceLinkSerializer();
            ODataSerializerContext             writeContext = new ODataSerializerContext();

            Assert.Throws <SerializationException>(
                () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "The related entity set could not be found from the OData path. The related entity set is required to serialize the payload.");
        }
コード例 #6
0
        public void WriteObject_Throws_NavigationPropertyMissingDuringSerialization()
        {
            ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();
            ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = new ODataPath() };

            Assert.Throws<SerializationException>(
                () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "The related navigation property could not be found from the OData path. The related navigation property is required to serialize the payload.");
        }
コード例 #7
0
        public void WriteObject_Throws_ODataPathMissing()
        {
            ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();
            ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet };

            Assert.Throws<SerializationException>(
                () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "The operation cannot be completed because no ODataPath is available for the request.");
        }
コード例 #8
0
        public void WriteObject_Throws_EntitySetMissingDuringSerialization()
        {
            ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();
            ODataSerializerContext writeContext = new ODataSerializerContext();

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

            Assert.Throws <SerializationException>(
                () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "The related navigation property could not be found from the OData path. The related navigation property is required to serialize the payload.");
        }
        public void WriteObject_Throws_ODataPathMissing()
        {
            ODataEntityReferenceLinkSerializer serializer   = new ODataEntityReferenceLinkSerializer();
            ODataSerializerContext             writeContext = new ODataSerializerContext {
                EntitySet = _customerSet
            };

            Assert.Throws <SerializationException>(
                () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "The operation cannot be completed because no ODataPath is available for the request.");
        }
コード例 #11
0
        public void WriteObject_Throws_ObjectCannotBeWritten_IfGraphIsNotUri()
        {
            IEdmNavigationProperty navigationProperty = _customerSet.ElementType.NavigationProperties().First();
            ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();
            ODataPath path = new ODataPath(new NavigationPathSegment(navigationProperty));
            ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = path };

            Assert.Throws<SerializationException>(
                () => serializer.WriteObject(graph: "not uri", messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "ODataEntityReferenceLinkSerializer cannot write an object of type 'System.String'.");
        }
        public void WriteObject_Throws_ObjectCannotBeWritten_IfGraphIsNotUri()
        {
            IEdmNavigationProperty             navigationProperty = _customerSet.ElementType.NavigationProperties().First();
            ODataEntityReferenceLinkSerializer serializer         = new ODataEntityReferenceLinkSerializer();
            ODataPath path = new ODataPath(new NavigationPathSegment(navigationProperty));
            ODataSerializerContext writeContext = new ODataSerializerContext {
                EntitySet = _customerSet, Path = path
            };

            Assert.Throws <SerializationException>(
                () => serializer.WriteObject(graph: "not uri", messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "ODataEntityReferenceLinkSerializer cannot write an object of type 'System.String'.");
        }
        public void ODataEntityReferenceLinkSerializer_Serializes_Uri()
        {
            // Arrange
            ODataEntityReferenceLinkSerializer serializer         = new ODataEntityReferenceLinkSerializer();
            IEdmNavigationProperty             navigationProperty = _customerSet.ElementType.NavigationProperties().First();
            ODataPath path = new ODataPath(new NavigationPathSegment(navigationProperty));
            ODataSerializerContext writeContext = new ODataSerializerContext {
                EntitySet = _customerSet, Path = path
            };
            MemoryStream          stream  = new MemoryStream();
            IODataResponseMessage message = new ODataMessageWrapper(stream);

            // Act
            serializer.WriteObject(new Uri("http://sampleuri/"), new ODataMessageWriter(message), writeContext);

            // Assert
            stream.Seek(0, SeekOrigin.Begin);
            XElement element = XElement.Load(stream);

            Assert.Equal("http://sampleuri/", element.Value);
        }
コード例 #14
0
        public void ODataEntityReferenceLinkSerializer_Serializes_Uri(object link)
        {
            // Arrange
            ODataEntityReferenceLinkSerializer serializer = new ODataEntityReferenceLinkSerializer();
            IEdmNavigationProperty navigationProperty = _customerSet.ElementType.NavigationProperties().First();
            ODataPath path = new ODataPath(new NavigationPathSegment(navigationProperty));
            ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = path };
            MemoryStream stream = new MemoryStream();
            IODataResponseMessage message = new ODataMessageWrapper(stream);

            // Act
            serializer.WriteObject(link, typeof(ODataEntityReferenceLink), new ODataMessageWriter(message), writeContext);

            // Assert
            stream.Seek(0, SeekOrigin.Begin);
            XElement element = XElement.Load(stream);
            Assert.Equal("http://sampleuri/", element.Value);
        }