public void NonNullableTopLevelPropertiesTest()
        {
            // Create a Test case
            var testCase = new NonNullablePropertiesTestCase()
            {
                RequestUris = new string[] { "/People(1)/Office", "/People(1)/Name", "/People(1)/Body", "/People(1)/Age" },
                HttpMethods = new string[] { "PUT"},
            };            

            // Run the variations
            test.TestUtil.RunCombinations(
                new DSPUnitTestServiceDefinition[]{ service },
                testCase.HttpMethods,
                testCase.RequestUris,
                new string[] { UnitTestsUtil.JsonLightMimeType, UnitTestsUtil.MimeApplicationXml },
                ServiceVersion.ValidVersions, // requestDSV
                ServiceVersion.ValidVersions, // requestMDSV
                ServiceVersion.ValidVersions, // maxProtocolVersion
                (localService, httpMethod, requestUri, format, requestDSV, requestMDSV, maxProtocolVersion) =>
                {
                    if (maxProtocolVersion == null)
                    {
                        return;
                    }

                    localService.DataServiceBehavior.MaxProtocolVersion = maxProtocolVersion.ToProtocolVersion();
                    using (TestWebRequest request = localService.CreateForInProcess())
                    {
                        if (requestDSV != null && maxProtocolVersion.ToProtocolVersion() < requestDSV.ToProtocolVersion())
                        {
                            return;
                        }
                        request.StartService();
                        request.HttpMethod = httpMethod;
                        request.RequestUriString = requestUri;
                        request.Accept = format;
                        if (requestDSV != null) request.RequestVersion = requestDSV.ToString();
                        if (requestMDSV != null) request.RequestMaxVersion = requestMDSV.ToString();                           
                           
                        request.RequestContentType = format;
                        if (format == UnitTestsUtil.JsonLightMimeType)
                        {
                            request.SetRequestStreamAsText(@"{ @odata.null : true }");       
                        }
                        else if(format == UnitTestsUtil.MimeApplicationXml)
                        {
                            request.SetRequestStreamAsText(@"<" + requestUri.Substring(requestUri.LastIndexOf("/") + 1) + " xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" m:null=\"true\" />");       
                        }                           

                        IDisposable dispose = null;
                        if (httpMethod != "GET")
                        {
                            dispose = service.CreateChangeScope(GetDefaultData(service.Metadata));
                        }

                        var exception = test.TestUtil.RunCatching(request.SendRequest);
                        Assert.IsNotNull(exception, "Exception is always expected.");
                        Assert.IsNotNull(exception.InnerException, "InnerException is always expected.");

                        if (requestUri.Substring(requestUri.LastIndexOf("/") + 1) == "Office")
                        {
                            Assert.AreEqual("System.Data.Entity", exception.InnerException.Source, "Source expected: System.Data.Entity, actual: " + exception.InnerException.Source);
                            Assert.AreEqual(500, request.ResponseStatusCode, "Status code expected: 500" + ", actual: " + request.ResponseStatusCode);
                        }
                        else
                        {
                            // For primitive properties provider decides what to do. For EF, we get an exception with response code of 500.
                            Assert.AreEqual(500, request.ResponseStatusCode, "Status code expected: 500" + ", actual: " + request.ResponseStatusCode);
                        }

                        dispose.Dispose();
                    }
                });
        }
示例#2
0
        public void NonNullableTopLevelPropertiesTest()
        {
            // Create a Test case
            var testCase = new NonNullablePropertiesTestCase()
            {
                RequestUris = new string[] { "/People(1)/Name", "/People(1)/Body", "/People(1)/Age" },
                HttpMethods = new string[] { "PUT" },
            };

            // Run the variations
            test.TestUtil.RunCombinations(
                new DSPUnitTestServiceDefinition[] { service },
                testCase.HttpMethods,
                testCase.RequestUris,
                new string[] { UnitTestsUtil.JsonLightMimeType },
                ServiceVersion.ValidVersions, // requestDSV
                ServiceVersion.ValidVersions, // requestMDSV
                ServiceVersion.ValidVersions, // maxProtocolVersion
                (localService, httpMethod, requestUri, format, requestDSV, requestMDSV, maxProtocolVersion) =>
            {
                if (maxProtocolVersion == null)
                {
                    return;
                }

                localService.DataServiceBehavior.MaxProtocolVersion = maxProtocolVersion.ToProtocolVersion();
                using (TestWebRequest request = localService.CreateForInProcess())
                {
                    if (requestDSV != null && maxProtocolVersion.ToProtocolVersion() < requestDSV.ToProtocolVersion())
                    {
                        return;
                    }
                    request.StartService();
                    request.HttpMethod       = httpMethod;
                    request.RequestUriString = requestUri;
                    request.Accept           = format;
                    if (requestDSV != null)
                    {
                        request.RequestVersion = requestDSV.ToString();
                    }
                    if (requestMDSV != null)
                    {
                        request.RequestMaxVersion = requestMDSV.ToString();
                    }

                    request.RequestContentType = format;
                    // TODO: Change the payload of null top-level properties #645
                    request.SetRequestStreamAsText(@"{ ""value"" : null }");

                    IDisposable dispose = null;
                    if (httpMethod != "GET")
                    {
                        dispose = service.CreateChangeScope(GetDefaultData(service.Metadata));
                    }

                    var exception = test.TestUtil.RunCatching(request.SendRequest);
                    Assert.IsNotNull(exception, "Exception is always expected.");
                    Assert.IsNotNull(exception.InnerException, "InnerException is always expected.");

                    if (requestUri.Substring(requestUri.LastIndexOf("/") + 1) == "Office")
                    {
                        Assert.AreEqual("System.Data.Entity", exception.InnerException.Source, "Source expected: System.Data.Entity, actual: " + exception.InnerException.Source);
                        Assert.AreEqual(500, request.ResponseStatusCode, "Status code expected: 500" + ", actual: " + request.ResponseStatusCode);
                    }
                    else
                    {
                        // For primitive properties provider decides what to do. For EF, we get an exception with response code of 500.
                        Assert.AreEqual(500, request.ResponseStatusCode, "Status code expected: 500" + ", actual: " + request.ResponseStatusCode);
                    }

                    dispose.Dispose();
                }
            });
        }