Exemple #1
0
            public void ServerDrivenPagingExpand()
            {
                using (Utils.ConfigurationCacheCleaner())
                    using (Utils.RestoreStaticValueOnDispose(typeof(SimpleDataServiceHelper), "PageSizeCustomizer"))
                    {
                        SimpleDataServiceHelper.PageSizeCustomizer = PageSizeCustomizer;
                        SimpleWorkspace workspace = this.NorthwindWorkspacePaged;
                        Uri             baseUri   = new Uri(workspace.ServiceEndPoint + workspace.ServiceContainer.Name + ".svc", UriKind.Absolute);

                        var querycountpairs = new[] { new { query = "/Employees?$expand=Orders($expand=Customers),Territories&$orderby=EmployeeID add 1", count = 1 }, };
                        int i = 0;
                        foreach (var querycount in querycountpairs)
                        {
                            string uri = querycount.query;
                            using (Stream response = Utils.ProcessWebRequest(new Uri(baseUri + uri, UriKind.Absolute)))
                            {
                                XmlDocument document = new XmlDocument(Utils.TestNameTable);
                                document.Load(response);
                                String      xpath = "descendant::atom:link[@rel='next']";
                                XmlNodeList list  = document.SelectNodes(xpath, Utils.TestNamespaceManager);
                                Assert.AreEqual(querycount.count, list.Count, "Expected number of next elements did not match the actual number of next elements");
                                i++;
                            }
                        }
                    }
            }
Exemple #2
0
            public void ServerDrivenPagingBasic()
            {
                using (Utils.ConfigurationCacheCleaner())
                    using (Utils.RestoreStaticValueOnDispose(typeof(SimpleDataServiceHelper), "PageSizeCustomizer"))
                    {
                        SimpleDataServiceHelper.PageSizeCustomizer = PageSizeCustomizer;
                        SimpleWorkspace workspace       = this.NorthwindWorkspacePaged;
                        Uri             baseUri         = new Uri(workspace.ServiceEndPoint + workspace.ServiceContainer.Name + ".svc", UriKind.Absolute);
                        var             querycountpairs = new[] { new { query = "/Customers?$top=20&$skip=1", count = 1, result = "/Customers?$top=10&$skiptoken='BSBEV'", idcount = 10 },
                                                                  new { query = "/Customers", count = 1, result = "/Customers?$skiptoken='BOTTM'", idcount = 10 }, };

                        foreach (var querycount in querycountpairs)
                        {
                            string uri = querycount.query;
                            using (Stream response = Utils.ProcessWebRequest(new Uri(baseUri + uri, UriKind.Absolute)))
                            {
                                XmlDocument document = new XmlDocument(Utils.TestNameTable);
                                document.Load(response);

                                string xpath = "/atom:feed/atom:link[@rel='next']";

                                XmlNodeList list = document.SelectNodes(xpath, Utils.TestNamespaceManager);
                                Assert.AreEqual(querycount.count, list.Count, "Expected number of next elements did not match the actual number of next elements");
                                // Verify that the next link is correct
                                Assert.AreEqual(baseUri.ToString() + querycount.result, list[0].Attributes["href"].Value);

                                // Verify count
                                list = document.SelectNodes("/atom:feed/atom:entry", Utils.TestNamespaceManager);
                                Assert.AreEqual(list.Count, querycount.idcount);
                            }
                        }
                    }
            }
Exemple #3
0
            public void QueryServiceOpTests()
            {
                var queries = new[] {
                    // Get:
                    new { uri = "/GetCustomerById?customerId='QUICK'", xpath = "/atom:entry/atom:category", method = "GET", mime = "application/atom+xml" },
                    new { uri = "/GetCustomersEnumerable", xpath = "/atom:feed[count(atom:entry)=5]", method = "GET", mime = "application/atom+xml" },
                    new { uri = "/GetAllCustomers", xpath = "/atom:feed[count(atom:entry)=5]", method = "GET", mime = "application/atom+xml" },
                    new { uri = "/GetAllCustomers()", xpath = "/atom:feed[count(atom:entry)=5]", method = "GET", mime = "application/atom+xml" },
                    new { uri = "/GetAllCustomers('ANATR')", xpath = "/atom:entry/atom:category", method = "GET", mime = "application/atom+xml" },

                    // primitive type:
                    new { uri = "/GetCustomerNameById?customerId='QUICK'", xpath = "/adsm:value", method = "GET", mime = "application/xml" },
                    new { uri = "/GetCustomerNamesEnumerable", xpath = "/adsm:value[count(adsm:element)=5]", method = "GET", mime = "application/xml" },

                    // Posts
                    new { uri = "/GetCustomersByIdPOST?customerId='QUICK'", xpath = "/atom:feed[count(atom:entry)=1]", method = "POST", mime = "application/atom+xml" },
                };

                using (Utils.ConfigurationCacheCleaner())
                {
                    SimpleWorkspace workspace = this.NWServiceOpWorkspace;
                    Uri             baseUri   = new Uri(workspace.ServiceEndPoint + workspace.ServiceContainer.Name + ".svc", UriKind.Absolute);

                    foreach (var q in queries)
                    {
                        Trace.WriteLine(q.uri);
                        using (Stream response = Utils.ProcessWebRequest(new Uri(baseUri + q.uri, UriKind.Absolute), q.mime, q.method))
                        {
                            XmlDocument document = new XmlDocument(Utils.TestNameTable);
                            document.Load(response);
                            Assert.IsTrue(document.SelectNodes(q.xpath, Utils.TestNamespaceManager).Count > 0, q.xpath);
                        }
                    }
                }
            }
Exemple #4
0
            public void SDPC_DSCFullLoad()
            {
                using (Utils.ConfigurationCacheCleaner())
                    using (Utils.RestoreStaticValueOnDispose(typeof(SimpleDataServiceHelper), "PageSizeCustomizer"))
                    {
                        SimpleDataServiceHelper.PageSizeCustomizer = PageSizeCustomizerFast;
                        SimpleWorkspace workspace = this.NorthwindWorkspacePaged;
                        Uri             baseUri   = new Uri(workspace.ServiceEndPoint + workspace.ServiceContainer.Name + ".svc", UriKind.Absolute);

                        DataServiceContext ctx = new DataServiceContext(baseUri);
                        ctx.EnableAtom = true;
                        ctx.Format.UseAtom();
                        var q = ctx.CreateQuery <northwindBinding.Customers>("Customers").Expand("Orders");

                        int totalCustomerCount = q.Count();
                        int totalOrdersCount   = ctx.CreateQuery <northwindBinding.Orders>("Orders").Count();
                        var custs = new DataServiceCollection <northwindBinding.Customers>(q, TrackingMode.None);

                        for (int i = 0; i < 2; i++)
                        {
                            if (i == 1)
                            {
                                // second iteration
                                ctx            = new DataServiceContext(baseUri);
                                ctx.EnableAtom = true;
                                ctx.Format.UseAtom();
                                q     = ctx.CreateQuery <northwindBinding.Customers>("Customers").Expand("Orders");
                                custs = new DataServiceCollection <northwindBinding.Customers>(q);
                            }

                            while (custs.Continuation != null)
                            {
                                custs.Load(ctx.Execute <northwindBinding.Customers>(custs.Continuation));
                            }

                            int linksCount  = 0;
                            int ordersCount = 0;
                            foreach (var c in custs)
                            {
                                while (c.Orders.Continuation != null)
                                {
                                    if (linksCount++ % 2 == 0)
                                    {
                                        ctx.LoadProperty(c, "Orders", c.Orders.Continuation);
                                    }
                                    else
                                    {
                                        c.Orders.Load(ctx.Execute <northwindBinding.Orders>(c.Orders.Continuation));
                                    }
                                }
                                ordersCount += c.Orders.Count;
                            }

                            Assert.IsTrue(linksCount > 0, "links Count must be greater than 0");
                            Assert.AreEqual(totalCustomerCount, custs.Count);
                            Assert.AreEqual(totalOrdersCount, ordersCount);
                        }
                    }
            }
Exemple #5
0
            public void PerTestSetup()
            {
                SimpleWorkspace workspace = this.NorthwindWorkspace;
                Uri             baseUri   = new Uri(workspace.ServiceEndPoint + workspace.ServiceContainer.Name + ".svc", UriKind.Absolute);

                this.ctx            = new northwindClient.northwindContext(baseUri);
                this.ctx.EnableAtom = true;
                this.ctx.Format.UseAtom();
                ctx.Timeout = TestConstants.MaxTestTimeout;
                Trace.WriteLine("Querying workspace at " + baseUri);
            }
Exemple #6
0
            public void SDPC_QORFullLoad()
            {
                using (Utils.ConfigurationCacheCleaner())
                    using (Utils.RestoreStaticValueOnDispose(typeof(SimpleDataServiceHelper), "PageSizeCustomizer"))
                    {
                        SimpleDataServiceHelper.PageSizeCustomizer = PageSizeCustomizerFast;
                        SimpleWorkspace workspace = this.NorthwindWorkspacePaged;
                        Uri             baseUri   = new Uri(workspace.ServiceEndPoint + workspace.ServiceContainer.Name + ".svc", UriKind.Absolute);

                        DataServiceContext ctx = new DataServiceContext(baseUri);
                        ctx.EnableAtom = true;
                        ctx.Format.UseAtom();
                        var q = ctx.CreateQuery <northwindBinding.Customers>("Customers").Expand("Orders");

                        int totalCustomerCount = q.Count();
                        int totalOrdersCount   = ctx.CreateQuery <northwindBinding.Orders>("Orders").Count();

                        var qor = q.Execute() as QueryOperationResponse <northwindBinding.Customers>;

                        DataServiceQueryContinuation <northwindBinding.Customers> nextCustLink = null;
                        int custCount  = 0;
                        int orderCount = 0;
                        do
                        {
                            ICollection previousOrderCollection = null;

                            foreach (var c in qor)
                            {
                                try
                                {
                                    if (previousOrderCollection != null)
                                    {
                                        qor.GetContinuation(previousOrderCollection);
                                        Assert.Fail("Out of scope collection did not throw");
                                    }
                                }
                                catch (ArgumentException)
                                {
                                }

                                var nextOrderLink = qor.GetContinuation(c.Orders);
                                while (nextOrderLink != null)
                                {
                                    if (custCount % 2 == 0)
                                    {
                                        var innerQOR = ctx.Execute <northwindBinding.Orders>(nextOrderLink) as QueryOperationResponse <northwindBinding.Orders>;
                                        foreach (var innerOrder in innerQOR)
                                        {
                                            ctx.AttachLink(c, "Orders", innerOrder);
                                            c.Orders.Add(innerOrder);
                                        }
                                        nextOrderLink = innerQOR.GetContinuation();
                                    }
                                    else
                                    {
                                        nextOrderLink = ctx.LoadProperty(c, "Orders", nextOrderLink).GetContinuation();
                                    }
                                }

                                previousOrderCollection = c.Orders;

                                orderCount += c.Orders.Count;
                                custCount++;
                            }

                            nextCustLink = qor.GetContinuation();
                            if (nextCustLink != null)
                            {
                                qor = ctx.Execute <northwindBinding.Customers>(nextCustLink) as QueryOperationResponse <northwindBinding.Customers>;
                            }
                        } while (nextCustLink != null);

                        Assert.AreEqual(totalCustomerCount, custCount);
                        Assert.AreEqual(totalOrdersCount, orderCount);
                        Assert.AreEqual(totalOrdersCount, ctx.Links.Count);
                        Assert.AreEqual(totalCustomerCount + totalOrdersCount, ctx.Entities.Count);
                    }
            }
Exemple #7
0
        public static void CreateWorkspaceForType(Type serviceType, Type contextType, string name, out SimpleWorkspace workspace, out DataServiceHost host, bool isEFBased)
        {
            int    retryCount = 0;
            string serviceEntryPointLocation = null;
            string partialEntryPointLocation = null;

            host = null;
            bool failed;

            do
            {
                failed = false;

                // Generate a random number between 20000 and 40000
                int LocalPort = random.Next(20000, 40000);

                Trace.WriteLine("Attempting to start service at port: " + LocalPort);
                try
                {
                    partialEntryPointLocation = "http://localhost:" + LocalPort + "/";
                    serviceEntryPointLocation = partialEntryPointLocation + name + ".svc";

                    host = new DataServiceHost(serviceType, new Uri[] { new Uri(serviceEntryPointLocation) });

                    Type implementedContract = typeof(IRequestHandler);
                    System.ServiceModel.Description.ServiceEndpoint endpoint = host.AddServiceEndpoint(implementedContract, new System.ServiceModel.WebHttpBinding(), "");
                    host.Open();
                    host.Faulted += delegate(object sender, EventArgs e)
                    {
                        Trace.WriteLine("WCF Host faulted.");
                    };
                }
                catch (System.ServiceModel.AddressAlreadyInUseException e)
                {
                    Trace.WriteLine(e.Message);
                    Trace.WriteLine("Failed to start service at: " + serviceEntryPointLocation);
                    retryCount++;
                    failed = true;
                }
            }while (retryCount < 10 && failed == true);

            Trace.WriteLine("Started " + name + " host at " + serviceEntryPointLocation);

            workspace = new SimpleWorkspace()
            {
                ServiceContainer = new SimpleServiceContainer()
                {
                    Name = name,
                    ResourceContainers = new ResourceContainerList(
                        from property in contextType.GetProperties()
                        where ((isEFBased && typeof(System.Data.Objects.ObjectQuery).IsAssignableFrom(property.PropertyType) ||
                                (!isEFBased && property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(IQueryable <>))))
                        select new SimpleResourceContainer(property.Name,
                                                           from resouceType in contextType.Assembly.GetTypes()
                                                           where property.PropertyType.GetGenericArguments()[0].IsAssignableFrom(resouceType)
                                                           select new SimpleResourceType(resouceType.Name,
                                                                                         from typeProperty in resouceType.GetProperties()
                                                                                         select new SimpleProperty(typeProperty.Name)
                                                                                         )
                                                           )
                        )
                },
                ServiceEndPoint = partialEntryPointLocation,
            };
        }