public async Task ODataMetadataSerializer_Works()
        {
            // Arrange
            ODataMetadataSerializer serializer = new ODataMetadataSerializer();
            IEdmModel model = new EdmModel();

            // 1) XML
            // Act
            string payload = await this.WriteAndGetPayloadAsync(model, "application/xml", async omWriter =>
            {
                await serializer.WriteObjectAsync("42" /*useless*/, typeof(IEdmModel), omWriter, new ODataSerializerContext());
            });

            // Assert
            Assert.Contains("<edmx:Edmx Version=\"4.0\"", payload);

            // 2) JSON
            // Act
            payload = await this.WriteAndGetPayloadAsync(model, "application/json", async omWriter =>
            {
                await serializer.WriteObjectAsync("42" /*useless*/, typeof(IEdmModel), omWriter, new ODataSerializerContext());
            });

            // Assert
            Assert.Equal(@"{
  ""$Version"": ""4.0""
}", payload);
        }
예제 #2
0
        public void WriteObject_ThrowsArgumentNull_MessageWriter()
        {
            ODataMetadataSerializer serializer = new ODataMetadataSerializer();

            ExceptionAssert.ThrowsArgumentNull(
                () => serializer.WriteObject(42, typeof(IEdmModel), messageWriter: null, writeContext: null),
                "messageWriter");
        }
예제 #3
0
        public async Task WriteObjectAsync_ThrowsArgumentNull_MessageWriter()
        {
            // Arrange
            ODataMetadataSerializer serializer = new ODataMetadataSerializer();

            // Act & Assert
            await ExceptionAssert.ThrowsArgumentNullAsync(
                () => serializer.WriteObjectAsync(42, typeof(IEdmModel), messageWriter: null, writeContext: null),
                "messageWriter");
        }
예제 #4
0
        public void ODataMetadataSerializer_Works()
        {
            // Arrange
            ODataMetadataSerializer    serializer = new ODataMetadataSerializer();
            MemoryStream               stream     = new MemoryStream();
            IODataResponseMessage      message    = new ODataMessageWrapper(stream);
            ODataMessageWriterSettings settings   = new ODataMessageWriterSettings();
            IEdmModel model = new EdmModel();

            // Act
            serializer.WriteObject("42", typeof(IEdmModel), new ODataMessageWriter(message, settings, model), new ODataSerializerContext());

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

            Assert.Equal("Edmx", element.Name.LocalName);
        }
예제 #5
0
        public void ODataMetadataSerializer_Works_ForSingleton()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.Singleton <Customer>("Me");
            IEdmModel model = builder.GetEdmModel();

            ODataMetadataSerializer    serializer = new ODataMetadataSerializer();
            MemoryStream               stream     = new MemoryStream();
            IODataResponseMessage      message    = new ODataMessageWrapper(stream);
            ODataMessageWriterSettings settings   = new ODataMessageWriterSettings();

            // Act
            serializer.WriteObject(model, typeof(IEdmModel), new ODataMessageWriter(message, settings, model), new ODataSerializerContext());

            // Assert
            stream.Seek(0, SeekOrigin.Begin);
            string result = new StreamReader(stream).ReadToEnd();

            Assert.Contains("<Singleton Name=\"Me\" Type=\"Microsoft.AspNetCore.OData.Tests.Formatter.Serialization.Customer\" />", result);
        }
        public async Task ODataMetadataSerializer_Works_ForSingleton()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.Singleton <Customer>("Me");
            IEdmModel model = builder.GetEdmModel();
            ODataMetadataSerializer serializer = new ODataMetadataSerializer();

            // XML
            // Act
            string payload = await this.WriteAndGetPayloadAsync(model, "application/xml", async omWriter =>
            {
                await serializer.WriteObjectAsync(model, typeof(IEdmModel), omWriter, new ODataSerializerContext());
            });

            // Assert
            Assert.Contains("<Singleton Name=\"Me\" Type=\"Microsoft.AspNetCore.OData.Tests.Formatter.Serialization.Customer\" />", payload);

            // JSON
            // Act
            payload = await this.WriteAndGetPayloadAsync(model, "application/json", async omWriter =>
            {
                await serializer.WriteObjectAsync(model, typeof(IEdmModel), omWriter, new ODataSerializerContext());
            });

            // Assert
            Assert.Contains(@"  ""Default"": {
    ""Container"": {
      ""$Kind"": ""EntityContainer"",
      ""Me"": {
        ""$Type"": ""Microsoft.AspNetCore.OData.Tests.Formatter.Serialization.Customer""
      }
    }
  }", payload);
        }