public void CanSerializerSingleton()
        {
            // Arrange
            const string expect = "{" +
                                  "\"@odata.context\":\"http://localhost/odata/$metadata#Boss\"," +
                                  "\"EmployeeId\":987,\"EmployeeName\":\"John Mountain\"}";

            IEdmModel              model       = GetEdmModel();
            IEdmSingleton          singleton   = model.EntityContainer.FindSingleton("Boss");
            HttpRequestMessage     request     = GetRequest(model, singleton);
            ODataSerializerContext readContext = new ODataSerializerContext()
            {
                Url              = new UrlHelper(request),
                Path             = request.ODataProperties().Path,
                Model            = model,
                NavigationSource = singleton
            };

            ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider();
            EmployeeModel           boss = new EmployeeModel {
                EmployeeId = 987, EmployeeName = "John Mountain"
            };
            MemoryStream bufferedStream = new MemoryStream();

            // Act
            ODataEntityTypeSerializer serializer = new ODataEntityTypeSerializer(serializerProvider);

            serializer.WriteObject(boss, typeof(EmployeeModel), GetODataMessageWriter(model, bufferedStream), readContext);

            // Assert
            string result = Encoding.UTF8.GetString(bufferedStream.ToArray());

            Assert.Equal(expect, result);
        }
 /// <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);
 }
示例#3
0
 public SampleODataSerializerProvider()
 {
     _sampleEntityTypeSerializer = new SampleODataEntityTypeSerializer(this);
 }
示例#4
0
 public SerializerProvider()
 {
     this.entityTypeSerializer = new NotProvidedFilteringEntityTypeSerializer(this);
 }