public void WebDataServiceDocumentTest()
        {
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("Location", new object[] { WebServerLocation.InProcess, WebServerLocation.InProcessWcf }),
                new Dimension("ServiceModelData", ServiceModelData.Values),
                new Dimension("Accept", new string[]
            {
                "application/atomsvc+xml",
                "application/atomsvc+xml;q=0.8",
                "application/xml",
                "application/xml;q=0.5"
            }));

            TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
            {
                string accept = (string)values["Accept"];
                WebServerLocation location = (WebServerLocation)values["Location"];
                ServiceModelData model     = (ServiceModelData)values["ServiceModelData"];
                if (!model.IsValid)
                {
                    return;
                }

                using (TestWebRequest request = TestWebRequest.CreateForLocation(location))
                {
                    request.Accept           = accept;
                    request.DataServiceType  = model.ServiceModelType;
                    request.RequestUriString = "/";
                    request.SendRequest();

                    XmlDocument document = request.GetResponseStreamAsXmlDocument();
                    string responseType  = TestUtil.GetMediaType(request.ResponseContentType);
                    if (accept.Contains("application/atomsvc+xml"))
                    {
                        Assert.AreEqual("application/atomsvc+xml", responseType);
                    }
                    else
                    {
                        Assert.AreEqual("application/xml", responseType);
                    }

                    Trace.WriteLine(document.OuterXml);
                    CheckServiceDocument(document);
                }
            });
        }
Beispiel #2
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')]");
        }
Beispiel #3
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 WebDataServiceDocumentJsonLightTest()
        {
            // Smoke test to verify that JSON Light service document can be written through the server. Detailed format-specific tests are in ODL.
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("Location", new object[] { WebServerLocation.InProcess, WebServerLocation.InProcessWcf }),
                new Dimension("Accept", new string[]
            {
                "application/json",
                "application/json;odata.metadata=minimal"
            }));

            TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
            {
                string accept = (string)values["Accept"];
                WebServerLocation location = (WebServerLocation)values["Location"];
                ServiceModelData model     = ServiceModelData.CustomData;

                Assert.IsTrue(model.IsValid);

                using (TestWebRequest request = TestWebRequest.CreateForLocation(location))
                {
                    request.Accept           = accept;
                    request.DataServiceType  = model.ServiceModelType;
                    request.RequestUriString = "/";
                    request.SendRequest();

                    string response     = request.GetResponseStreamAsText();
                    string responseType = TestUtil.GetMediaType(request.ResponseContentType);
                    Assert.AreEqual("application/json;odata.metadata=minimal", responseType);

                    Trace.WriteLine(response);

                    // Customers is defined in ServiceModelData.
                    // Smoke test: Confirm that it's written out as the name of a resource collection somewhere in the service document.
                    Assert.IsTrue(response.Contains("{\"name\":\"Customers\""), "Expected to find \"Customers\" resource collection formatted as JSON Light");
                }
            });
        }
Beispiel #5
0
        [Ignore] // test case issue, request uri and service root in this case is null.
        public void RequestQueryParserTestBasicTests()
        {
            using (OpenWebDataServiceHelper.AcceptReplaceFunctionInQuery.Restore())
            {
                OpenWebDataServiceHelper.AcceptReplaceFunctionInQuery.Value = true;
                TestUtil.ClearConfiguration();

                // Repro Protocol: Filter - replace not implemented?
                // Repro Protocol: Can't cast simple primitive value in filter expression
                CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                    new Dimension("ServiceModelData", ServiceModelData.Values));

                TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
                {
                    ServiceModelData modelData = (ServiceModelData)values["ServiceModelData"];
                    object service             = Activator.CreateInstance(typeof(OpenWebDataService <>).MakeGenericType(modelData.ServiceModelType));
                    service.GetType().GetMethod("AttachHost", BindingFlags.Public | BindingFlags.Instance).Invoke(service, new object[] { new TestServiceHost2() });
                    object context  = ServiceModelData.InitializeAndGetContext(service);
                    object provider = ServiceModelData.CreateProvider(context, service);

                    if (!modelData.ContainerNames.Contains("Customers"))
                    {
                        return;
                    }

                    string customerNameProperty = modelData.IsUnitTestProvider ? "Name" : "CompanyName";
                    string integerProperty      = modelData.IsUnitTestProvider ? "ID" : "1";

                    string[] predicates = new string[]
                    {
                        "1 eq 1",
                        "1 add 1 eq 2",
                        "2 eq 1 add 1",
                        "3.5 eq 3 add 0.5",
                        "3.5 eq 3 add 0.5",
                        "1 add 2 mul 2 eq 5",
                        "(1 add 2) mul 2 eq 6",
                        "2 sub 1 eq 1",
                        "2 sub 1 add 1 ne 1",
                        "1 add 1 lt 5",
                        "1 add 1 le 2",
                        "1 add 1 ge 2",
                        "1 add 1 gt 1",
                        "1 lt " + Int64.MaxValue + "L",
                        "1 gt " + Int64.MinValue + "L",
                        ///TODO: these 2 should succeed, (double, double, single) shouldn't get -1 from
                        ///private static int CompareConversions(Type source, Type targetA, Type targetB) , this method needs some fixing.
                        ///"1 lt " + decimal.MaxValue + "00",
                        ///"1 gt " + decimal.MinValue + "00",
                        "not (1 add 1 eq 1)",
                        "1 eq 1 or 2 eq 1",
                        "1 eq 1 and 2 eq 1 add 1",
                        "1 eq 1 and not not (2 eq 1 add 1)",
                        "1 eq 0 sub -1",
                        "1 eq 0 sub - 1",
                        "0 sub 3 eq -(3)",
                        "'a' eq 'a'",
                        "'abc' eq 'abc'",
                        "'''' eq ''''",
                        "-" + integerProperty + " eq 1 sub 2",
                        customerNameProperty + " eq 'John' or 1 eq 1",
                        "10 div 2 eq 5",
                        "3 mod 2 eq 1",
                        "1 gt " + XmlConvert.ToString(10.1E-9),
                        "1 lt " + XmlConvert.ToString(10.1E+3),
                        "binary'12AABBff' eq Binary'12aabbFF'",
                        "binary'000102030405060708090A0B0C0D0E0F' eq BINARY'000102030405060708090a0b0c0d0e0f'",
                        "binary'12AABBff' ne binary'22aabbFF'",

                        // String functions.
                        "endswith('abc', 'bc')",
                        "startswith('abc', 'ab')",
                        "not startswith('abc', 'aab')",
                        "contains('abc','b')",
                        "indexof('abc', 'b') ge 1",
                        "replace('foo','o','g') eq 'fgg'",
                        "substring('123', 1) eq '23'",
                        "substring('123', 1, 1) eq '2'",
                        "tolower('ABC') eq 'abc'",
                        "toupper('AbC') eq 'ABC'",
                        "length(toupper('aBc')) eq length(tolower('aBc'))",
                        "concat('a', 'b') eq 'ab'",
                        "'a' lt 'b'",
                        "'a' le 'a'",
                        "'a' ge 'a'",
                        "'b' ge 'a'",
                        // "'a' add 'b' eq 'ab'",
                        // Repro Protocol: can't call date function in filter expressions on LinqToSql
                        "startswith(" + customerNameProperty + ", 'C')",
                        "endswith(concat(" + customerNameProperty + ", 'b'), 'b')",
                        "contains(" + customerNameProperty + ",'C')",
                        "trim(" + customerNameProperty + ") eq substring(" + customerNameProperty + ", 0)",

                        // DateTime functions.
                        "year(2007-08-08) eq 2007",
                        "month(2007-08-10) eq 08",
                        "day(2007-08-10) eq 10",
                        "hour(2007-08-10T14:11:12Z) eq 14",
                        "minute(2007-08-10T14:11:12Z) eq 11",
                        "second(2007-08-10T14:11:12Z) eq 12",

                        // Math functions.
                        "round(1.1) eq 1",
                        "round(42) eq 42",
                        "floor(1.1M) eq 1",
                        "ceiling(1.1f) eq 2",
                    };

                    if (modelData.IsUnitTestProvider)
                    {
                        // Refer to some specific types.
                        string[] customDataContextPredicates = new string[]
                        {
                            //   "(BestFriend ne null and BestFriend/Name eq 'John') or 1 eq 1",
                            "GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716",
                            "GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716",
                            "GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716 and GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716",
                            // Type functions.
                            "ID eq cast(1, 'Edm.Int32')",
                            String.Format("not isof(1, '{0}')", UnitTestsUtil.ConvertTypeNames("AstoriaUnitTests.Stubs.Customer", context)),
                            String.Format("isof('{0}')", UnitTestsUtil.ConvertTypeNames("AstoriaUnitTests.Stubs.Customer", context)),
                            String.Format("isof('{0}') and cast('{0}')/Birthday gt 1960-01-01", UnitTestsUtil.ConvertTypeNames("AstoriaUnitTests.Stubs.CustomerWithBirthday", context))
                        };

                        if (!(context is CustomRowBasedOpenTypesContext))
                        {
                            predicates = predicates.Concat(new string[] {
                                "ID eq cast(1, 'Edm.Int64')",
                                "ID eq 1L"
                            }).ToArray();
                        }

                        predicates = predicates.Concat(customDataContextPredicates).ToArray();
                    }
                    else if (context is NorthwindModel.NorthwindContext)
                    {
                        string[] northwindPredicates = new string[]
                        {
                            // Repro 602210 - Exception when filter expression contains null
                            "((((CustomerID) eq ('ALFKI')) and ((CustomerID) eq ('ANATR')))) or ((Region) ne (null))"
                        };
                        predicates = predicates.Concat(northwindPredicates).ToArray();
                    }
                    else if (context is AstoriaUnitTests.Stubs.Sql.SqlNorthwindDataContext)
                    {
                        string[] sqlNorthwindPredicates = new string[]
                        {
                            // Repro Protocol: Can't compare properties to null in LinqToSql filter expression
                            "Categories|CategoryName eq null or 1 add 1 eq 2",
                            "Categories|null eq CategoryName or 1 add 1 eq 2",

                            // Repro Protocol: error trying to use Link property in filter expression (LinqToSql)
                            //"Categories|contains('Beer',CategoryName)",
                            //"Products|contains('Beer',Categories/CategoryName)",

                            // Repro Protocol: can't call date function in filter expressions on LinqToSql
                            //"Employees|month(HireDate) eq 5",
                        };
                        predicates = sqlNorthwindPredicates;
                        // predicates = predicates.Concat(sqlNorthwindPredicates).ToArray();
                    }

                    VerifyResultsExistForWhere(service, context, "Customers", predicates);
                });
            }
        }
Beispiel #6
0
                internal string BuildRequestUri(ServiceModelData model)
                {
                    if (model == null)
                    {
                        throw new ArgumentNullException("model");
                    }

                    string sampleContainer = model.SampleContainer;
                    switch (this.Kind)
                    {
                        case AddressableElementKind.Metadata:
                            return "/$metadata";
                        case AddressableElementKind.ServiceDocument:
                            return "/";
                        case AddressableElementKind.EntitySet:
                            return "/" + sampleContainer;
                        case AddressableElementKind.Entity:
                            return "/" + sampleContainer + "(" + model.GetSampleKeyForUri(sampleContainer) + ")";
                        case AddressableElementKind.EntityPrimitiveProperty:
                            return "/" + sampleContainer + "(" + model.GetSampleKeyForUri(sampleContainer) + ")/" +
                                model.GetSampleNonKeyPrimitiveProperty(sampleContainer).Name;
                        case AddressableElementKind.EntityPrimitivePropertyValue:
                            return "/" + sampleContainer + "(" + model.GetSampleKeyForUri(sampleContainer) + ")/" +
                                model.GetSampleNonKeyPrimitiveProperty(sampleContainer).Name + "/$value";
                        case AddressableElementKind.EntityComplexPropertyValue:
                            return null;
                        case AddressableElementKind.EntityComplexProperty:
                            return null;
                        case AddressableElementKind.EntityReference:
                            return null;
                        case AddressableElementKind.EntityCollectionReference:
                            return null;
                        case AddressableElementKind.EntityPrimitiveOpenProperty:
                            return null;
                        case AddressableElementKind.EntityPrimitiveOpenPropertyValue:
                            return null;
                        case AddressableElementKind.EntityComplexOpenPropertyValue:
                            return null;
                        case AddressableElementKind.EntityComplexOpenProperty:
                            return null;
                        case AddressableElementKind.EntityOpenReference:
                            return null;
                        case AddressableElementKind.EntityOpenCollectionReference:
                            return null;
                    }
                    
                    return null;
                }
Beispiel #7
0
                internal Stream BuildRequestBody(
                    string method, 
                    SerializationFormatData format, 
                    ServiceModelData model, 
                    bool includeKeys, 
                    bool includeId)
                {
                    if (method == "GET" || method == "DELETE")
                    {
                        return null;
                    }
                    else if (!this.Addressable || this.SystemGenerated)
                    {
                        return new MemoryStream(Encoding.UTF8.GetBytes("foo"));
                    }

                    string text = null;
                    switch (this.Kind)
                    {
                        case AddressableElementKind.Metadata:
                        case AddressableElementKind.ServiceDocument:
                        case AddressableElementKind.EntitySet:
                            break;
                        case AddressableElementKind.Entity:
                            string containerName = model.SampleContainer;
                            string containerTypeName = model.GetContainerRootTypeName(containerName);
                            string keyName = model.GetKeyProperties(containerTypeName).Single().Name;
                            string nonKeyName = model.GetNonKeyPrimitiveProperties(containerTypeName).First().Name;
                            if (format == SerializationFormatData.Atom)
                            {
                                // null.
                                //text = "<entry " +
                                //    "xmlns:ads='http://docs.oasis-open.org/odata/ns/data' " +
                                //    "xmlns:adsm='http://docs.oasis-open.org/odata/ns/metadata' " +
                                //    "xmlns='http://www.w3.org/2005/Atom' " +
                                //    "adsm:null='true' />";

                                // valid payload.
                                text = "<entry " +
                                    "xmlns:ads='http://docs.oasis-open.org/odata/ns/data' " +
                                    "xmlns:adsm='http://docs.oasis-open.org/odata/ns/metadata' " +
                                    "xmlns='http://www.w3.org/2005/Atom'>\r\n" +
                                    ((includeId) ? String.Format(" <id>{0}</id>", this.BuildRequestUri(model)) : " <id />") +
                                    "\r\n <author><name /></author>\r\n" +
                                    " <content type='application/xml'><adsm:properties>\r\n" +
                                    String.Format("  <ads:{0}>123</ads:{0}>", nonKeyName) +
                                    ((includeKeys) ? String.Format("  <ads:{0}>9999</ads:{0}>", keyName) : "") +
                                    "\r\n </adsm:properties></content>" +
                                    "</entry>";
                            }
                            else if (format == SerializationFormatData.JsonLight)
                            {
                            }
                            break;
                        case AddressableElementKind.EntityPrimitivePropertyValue:
                        case AddressableElementKind.EntityPrimitiveOpenPropertyValue:
                        case AddressableElementKind.EntityPrimitiveOpenProperty:
                            return new MemoryStream(Encoding.UTF8.GetBytes("1"));
                        case AddressableElementKind.EntityReference:
                            return null;
                        case AddressableElementKind.EntityCollectionReference:
                            return null;
                        case AddressableElementKind.EntityComplexOpenPropertyValue:
                            return null;
                        case AddressableElementKind.EntityComplexOpenProperty:
                            return null;
                        case AddressableElementKind.EntityOpenReference:
                            return null;
                        case AddressableElementKind.EntityOpenCollectionReference:
                            return null;
                    }

                    if (text == null)
                    {
                        return null;
                    }
                    else
                    {
                        return new MemoryStream(Encoding.UTF8.GetBytes(text));
                    }
                }
Beispiel #8
0
            //[TestMethod]
            public void SilverlightBasicTest()
            {
                // setup northwind database
                ServiceModelData modelData = ServiceModelData.Values[0];

                using (TestWebRequest request = TestWebRequest.CreateForLocal())
                {
                    request.DataServiceType = modelData.ServiceModelType;
                    request.StartService();

                    #region copy compiled binaries for Silverlight request

                    string baseUri = request.BaseUri;
                    Assert.IsTrue(baseUri.EndsWith(".svc", StringComparison.Ordinal));

                    string FileTargetPath = LocalWebServerHelper.FileTargetPath;
                    Assert.IsTrue(!FileTargetPath.EndsWith("\\"));

                    string SilverlightSrcPath = LocalWebServerHelper.BinarySourcePath + "\\Silverlight";
                    string ClientBinPath      = FileTargetPath + "\\ClientBin";

                    string startPage  = "Astoria.Silverlight.html";
                    string requestUri = baseUri.Substring(0, baseUri.LastIndexOf('/') + 1) + "ClientBin/" + startPage;

                    string[] binariesToCopy = new string[] { // to ClientBinPath
                        DataFxAssemblyRef.File.DataServicesClient,
                        DataFxAssemblyRef.File.DataServicesClient.Replace(".dll", ".pdb"),
                        "Astoria.Silverlight.UnitTests.dll",
                        "Astoria.Silverlight.UnitTests.pdb",
                    };

                    string[] pagesToCopy = new string[] { // to FileTargetPath
                        "Astoria.Silverlight.xaml",
                        startPage,
                        startPage + ".js",
                        "Silverlight.js",
                    };

                    foreach (string file in binariesToCopy)
                    {
                        Assert.IsTrue(File.Exists(SilverlightSrcPath + "\\" + file), file);
                    }

                    foreach (string file in pagesToCopy)
                    {
                        Assert.IsTrue(File.Exists(SilverlightSrcPath + "\\" + file), file);
                    }

                    Directory.CreateDirectory(ClientBinPath);

                    foreach (string file in binariesToCopy)
                    {
                        File.Copy(
                            SilverlightSrcPath + "\\" + file,
                            ClientBinPath + "\\" + file,
                            /*overwrite*/ true);
                    }

                    foreach (string binary in pagesToCopy)
                    {
                        File.Copy(
                            SilverlightSrcPath + "\\" + binary,
                            ClientBinPath + "\\" + binary,
                            /*overwrite*/ true);
                    }

                    #endregion

                    string status = "missing";

                    Thread uiThread = new Thread(delegate(object o)
                    {
                        Form form          = new Form();
                        form.Width         = 640;
                        form.Height        = 480;
                        WebBrowser browser = new WebBrowser();
                        browser.Width      = form.Width;
                        browser.Height     = form.Height;
                        form.Controls.Add(browser);
                        browser.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

                        SilverlightExternal scriptingObject = new SilverlightExternal();
                        scriptingObject.TestCompletedEvent += delegate(object sender, TestCompletedEventArgs e)
                        {
                            status = e.Status;
#if false
                            Action action = delegate { form.Text = e.Status; };
                            form.Invoke(action);
#else
                            form.Close();
#endif
                        };

                        browser.ObjectForScripting = scriptingObject;

                        form.Load += delegate(object sender, EventArgs e)
                        {
                            browser.Url = new Uri(requestUri);
                            form.BringToFront();
                        };
                        form.ShowDialog();
                        return;
                    });

                    uiThread.SetApartmentState(ApartmentState.STA);
                    uiThread.Start();
                    if (!uiThread.Join(new TimeSpan(0, 3, 0)))
                    {
                        status = "timeout";
                    }

                    if (status != "test finished")
                    {
                        throw new Exception(status);
                    }
                }
            }