public void PrimitiveTypesSerializeAsOData(Type valueType, object value, MediaTypeHeaderValue mediaType,
                                                   string resourceName)
        {
            string expectedEntity = Resources.GetString(resourceName);

            Assert.NotNull(expectedEntity);

            ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();

            modelBuilder.EntitySet <WorkItem>("WorkItems");
            IEdmModel model = modelBuilder.GetEdmModel();

            string actualEntity;

            using (HttpConfiguration configuration = CreateConfiguration())
                using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
                                                                           "http://localhost/WorkItems(10)/ID"))
                {
                    request.SetConfiguration(configuration);
                    IEdmProperty property =
                        model.EntityContainer.EntitySets().Single().EntityType().Properties().First();
                    request.ODataProperties().Model = model;
                    request.ODataProperties().Path  = new ODataPath(new PropertyAccessPathSegment(property));
                    request.SetFakeODataRouteName();

                    ODataMediaTypeFormatter formatter = CreateFormatter(request);
                    formatter.SupportedMediaTypes.Add(mediaType);

                    Type type = (value != null) ? value.GetType() : typeof(Nullable <int>);

                    using (ObjectContent content = new ObjectContent(type, value, formatter))
                    {
                        actualEntity = content.ReadAsStringAsync().Result;
                    }
                }

            JsonAssert.Equal(expectedEntity, actualEntity);
        }
Exemple #2
0
        public static void VerifyResponse(HttpContent actualContent, string expected)
        {
            string actual = actualContent.ReadAsStringAsync().Result;

            JsonAssert.Equal(expected, actual);
        }