Exemple #1
0
        [Ignore] // test case issue, request uri and service root in this case is null.
        public void RequestQueryParserTestFilterTest()
        {
            var service = new OpenWebDataService <CustomDataContext>();

            service.AttachHost(new TestServiceHost2());
            CustomDataContext context = ServiceModelData.InitializeAndGetContext(service);

            Prov.ResourceType customerType = GetResourceTypeForContainer(service, "Customers");
            object            customerSet  = GetResourceSetWrapper(service, "Customers");
            IQueryable        result       = InvokeWhere(service, GetRequestDescription(customerType, customerSet, "Customers"), context.Customers, "ID eq 5");
            XmlDocument       document     = CreateDocumentFromIQueryable(result);

            Trace.WriteLine(document.InnerXml);
            UnitTestsUtil.VerifyXPaths(document,
                                       "/Source//*[@NodeType='Lambda']",
                                       "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']",
                                       "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']/*[@NodeType='Constant' and @Value='5']",
                                       "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']/*[@NodeType='MemberAccess' and contains(@Member, 'ID')]");
        }
        public void SerializeResponseBodyAcceptTypeWithCharsetTest()
        {
            // Verifies that the correct handling of 'charset' parameters in accept header media types.
            TestServiceHost host = new TestServiceHost();

            host.RequestPathInfo = "/Customers(0)/Name/$value";
            DataService <CustomDataContext> context = new OpenWebDataService <CustomDataContext>();

            const string TextPlain = "text/plain";
            var          tests     = TestUtil.CreateDictionary <string>(
                TextPlain, TextPlain,
                // valid charset of accept header should not be used for conneg
                TextPlain + ";charset=UTF-8", TextPlain,
                // invalid charset of accept header should not be used for conneg
                TextPlain + ";charset=aabbcc", TextPlain,
                // non-charset parameter should be used for matching
                TextPlain + ";some=value", null,
                // charset and non-charset parameters; non-charset one should be used for matching
                TextPlain + ";charset=utf-8;some=value", null
                );

            TestUtil.RunCombinations(tests, (test) =>
            {
                host.ClearResponse();
                context.AttachHost(host);
                string acceptTypes  = test.Key;
                string result       = test.Value;
                Exception exception = TestUtil.RunCatching(delegate()
                {
                    Trace.WriteLine("Running query with accept type: " + acceptTypes);
                    host.RequestAccept = acceptTypes;
                    context.ProcessRequest();
                });
                TestUtil.AssertExceptionExpected(exception, result == null);
                if (result != null)
                {
                    Assert.AreEqual(result, TestUtil.GetMediaType(host.ResponseContentType));
                }
            });
        }
Exemple #3
0
        public void DataServiceHostServiceRootUriTest()
        {
            // Edit link "../Product(1)" incorrectly produced when base uri is http://service.svc using IDSH
            // Make sure service root URIs always end in '/' when using an IDataServiceHost/IDataServiceHost2
            //
            // Verifies that the service root URI for a IDSH is always terminated in a '/'
            // NOTE: if the service URI would not be properly terminated in a '/', the created edit link in the resulting
            //       entry would be incorrect.
            Uri[] uris = new Uri[]
            {
                new Uri("http://host"),
                new Uri("http://host/a/b"),
                new Uri("http://host/a/b.svc"),
                new Uri("http://host/a/b/c.svc")
            };

            TestUtil.RunCombinations(uris, (uri) =>
            {
                TestServiceHost host = new TestServiceHost(uri)
                {
                    RequestAccept   = "application/atom+xml",
                    RequestPathInfo = "/Customers(0)",
                };

                DataService <CustomDataContext> context = new OpenWebDataService <CustomDataContext>();
                context.AttachHost(host);

                Exception exception = TestUtil.RunCatching(delegate()
                {
                    context.ProcessRequest();
                });

                XmlDocument document = new XmlDocument(TestUtil.TestNameTable);
                host.ResponseStream.Seek(0, SeekOrigin.Begin);
                document.Load(host.ResponseStream);
                UnitTestsUtil.VerifyXPaths(document, "/atom:entry/atom:link[@rel='edit' and @href='Customers(0)']");

                TestUtil.AssertExceptionExpected(exception, false);
            });
        }
Exemple #4
0
        public void RequestQueryParserTestNegativeTests()
        {
            // Repro Protocol: filter throws NYI when using null with arithmetic operators
            var service = new OpenWebDataService <CustomDataContext>();

            service.AttachHost(new TestServiceHost2());
            CustomDataContext context = ServiceModelData.InitializeAndGetContext(service);

            string[] predicates = new string[]
            {
                "1 eq 1 and not not 2 eq 1 add 1",
                "1 eq FakePropertyName",
                "1 eq '1'",
                "1 add",
                "'",
                "?",
                "1 add 1",
                "#",
                "endswith(123, 'abc')",
                "endswith('abc')",
                "endswith('abc', 123)",
                "0xaa eq 0xa",
                "0xaa eq 0xag",
                "null add 4 eq 1",
                "'a' add 'b' eq 'ab'",
                "endswith(Name add 'b', 'b')",
                "BestFriend add null",
            };

            // This way of getting the type is less ideal than getting it based on the
            // container name (see GetResourceTypeForContainer), because it does not work
            // for custom IDataServiceProvider implementations. In this case there seems to be
            // no other option.
            Prov.ResourceType customerType = GetResourceType(service, context.Customers.ElementType.FullName);
            object            customerSet  = GetResourceSetWrapper(service, "Customers");

            VerifyExceptionForWhere(service, customerSet, customerType, context.Customers, predicates);
        }
        public void SerializeResponseBodyAcceptTypeTest()
        {
            // Verifies that the correct Content-Type is selected at serialization time.
            TestServiceHost host = new TestServiceHost();

            host.RequestPathInfo = "/Customers";
            DataService <CustomDataContext> context = new OpenWebDataService <CustomDataContext>();

            const string AtomXml     = "application/atom+xml";
            const string AtomXmlFeed = "application/atom+xml;type=feed";
            const string charsetUtf8 = ";charset=utf-8";
            const string JsonLight   = "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false";

            var testCases = new[]
            {
                // Success cases for all versions
                new { AcceptHeaderString = "application/atom+xml, application/json", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "application/atom+xml, application/json;odata.metadata=minimal", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "application/json, application/atom+xml", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = (string)null, Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = " ", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "*/*", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = AtomXml, Expectation = AtomXmlFeed + charsetUtf8 },
                new { AcceptHeaderString = "application/json", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "application/xml,application/json;q=0.8", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = AtomXml + ",application/json;q=0.8", Expectation = AtomXmlFeed + charsetUtf8 },
                new { AcceptHeaderString = "application/json," + AtomXml + ";q=0.8", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "text/xml,*/*", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "application/xml,*/*", Expectation = JsonLight + charsetUtf8 },

                // Error cases for all versions
                new { AcceptHeaderString = "text/xml", Expectation = (string)null },
                new { AcceptHeaderString = "application/xml", Expectation = (string)null },
                new { AcceptHeaderString = "application/json;foo=bar", Expectation = (string)null },
                new { AcceptHeaderString = "application/json;odata.metadata=bla", Expectation = (string)null },
                new { AcceptHeaderString = "application/json;foo=bar", Expectation = (string)null },

                // Cases where V2 and V3 expected behaviors differ
                new { AcceptHeaderString = "application/json", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "application/json;odata.metadata=minimal", Expectation = JsonLight + charsetUtf8 },
                new { AcceptHeaderString = "application/json, application/json;odata.metadata=minimal", Expectation = JsonLight + charsetUtf8 },
            };

            TestUtil.RunCombinations(
                testCases,
                new string[] { "4.0" },
                (testCase, requestMaxVersion) =>
            {
                host.ClearResponse();
                context.AttachHost(host);
                string acceptTypes = testCase.AcceptHeaderString;
                string result      = testCase.Expectation;

                Exception exception = TestUtil.RunCatching(delegate()
                {
                    Trace.WriteLine("Running query with accept type: " + acceptTypes);
                    host.RequestAccept     = acceptTypes;
                    host.RequestMaxVersion = requestMaxVersion;
                    context.ProcessRequest();
                });
                TestUtil.AssertExceptionExpected(exception, result == null);
                if (result != null)
                {
                    Assert.AreEqual(result, host.ResponseContentType);
                }
            });
        }
        public void RequestQueryParserTestNegativeTests()
        {
            // Repro Protocol: filter throws NYI when using null with arithmetic operators
            var service = new OpenWebDataService<CustomDataContext>();
            service.AttachHost(new TestServiceHost2());
            CustomDataContext context = ServiceModelData.InitializeAndGetContext(service);
            string[] predicates = new string[]
            {
                "1 eq 1 and not not 2 eq 1 add 1",
                "1 eq FakePropertyName",
                "1 eq '1'",
                "1 add",
                "'",
                "?",
                "1 add 1",
                "#",
                "endswith(123, 'abc')",
                "endswith('abc')",
                "endswith('abc', 123)",
                "0xaa eq 0xa",
                "0xaa eq 0xag",
                "null add 4 eq 1",
                "'a' add 'b' eq 'ab'",
                "endswith(Name add 'b', 'b')",
                "BestFriend add null",
            };

            // This way of getting the type is less ideal than getting it based on the
            // container name (see GetResourceTypeForContainer), because it does not work
            // for custom IDataServiceProvider implementations. In this case there seems to be
            // no other option.
            Prov.ResourceType customerType = GetResourceType(service, context.Customers.ElementType.FullName);
            object customerSet = GetResourceSetWrapper(service, "Customers");
            VerifyExceptionForWhere(service, customerSet, customerType, context.Customers, predicates);
        }
 [Ignore] // test case issue, request uri and service root in this case is null.
 public void RequestQueryParserTestFilterTest()
 {
     var service = new OpenWebDataService<CustomDataContext>();
     service.AttachHost(new TestServiceHost2());
     CustomDataContext context = ServiceModelData.InitializeAndGetContext(service);
     Prov.ResourceType customerType = GetResourceTypeForContainer(service, "Customers");
     object customerSet = GetResourceSetWrapper(service, "Customers");
     IQueryable result = InvokeWhere(service, GetRequestDescription(customerType, customerSet, "Customers"), context.Customers, "ID eq 5");
     XmlDocument document = CreateDocumentFromIQueryable(result);
     Trace.WriteLine(document.InnerXml);
     UnitTestsUtil.VerifyXPaths(document,
         "/Source//*[@NodeType='Lambda']",
         "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']",
         "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']/*[@NodeType='Constant' and @Value='5']",
         "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']/*[@NodeType='MemberAccess' and contains(@Member, 'ID')]");
 }