public void WriteObject_Throws_ErrorTypeMustBeODataErrorOrHttpError()
 {
     ODataErrorSerializer serializer = new ODataErrorSerializer();
     Assert.Throws<SerializationException>(
         () => serializer.WriteObject(42, ODataTestUtil.GetMockODataMessageWriter(), new ODataSerializerContext()),
         "The type 'System.Int32' is not supported by the ODataErrorSerializer. The type must be ODataError or HttpError.");
 }
        public void WriteObject_ThrowsArgumentNull_MessageWriter()
        {
            ODataErrorSerializer serializer = new ODataErrorSerializer();

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: 42, messageWriter: null, writeContext: null),
                "messageWriter");
        }
        public void WriteObject_ThrowsArgumentNull_Graph()
        {
            ODataErrorSerializer serializer = new ODataErrorSerializer();

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: null, type: typeof(ODataError),messageWriter: null, writeContext: null),
                "graph");
        }
Ejemplo n.º 4
0
        public void WriteObject_Throws_ErrorTypeMustBeODataErrorOrHttpError()
        {
            ODataErrorSerializer serializer = new ODataErrorSerializer();

            Assert.Throws <SerializationException>(
                () => serializer.WriteObject(42, ODataTestUtil.GetMockODataMessageWriter(), new ODataSerializerContext()),
                "The type 'System.Int32' is not supported by the ODataErrorSerializer. The type must be ODataError or HttpError.");
        }
Ejemplo n.º 5
0
        public void WriteObject_ThrowsArgumentNull_MessageWriter()
        {
            ODataErrorSerializer serializer = new ODataErrorSerializer();

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: 42, messageWriter: null, writeContext: null),
                "messageWriter");
        }
Ejemplo n.º 6
0
        public void WriteObject_ThrowsArgumentNull_Graph()
        {
            ODataErrorSerializer serializer = new ODataErrorSerializer();

            Assert.ThrowsArgumentNull(
                () => serializer.WriteObject(graph: null, type: typeof(ODataError), messageWriter: null, writeContext: null),
                "graph");
        }
        public void WriteObject_SupportsHttpError()
        {
            var serializer = new ODataErrorSerializer();
            var error = new HttpError("bad stuff");
            Mock<IODataResponseMessage> mockResponseMessage = new Mock<IODataResponseMessage>();
            mockResponseMessage.Setup(response => response.GetStream()).Returns(new MemoryStream());

            Assert.DoesNotThrow(() => serializer.WriteObject(error, new ODataMessageWriter(mockResponseMessage.Object), new ODataSerializerContext()));
        }
        public void WriteObject_SupportsHttpError()
        {
            var serializer = new ODataErrorSerializer();
            var error      = new HttpError("bad stuff");
            Mock <IODataResponseMessage> mockResponseMessage = new Mock <IODataResponseMessage>();

            mockResponseMessage.Setup(response => response.GetStream()).Returns(new MemoryStream());

            Assert.DoesNotThrow(() => serializer.WriteObject(error, new ODataMessageWriter(mockResponseMessage.Object), new ODataSerializerContext()));
        }
        public void ODataErrorSerializer_Works()
        {
            // Arrange
            ODataErrorSerializer serializer = new ODataErrorSerializer();
            MemoryStream stream = new MemoryStream();
            IODataResponseMessage message = new ODataMessageWrapper(stream);
            ODataError error = new ODataError { Message = "Error!!!" };

            // Act
            serializer.WriteObject(error, new ODataMessageWriter(message), new ODataSerializerContext());

            // Assert
            stream.Seek(0, SeekOrigin.Begin);
            XElement element = XElement.Load(stream);
            Assert.Equal("Error!!!", element.Descendants().Single(e => e.Name.LocalName == "message").Value);
        }
Ejemplo n.º 10
0
        public void ODataErrorSerializer_Works()
        {
            // Arrange
            ODataErrorSerializer  serializer = new ODataErrorSerializer();
            MemoryStream          stream     = new MemoryStream();
            IODataResponseMessage message    = new ODataMessageWrapper(stream);
            ODataError            error      = new ODataError {
                Message = "Error!!!"
            };

            // Act
            serializer.WriteObject(error, new ODataMessageWriter(message), new ODataSerializerContext());

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

            Assert.Equal("Error!!!", element.Descendants().Single(e => e.Name.LocalName == "message").Value);
        }