Exemplo n.º 1
0
        public void RequestUriProcessorNullNavigationTest()
        {
            string[] uris = new string[]
            {
                "/Customer(100)/BestFriend/Name",
                "/Customer(100)/Orders",
                "/Customer(100)/Orders(1)",
                "/Customer(100)/Orders(1)/DollarAmount",
                // "/Customer(100)/BestFriend/BestFriend/Name",
            };

            using (CustomDataContext.CreateChangeScope())
                using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                {
                    request.DataServiceType = typeof(CustomDataContext);

                    var c = new CustomDataContext();
                    c.InternalCustomersList.Add(new Customer()
                    {
                        ID = 100, BestFriend = null, Orders = null
                    });
                    c.SaveChanges();

                    CombinatorialEngine engine = CombinatorialEngine.FromDimensions(new Dimension("URI", uris));
                    TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
                    {
                        string uri = (string)values["URI"];
                        request.RequestUriString = "/Customer(100)/BestFriend/Name";
                        Exception exception      = TestUtil.RunCatching(request.SendRequest);
                        TestUtil.AssertExceptionStatusCode(exception, 404, "404 expected for " + uri);
                    });
                }
        }
Exemplo n.º 2
0
            public void ETag_VerifyETagInPayloadInTopLevelPost()
            {
                string jsonPayload = "{ " +
                                     "@odata.type : \"AstoriaUnitTests.Stubs.Customer\" ," +
                                     "Name: \"Bar\"," +
                                     "ID: 125" +
                                     "}";

                string[] jsonXPath = new string[] { String.Format("count(/{0}/odata.etag)=1", JsonValidator.ObjectString) };

                string atomPayload = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" +
                                     "<entry xml:base=\"/\" " + TestUtil.CommonPayloadNamespaces + ">" +
                                     AtomUpdatePayloadBuilder.GetCategoryXml(typeof(Customer).FullName) +
                                     "<content type=\"application/xml\">" +
                                     "<adsm:properties>" +
                                     "<ads:Name>Foo</ads:Name>" +
                                     "<ads:ID>125</ads:ID>" +
                                     "</adsm:properties>" +
                                     "</content>" +
                                     "</entry>";

                string[] atomXPaths = new string[] { "count(/atom:entry/@adsm:etag)=1" };
                using (CustomDataContext.CreateChangeScope())
                {
                    GetResponse("/Customers", UnitTestsUtil.JsonLightMimeType, typeof(CustomDataContext), jsonXPath, null, "POST", jsonPayload);
                }

                using (CustomDataContext.CreateChangeScope())
                {
                    GetResponse("/Customers", UnitTestsUtil.AtomFormat, typeof(CustomDataContext), atomXPaths, null, "POST", atomPayload);
                }
            }
Exemplo n.º 3
0
        public void HttpProcessUtilityJsonEncodingTest()
        {
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("Test", TestUtil.CreateDictionary <string, Encoding>(
                                  new string[] { UnitTestsUtil.JsonLightMimeType, UnitTestsUtil.JsonLightMimeType + ";charset=utf-16", UnitTestsUtil.JsonLightMimeType + ";charset=GB18030" },
                                  new Encoding[] { Encoding.UTF8, Encoding.Unicode, Encoding.GetEncoding("GB18030") })));

            using (CustomDataContext.CreateChangeScope())
                using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                {
                    request.DataServiceType = typeof(CustomDataContext);
                    request.Accept          = UnitTestsUtil.JsonLightMimeType;
                    request.HttpMethod      = "POST";

                    int index = 100;
                    TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
                    {
                        KeyValuePair <string, Encoding> test = (KeyValuePair <string, Encoding>)values["Test"];
                        Encoding encoding = test.Value;

                        request.RequestContentType = test.Key;
                        request.RequestStream      = new MemoryStream();

                        byte[] bytes = encoding.GetBytes("{ @odata.type: 'AstoriaUnitTests.Stubs.Customer', ID : " + index++.ToString() + ", Name : \"P\\\\B \\/K\\\"n\\u00e4c\\f\\tke\\r\\n\\br\\u00f6d AB\" }");
                        request.RequestStream.Write(bytes, 0, bytes.Length);
                        request.RequestStream.Position = 0;

                        request.RequestUriString = "/Customers";
                        request.SendRequest();
                        string responseText = request.GetResponseStreamAsText();
                        Assert.IsTrue(responseText.Contains(@"P\\B /K\" + "\"" + @"n\u00e4c\f\tke\r\n\br\u00f6d AB"), "Response [" + responseText + "] contains the expected escape sequences.");
                    });
                }
        }
Exemplo n.º 4
0
            private void GetResponseFromReflectionBasedProvider(string uri, string responseFormat, string[] xPathsToVerify)
            {
                CustomDataContext.ClearData();
                CustomDataContext.PreserveChanges = true;
                Type contextType = typeof(CustomDataContext);

                GetResponse(uri, responseFormat, contextType, xPathsToVerify, null);
                CustomDataContext.PreserveChanges = false;
            }
Exemplo n.º 5
0
        public void FactoryMustCreateUowWithDataContext()
        {
            IDataContext       dataContext = new CustomDataContext();
            IUnitOfWorkFactory factory     = new UnitOfWorkFactory();

            var uow = factory.Create(dataContext);

            Assert.Equal(dataContext, uow.DataContext);
        }
        public void FactoryMustCreateUowWithDataContext()
        {
            IDataContext dataContext = new CustomDataContext();
            IUnitOfWorkFactory factory = new UnitOfWorkFactory();

            var uow = factory.Create(dataContext);

            Assert.Equal(dataContext, uow.DataContext);
        }
        public void TestThatDcReturnedCorrectTables()
        {
            IDataContext dataContext = new CustomDataContext();
            var          tableFromDc = dataContext.GetTable <Item>();

            var dmDataContext       = new DmDataContext();
            var tableFromDataMapper = dmDataContext.GetTable <Item>();

            Assert.True(tableFromDc.ToString().Equals(tableFromDataMapper.ToString()));
        }
        public void TestThatDcReturnedCorrectTables()
        {
            IDataContext dataContext = new CustomDataContext();
            var tableFromDc = dataContext.GetTable<Item>();

            var dmDataContext = new DmDataContext();
            var tableFromDataMapper = dmDataContext.GetTable<Item>();

            Assert.True(tableFromDc.ToString().Equals(tableFromDataMapper.ToString()));
        }
Exemplo n.º 9
0
        public void LoadPropertyRemoveElementDeletedSource()
        {
            MergeOption original = this.context.MergeOption;

            try
            {
                foreach (MergeOption mo in new[] { MergeOption.OverwriteChanges, MergeOption.PreserveChanges })
                {
                    using (CustomDataContext.CreateChangeScope())
                        using (OpenWebDataServiceHelper.PageSizeCustomizer.Restore())
                        {
                            OpenWebDataServiceHelper.PageSizeCustomizer.Value = (config, type) => { config.SetEntitySetPageSize("Orders", 5); };
                            Customer c = new Customer()
                            {
                                ID = 0
                            };
                            Customer c2 = new Customer()
                            {
                                ID = 2
                            };
                            Order o = new Order()
                            {
                                ID = 102
                            };

                            this.context.MergeOption = mo;

                            this.context.AttachTo("Customers", c);
                            this.context.AttachTo("Customers", c2);
                            this.context.AttachTo("Orders", o);

                            this.context.AddLink(c, "Orders", o);
                            this.context.SetLink(o, "Customer", c);
                            this.context.SaveChanges();

                            // Mark the object as deleted
                            this.context.DeleteObject(c);

                            this.context.LoadProperty(c, "Orders");

                            var changedDescritors = this.context.Entities.Cast <Descriptor>().Union(this.context.Links.Cast <Descriptor>()).Where(d => d.State != EntityStates.Unchanged);

                            Assert.AreEqual(changedDescritors.Count(), 1);
                            Assert.IsTrue(changedDescritors.Single().State == EntityStates.Deleted);
                            Assert.IsTrue(changedDescritors.Single() is EntityDescriptor);
                        }

                    this.ClearContext();
                }
            }
            finally
            {
                this.context.MergeOption = original;
            }
        }
Exemplo n.º 10
0
            public void DeleteUsingAnyValueForIfMatch()
            {
                using (CustomDataContext.CreateChangeScope())
                {
                    Type contextType   = typeof(CustomDataContext);
                    var  ifMatchHeader = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("If-Match", "*") };

                    // Directly deleting a top level entity
                    UnitTestsUtil.SendRequestAndVerifyXPath(null, "/Customers(0)", null, contextType, null, "DELETE", ifMatchHeader, false);

                    // Deleting a deep entity
                    UnitTestsUtil.SendRequestAndVerifyXPath(null, "/Customers(2)/BestFriend", null, contextType, null, "DELETE", ifMatchHeader, false);
                }
            }
Exemplo n.º 11
0
        public void CanOverloadUpdateRequestWithHeader()
        {
            foreach (var serviceType in Services)
            {
                using (CustomDataContext.CreateChangeScope())
                {
                    using (TestWebRequest webRequest = TestWebRequest.CreateForInProcessWcf())
                    {
                        // get an existing customer before sending PUT requests
                        webRequest.HttpMethod       = "GET";
                        webRequest.ServiceType      = serviceType;
                        webRequest.RequestUriString = "/Customers(1)";
                        webRequest.Accept           = UnitTestsUtil.JsonLightMimeType;
                        TestUtil.RunCatching(webRequest.SendRequest);
                        Assert.IsTrue(webRequest.ResponseContentType.ToLower().Contains(UnitTestsUtil.JsonLightMimeType.ToLower()));

                        // all the subsequent requests are PUT requests with specified Accept and Content-Type headers
                        webRequest.HttpMethod         = "PUT";
                        webRequest.Accept             = UnitTestsUtil.JsonLightMimeType;
                        webRequest.RequestContentType = "application/json";

                        // update the customer and send the correct ETag in query string header - should succeed
                        webRequest.RequestUriString = "/Customers(1)/Name?Override-If-Match=" + webRequest.ResponseETag;
                        webRequest.IfMatch          = "SomeBadValue";
                        webRequest.SetRequestStreamAsText("{\"value\": \"Name1\"}");
                        TestUtil.RunCatching(webRequest.SendRequest);
                        Assert.AreEqual(204, webRequest.ResponseStatusCode);
                        string eTag = webRequest.ResponseETag;

                        // update the customer and send ETag with reversed guid in query string header - should fail
                        // Length of a GUID is 36
                        string correctGuid  = webRequest.ResponseETag.Substring(webRequest.ResponseETag.IndexOf('"') + 1, 36);
                        string reversedGuid = string.Concat(correctGuid.ToArray().Reverse());
                        webRequest.RequestUriString = "/Customers(1)/Name?Override-If-Match=" + webRequest.ResponseETag.Replace(correctGuid, reversedGuid);
                        webRequest.IfMatch          = eTag;
                        webRequest.SetRequestStreamAsText("{\"value\": \"Name2\"}");
                        TestUtil.RunCatching(webRequest.SendRequest);
                        Assert.AreEqual(412, webRequest.ResponseStatusCode);

                        // update the customer and send prefer header return=representation in query string - expect 200
                        webRequest.RequestUriString = "/Customers(1)/Name?Override-Prefer=return=representation";
                        webRequest.IfMatch          = eTag;
                        webRequest.SetRequestStreamAsText("{\"value\": \"Name3\"}");
                        TestUtil.RunCatching(webRequest.SendRequest);
                        Assert.AreEqual(200, webRequest.ResponseStatusCode);
                        Assert.IsTrue(webRequest.GetResponseStreamAsText().Contains("TheTest/$metadata#Customers(1)/Name\",\"value\":\"Name3\""));
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void WritingEntityWithControlChars()
        {
            this.context.ResolveName = t => typeof(Customer).FullName;

            // Try a simple exercise with and without the entity handler.

            using (CustomDataContext.CreateChangeScope())
            {
                Customer customer = new Customer();
                customer.Name = "Control character here -> \0x02";
                customer.ID   = 1234;
                this.context.AddObject("Customers", customer);
                this.context.SaveChanges();
            }
        }
Exemplo n.º 13
0
            public void SampleServiceOperationBatch()
            {
                string batchRequestsDirectory = Path.Combine(TestUtil.ServerUnitTestSamples, @"tests\BatchRequests");

                foreach (string fileName in Directory.GetFiles(batchRequestsDirectory, "*serviceoperationrequest*"))
                {
                    string batchRequest     = File.ReadAllText(fileName);
                    string responseFileName = fileName.Replace("request", "response");

                    using (CustomDataContext.CreateChangeScope())
                    {
                        string actualResponse = BatchTestUtil.GetResponse(batchRequest, typeof(OpenBatchDataService), WebServerLocation.InProcess);
                        BatchTestUtil.CompareBatchResponse(responseFileName, actualResponse);
                    }
                }
            }
Exemplo n.º 14
0
            public void ETag_PUTPATCHResourceWithNoContent()
            {
                CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                    new Dimension("Type", new Type[] { typeof(Customer) }),
                    new Dimension("Method", new string[] { "PUT", "PATCH" }),
                    new Dimension("ProcessResponse", new bool[] { true, false }));

                using (CustomDataContext.CreateChangeScope())
                    using (TestUtil.RestoreStaticValueOnDispose(typeof(BaseTestWebRequest), "HostInterfaceType"))
                        using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                        {
                            request.DataServiceType = typeof(CustomDataContext);
                            BaseTestWebRequest.HostInterfaceType = typeof(Microsoft.OData.Service.IDataServiceHost2);

                            TestUtil.RunCombinatorialEngineFail(engine, values =>
                            {
                                Type type            = (Type)values["Type"];
                                string method        = (string)values["Method"];
                                bool processResponse = (bool)values["ProcessResponse"];

                                string atomPayload = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" +
                                                     "<entry xml:base=\"/\" " + TestUtil.CommonPayloadNamespaces + ">" +
                                                     AtomUpdatePayloadBuilder.GetCategoryXml(type.FullName) +
                                                     "</entry>";

                                request.RequestUriString = "/Customers(0)";
                                request.HttpMethod       = method;
                                request.IfMatch          = "W/\"sdfght\""; // Wrong ETag
                                request.RequestVersion   = "4.0;";
                                if (processResponse)
                                {
                                    request.RequestHeaders["Prefer"] = "return=representation";
                                }
                                else
                                {
                                    request.RequestHeaders["Prefer"] = "return=minimal";
                                }

                                request.SetRequestStreamAsText(atomPayload);
                                request.RequestContentType = UnitTestsUtil.AtomFormat;
                                Exception e = TestUtil.RunCatching(request.SendRequest);
                                Assert.IsNotNull(e, "The request should have failed.");
                                Assert.AreEqual(412, request.ResponseStatusCode, "The request should have failed due to mismatch in ETags");
                            });
                        }
            }
Exemplo n.º 15
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')]");
        }
Exemplo n.º 16
0
            public void GetNullPrimitiveValueWithAnyValueForETag()
            {
                using (CustomDataContext.CreateChangeScope())
                {
                    Type contextType = typeof(CustomDataContext);

                    var ifMatchHeader = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("If-Match", "*") };

                    // Set the name property to null
                    UnitTestsUtil.SendRequestAndVerifyXPath(null, "/Customers(1)/Name/$value", null, contextType, UnitTestsUtil.JsonLightMimeType, "DELETE", ifMatchHeader, false);

                    // Both should work fine since the etag is of Customers(1)
                    UnitTestsUtil.SendRequestAndVerifyXPath(null, "/Customers(1)/Name", null, contextType, UnitTestsUtil.JsonLightMimeType, "GET", ifMatchHeader, true);
                    VerifyStatusCode("/Customers(1)/Name", UnitTestsUtil.JsonLightMimeType, "*", contextType, (int)HttpStatusCode.NotModified);

                    // This should return 404
                    UnitTestsUtil.VerifyInvalidRequest(null, "/Customers(1)/Name/$value", contextType, null, "GET", (int)HttpStatusCode.NotFound, ifMatchHeader);
                    VerifyStatusCode("/Customers(1)/Name/$value", UnitTestsUtil.MimeTextPlain, "*", contextType, (int)HttpStatusCode.NotModified);
                }
            }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        [Ignore] // Remove Atom
        // [TestMethod, TestCategory("Partition1")]
        public void OverloadUpdateRequestWithContentTypeContentLengthHeader()
        {
            using (CustomDataContext.CreateChangeScope())
            {
                using (TestWebRequest webRequest = TestWebRequest.CreateForInProcessWcf())
                {
                    // get an existing customer before the PUT requests
                    webRequest.HttpMethod       = "GET";
                    webRequest.ServiceType      = typeof(ModifyHeaderOnStartProcessingRequestTestService);
                    webRequest.RequestUriString = "/Customers(1)";
                    webRequest.Accept           = UnitTestsUtil.JsonLightMimeType;
                    TestUtil.RunCatching(webRequest.SendRequest);
                    Assert.IsTrue(webRequest.ResponseContentType.ToLower().Contains(UnitTestsUtil.JsonLightMimeType.ToLower()));

                    // all the subsequent requests are PUT requests with specified Accept If-Match, and Content-Type headers
                    webRequest.HttpMethod         = "PUT";
                    webRequest.Accept             = UnitTestsUtil.JsonLightMimeType;
                    webRequest.IfMatch            = "*";
                    webRequest.RequestContentType = "application/json";

                    // override Content-Type header
                    webRequest.RequestUriString = "/Customers(1)/Name?Override-Content-Type=application/xml";
                    webRequest.SetRequestStreamAsText("{\"value\": \"Name1\"}");
                    TestUtil.RunCatching(webRequest.SendRequest);
                    Assert.AreEqual(400, webRequest.ResponseStatusCode);
                    // The following response header is written in ProcessingRequest/OnStartProcessingRequest
                    Assert.IsTrue(webRequest.GetResponseStreamAsText().Contains("Data at the root level is invalid."));

                    // override Content-Length header
                    webRequest.RequestUriString = "/Customers(1)/Name?Override-Content-Length=10000";
                    webRequest.SetRequestStreamAsText("{\"value\": \"Name1\"}");
                    TestUtil.RunCatching(webRequest.SendRequest);
                    Assert.AreEqual(204, webRequest.ResponseStatusCode);
                    // The following response header is written in ProcessingRequest/OnStartProcessingRequest
                    Assert.AreEqual("10000", webRequest.ResponseHeaders["Request-Content-Length"]);
                }
            }
        }
Exemplo n.º 19
0
        private static void CompareIds(string uri, string uri1)
        {
            string xpath = "/atom:feed/atom:id";

            using (CustomDataContext.CreateChangeScope())
                using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                {
                    request.DataServiceType  = typeof(CustomDataContext);
                    request.RequestUriString = uri;
                    request.Accept           = "application/atom+xml,application/xml";
                    request.SendRequest();
                    XmlDocument document = request.GetResponseStreamAsXmlDocument();
                    string      id       = document.SelectSingleNode(xpath, TestUtil.TestNamespaceManager).InnerText;

                    request.DataServiceType  = typeof(CustomDataContext);
                    request.RequestUriString = uri1;
                    request.SendRequest();
                    document = request.GetResponseStreamAsXmlDocument();
                    string id1 = document.SelectSingleNode(xpath, TestUtil.TestNamespaceManager).InnerText;

                    Assert.AreEqual(id, id1);
                    Assert.IsFalse(id.Contains("()"));
                }
        }
Exemplo n.º 20
0
 [Ignore] // Remove Atom
 // [TestCategory("Partition2"), TestMethod, Variation]
 public void TestExceedMaxBatchCount()
 {
     // Astoria Server: Assert on Batch Request after configuring MaxBatchCount
     TestUtil.ClearConfiguration();
     try
     {
         using (CustomDataContext.CreateChangeScope())
             using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                 using (StaticCallbackManager <InitializeServiceArgs> .RegisterStatic((sender, args) =>
                 {
                     args.Config.SetEntitySetAccessRule("*", EntitySetRights.All);
                     args.Config.MaxBatchCount = 1;
                     args.Config.UseVerboseErrors = true;
                 }))
                 {
                     request.ServiceType        = typeof(TypedDataService <CustomDataContext>);
                     request.HttpMethod         = "POST";
                     request.RequestUriString   = "/$batch";
                     request.RequestContentType = "multipart/mixed;boundary=boundary1";
                     request.SetRequestStreamAsText(
                         "--boundary1\r\n" +
                         "Content-Type: multipart/mixed; boundary=cs\r\n" +
                         "\r\n" +
                         "--cs\r\n" +
                         "Content-Type: application/http\r\n" +
                         "Content-Transfer-Encoding: binary\r\n" +
                         "\r\n" +
                         "POST /Customers HTTP/1.1\r\n" +
                         "Content-Type: application/atom+xml\r\n" +
                         "Accept: application/atom+xml\r\n" +
                         "Content-ID : 2\r\n" +
                         "\r\n" +
                         "<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:type='#AstoriaUnitTests.Stubs.Customer'>\r\n" +
                         "<content type='application/xml'>\r\n" +
                         "<adsm:properties>\r\n" +
                         "<ads:ID ads:type='Edm.Int32'>10</ads:ID>\r\n" +
                         "</adsm:properties>\r\n" +
                         "</content></entry>\r\n" +
                         "--cs--\r\n" +
                         "--boundary1\r\n" +
                         "Content-Type: multipart/mixed; boundary=cs\r\n" +
                         "\r\n" +
                         "--cs\r\n" +
                         "Content-Type: application/http\r\n" +
                         "Content-Transfer-Encoding: binary\r\n" +
                         "\r\n" +
                         "POST /Customers HTTP/1.1\r\n" +
                         "Content-Type: application/atom+xml\r\n" +
                         "Accept: application/atom+xml\r\n" +
                         "Content-ID : 2\r\n" +
                         "\r\n" +
                         "<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:type='#AstoriaUnitTests.Stubs.Customer'>\r\n" +
                         "<content type='application/xml'>\r\n" +
                         "<adsm:properties>\r\n" +
                         "<ads:ID ads:type='Edm.Int32'>10</ads:ID>\r\n" +
                         "</adsm:properties>\r\n" +
                         "</content></entry>\r\n" +
                         "--cs--\r\n" +
                         "--boundary1--");
                     Exception exception = TestUtil.RunCatching(request.SendRequest);
                     TestUtil.AssertExceptionExpected(exception, false);
                     string response = request.GetResponseStreamAsText();
                     TestUtil.AssertContains(response, "exceeds");
                 }
     }
     finally
     {
         TestUtil.ClearMetadataCache();
     }
 }
Exemplo n.º 21
0
        public void ExerciseApplyItemsToCollectionViaMergeLists()
        {
            MergeOption original = this.context.MergeOption;

            try
            {
                foreach (MergeOption mo in new[] { MergeOption.OverwriteChanges, MergeOption.PreserveChanges })
                {
                    using (CustomDataContext.CreateChangeScope())
                        using (OpenWebDataServiceHelper.PageSizeCustomizer.Restore())
                        {
                            OpenWebDataServiceHelper.PageSizeCustomizer.Value = (config, type) => { config.SetEntitySetPageSize("Orders", 5); };
                            NarrowCustomer c0 = new NarrowCustomer()
                            {
                                ID = 0
                            };

                            this.context.MergeOption = mo;

                            this.context.AttachTo("Customers", c0);

                            var customers = this.context.CreateQuery <NarrowCustomer>("Customers")
                                            .Where(c => c.ID == 0)
                                            .Select(c => new NarrowCustomer()
                            {
                                ID = c.ID, Orders = c.Orders.Select(o => new NarrowOrder()
                                {
                                    DollarAmount = o.DollarAmount
                                }).ToList()
                            });

                            foreach (var dummy in customers)
                            {
                            }

                            var customers2 = this.context.CreateQuery <NarrowCustomer>("Customers")
                                             .Where(c => c.ID == 0)
                                             .Select(c => new NarrowCustomer()
                            {
                                ID = c.ID, Orders = c.Orders.Select(o => new NarrowOrder()
                                {
                                    DollarAmount = o.DollarAmount
                                }).ToList()
                            });

                            foreach (var dummy in customers2)
                            {
                            }

                            // Ensure that we still have the same item count
                            Assert.IsTrue(c0.Orders.Count == 2);
                        }

                    this.ClearContext();
                }
            }
            finally
            {
                this.context.MergeOption = original;
            }
        }
Exemplo n.º 22
0
        protected override void RunCommand(IEnumerable <string> args)
        {
            List <string> argsList = args.ToList();

            if (showCommandHelp(argsList))
            {
                return;
            }

            ArkDataManager.LoadData(GlobalOptions.Language);

            Stopwatch stopwatch = new Stopwatch(GlobalOptions.UseStopWatch);

            bool mapNeeded = !string.IsNullOrEmpty(inventory) || positions;

            if (!GlobalOptions.Quiet && mapNeeded)
            {
                Console.WriteLine("Need to load map, this may take some time...");
            }

            string saveGame = argsList.Count > 0
                    ? argsList[0]
                    : Path.Combine(GlobalOptions.ArkToolsConfiguration.BasePath, GlobalOptions.ArkToolsConfiguration.ArkSavegameFilename);
            string outputDirectory = argsList.Count > 1 ? argsList[1] : Path.Combine(GlobalOptions.ArkToolsConfiguration.BasePath, GlobalOptions.ArkToolsConfiguration.PlayersPath);
            string saveDir         = Path.GetDirectoryName(saveGame);

            CustomDataContext context = new CustomDataContext();

            if (mapNeeded)
            {
                ArkSavegame mapSave = new ArkSavegame().ReadBinary <ArkSavegame>(saveGame, ReadingOptions.Create().WithBuildComponentTree(true));
                context.ObjectContainer = mapSave;
                context.Savegame        = mapSave;
                context.MapData         = LatLonCalculator.ForSave(mapSave);
                stopwatch.Stop("Loading map data");
            }

            Dictionary <int, Tribe> tribes = new Dictionary <int, Tribe>();
            List <Action>           tasks  = GlobalOptions.Parallel ? new List <Action>() : null;

            foreach (string path in Directory.EnumerateFiles(saveDir).Where(path => profilePattern.IsMatch(Path.GetFileName(path))))
            {
                if (maxAge.HasValue)
                {
                    DateTimeOffset fileTime = File.GetLastWriteTimeUtc(path);

                    if (fileTime < DateTimeOffset.UtcNow.AddSeconds(-maxAge.Value))
                    {
                        continue;
                    }
                }

                Action task = () => {
                    try {
                        Player player = new Player(path, context, ReadingOptions.Create());

                        long playerId = player.playerDataId;

                        string playerFileName;
                        if (naming == "steamid" || string.IsNullOrWhiteSpace(naming))
                        {
                            playerFileName = player.uniqueId.NetId + ".json";
                        }
                        else if (naming == "playerid")
                        {
                            playerFileName = playerId + ".json";
                        }
                        else
                        {
                            throw new Exception("Invalid value for parameter naming.");
                        }

                        if (player.tribeId != 0)
                        {
                            if (!tribes.ContainsKey(player.tribeId))
                            {
                                string tribePath = Path.Combine(saveDir, player.tribeId + ".arktribe");
                                if (File.Exists(tribePath))
                                {
                                    try {
                                        tribes[player.tribeId] = new Tribe(tribePath, ReadingOptions.Create());
                                    } catch (Exception ex) {
                                        // Either the header didn't match or one of the properties is missing
                                        Console.Error.WriteLine("Found potentially corrupt ArkTribe: " + tribePath);
                                        if (GlobalOptions.Verbose)
                                        {
                                            Console.Error.WriteLine(ex.Message);
                                            Console.Error.WriteLine(ex.StackTrace);
                                        }
                                    }
                                }
                            }
                        }

                        string playerPath = Path.Combine(outputDirectory, playerFileName);

                        void writePlayer(JsonTextWriter writer, WritingOptions options)
                        {
                            writer.WriteStartObject();

                            // Player data

                            player.WriteAllProperties(writer, context, writeAllFields, noPrivacy);

                            // Inventory
                            if (!string.IsNullOrEmpty(inventory))
                            {
                                player.WriteInventory(writer, context, writeAllFields, inventory.ToLowerInvariant() != "long");
                            }

                            // Tribe

                            if (player.tribeId != 0 && tribes.TryGetValue(player.tribeId, out Tribe tribe))
                            {
                                writer.WriteField("tribeName", tribe.tribeName);

                                if (writeAllFields || tribe.ownerPlayerDataId == playerId)
                                {
                                    writer.WriteField("tribeOwner", tribe.ownerPlayerDataId == playerId);
                                }

                                if (writeAllFields || tribe.tribeAdmins.Contains((int)playerId))
                                {
                                    writer.WriteField("tribeAdmin", tribe.tribeAdmins.Contains((int)playerId));
                                }
                            }

                            writer.WriteEndObject();
                        }

                        CommonFunctions.WriteJson(playerPath, writePlayer, writingOptions);
                    } catch (Exception ex) when(!Debugger.IsAttached)
                    {
                        Console.Error.WriteLine("Found potentially corrupt ArkProfile: " + path);
                        if (GlobalOptions.Verbose)
                        {
                            Console.Error.WriteLine(ex.Message);
                            Console.Error.WriteLine(ex.StackTrace);
                        }
                    }
                };

                if (tasks != null)
                {
                    tasks.Add(task);
                }
                else
                {
                    task();
                }
            }

            if (tasks != null)
            {
                Parallel.ForEach(tasks, task => task());
            }

            stopwatch.Stop("Loading profiles and writing info");
            stopwatch.Print();
        }
Exemplo n.º 23
0
        public void LoadPropertyRemoveElementUnChangedSource()
        {
            MergeOption original = this.context.MergeOption;

            try
            {
                foreach (MergeOption mo in new[] { MergeOption.OverwriteChanges, MergeOption.PreserveChanges })
                {
                    foreach (bool usePaging in new[] { false, true })
                    {
                        using (CustomDataContext.CreateChangeScope())
                            using (OpenWebDataServiceHelper.PageSizeCustomizer.Restore())
                            {
                                OpenWebDataServiceHelper.PageSizeCustomizer.Value = (config, type) => { config.SetEntitySetPageSize("Orders", usePaging ? 1 : 5); };
                                Customer c = new Customer()
                                {
                                    ID = 0
                                };
                                Customer c2 = new Customer()
                                {
                                    ID = 2
                                };
                                Order o = new Order()
                                {
                                    ID = 102
                                };

                                this.context.MergeOption = mo;

                                this.context.AttachTo("Customers", c);
                                this.context.AttachTo("Customers", c2);
                                this.context.AttachTo("Orders", o);

                                this.context.AddLink(c, "Orders", o);
                                this.context.SetLink(o, "Customer", c);
                                this.context.SaveChanges();

                                if (usePaging)
                                {
                                    DataServiceQueryContinuation continuation = null;
                                    do
                                    {
                                        QueryOperationResponse response = this.context.LoadProperty(c, "Orders", continuation);
                                        continuation = response.GetContinuation();
                                    }while (continuation != null);
                                }
                                else
                                {
                                    this.context.LoadProperty(c, "Orders");
                                }

                                this.context.LoadProperty(o, "Customer");

                                if (c.Orders != null)
                                {
                                    Assert.IsTrue(c.Orders.Contains(o));
                                }
                                if (o.Customer != null)
                                {
                                    Assert.IsTrue(o.Customer.ID == c.ID);
                                }

                                // Remove the link
                                this.context.DeleteLink(c, "Orders", o);
                                this.context.SetLink(o, "Customer", c2);

                                this.context.SaveChanges();

                                if (usePaging)
                                {
                                    DataServiceQueryContinuation continuation = null;
                                    do
                                    {
                                        QueryOperationResponse response = this.context.LoadProperty(c, "Orders", continuation);
                                        continuation = response.GetContinuation();
                                    }while (continuation != null);
                                }
                                else
                                {
                                    this.context.LoadProperty(c, "Orders");
                                }

                                this.context.LoadProperty(o, "Customer");

                                if (c.Orders != null)
                                {
                                    Assert.IsFalse(c.Orders.Contains(o));
                                }
                                if (o.Customer != null)
                                {
                                    Assert.IsFalse(o.Customer.ID == c.ID);
                                }
                            }

                        this.ClearContext();
                    }
                }
            }
            finally
            {
                this.context.MergeOption = original;
            }
        }
Exemplo n.º 24
0
        private void writeList(KeyValuePair <string, List <GameObject> > entry)
        {
            string outputFile = Path.Combine(outputDirectory, entry.Key + ".json");

            List <GameObject> filteredClasses = entry.Value;
            MapData           mapData         = LatLonCalculator.ForSave(arkSavegame);

            CommonFunctions.WriteJson(outputFile, (generator, writingOptions) => {
                if (statistics)
                {
                    generator.WriteStartObject();

                    generator.WriteField("count", filteredClasses.Count);

                    List <int> summaryStatistics = filteredClasses.Where(o => o.IsWild())
                                                   .Select(a => a.GetBaseLevel(arkSavegame)).ToList();
                    if (summaryStatistics.Any())
                    {
                        generator.WriteField("wildMin", summaryStatistics.Min());
                        generator.WriteField("wildMax", summaryStatistics.Max());
                        generator.WriteField("wildAverage", summaryStatistics.Average());
                    }

                    List <int> tamedBaseStatistics = filteredClasses.Where(o => o.IsTamed())
                                                     .Select(a => a.GetBaseLevel(arkSavegame)).ToList();
                    if (tamedBaseStatistics.Any())
                    {
                        generator.WriteField("tamedBaseMin", tamedBaseStatistics.Min());
                        generator.WriteField("tamedBaseMax", tamedBaseStatistics.Max());
                        generator.WriteField("tamedBaseAverage", tamedBaseStatistics.Average());
                    }

                    List <int> tamedFullStatistics = filteredClasses.Where(o => o.IsTamed())
                                                     .Select(a => a.GetFullLevel(arkSavegame)).ToList();
                    if (tamedFullStatistics.Any())
                    {
                        generator.WriteField("tamedFullMin", tamedFullStatistics.Min());
                        generator.WriteField("tamedFullMax", tamedFullStatistics.Max());
                        generator.WriteField("tamedFullAverage", tamedFullStatistics.Average());
                    }

                    generator.WritePropertyName("dinos");
                    generator.WriteStartArray();
                }
                else
                {
                    generator.WriteStartArray();
                }

                CustomDataContext context = new CustomDataContext {
                    MapData         = mapData,
                    ObjectContainer = container,
                    Savegame        = arkSavegame
                };
                foreach (GameObject creatureObject in filteredClasses)
                {
                    Creature creature = new Creature(creatureObject, container);
                    generator.WriteStartObject();
                    creature.writeAllProperties(generator, context, writeAllFields);
                    if (!string.IsNullOrWhiteSpace(inventory))
                    {
                        creature.writeInventory(generator, context, writeAllFields, inventory == "summary");
                    }

                    generator.WriteEndObject();
                }

                generator.WriteEndArray();

                if (statistics)
                {
                    generator.WriteEndObject();
                }
            }, writingOptions);
        }
Exemplo n.º 25
0
        public void RequestUriProcessorNullNavigationTest()
        {
            string[] uris = new string[]
            {
                "/Customer(100)/BestFriend/Name",
                "/Customer(100)/Orders",
                "/Customer(100)/Orders(1)",
                "/Customer(100)/Orders(1)/DollarAmount",
                // "/Customer(100)/BestFriend/BestFriend/Name",
            };

            using (CustomDataContext.CreateChangeScope())
            using (TestWebRequest request = TestWebRequest.CreateForInProcess())
            {
                request.DataServiceType = typeof(CustomDataContext);

                var c = new CustomDataContext();
                c.InternalCustomersList.Add(new Customer() { ID = 100, BestFriend = null, Orders = null });
                c.SaveChanges();

                CombinatorialEngine engine = CombinatorialEngine.FromDimensions(new Dimension("URI", uris));
                TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
                {
                    string uri = (string)values["URI"];
                    request.RequestUriString = "/Customer(100)/BestFriend/Name";
                    Exception exception = TestUtil.RunCatching(request.SendRequest);
                    TestUtil.AssertExceptionStatusCode(exception, 404, "404 expected for " + uri);
                });
            }
        }
Exemplo n.º 26
0
        protected override void RunCommand(IEnumerable <string> args)
        {
            List <string> argsList = args.ToList();

            if (showCommandHelp(argsList))
            {
                return;
            }

            bool itemsLong      = withItems == "long";
            bool inventoryLong  = withInventory == "long";
            bool tamedLong      = tamed == "long";
            bool structuresLong = withStructures == "long";

            Stopwatch stopwatch = new Stopwatch(GlobalOptions.UseStopWatch);

            bool mapNeeded = withItems != null || tamed != null || withStructures != null || withInventory != null;

            if (!GlobalOptions.Quiet && mapNeeded)
            {
                Console.WriteLine("Need to load map, this may take some time...");
            }

            string saveGame        = argsList.Count > 0 ? argsList[0] : Path.Combine(GlobalOptions.ArkToolsConfiguration.BasePath, GlobalOptions.ArkToolsConfiguration.ArkSavegameFilename);
            string outputDirectory = argsList.Count > 1 ? argsList[1] : Path.Combine(GlobalOptions.ArkToolsConfiguration.BasePath, GlobalOptions.ArkToolsConfiguration.TribesPath);
            string saveDir         = Path.GetDirectoryName(saveGame);

            Dictionary <int, HashSet <TribeBase> > baseMap;
            CustomDataContext context = new CustomDataContext();

            if (mapNeeded)
            {
                ArkDataManager.LoadData(GlobalOptions.Language);

                ArkSavegame mapSave = new ArkSavegame().ReadBinary <ArkSavegame>(saveGame, ReadingOptions.Create().WithBuildComponentTree(true));
                context.Savegame = mapSave;
                context.MapData  = LatLonCalculator.ForSave(context.Savegame);
                stopwatch.Stop("Loading map data");
                if (withBases)
                {
                    baseMap = new Dictionary <int, HashSet <TribeBase> >();
                    foreach (GameObject gameObject in mapSave)
                    {
                        // Skip items and stuff without a location
                        if (gameObject.IsItem || gameObject.Location == null)
                        {
                            continue;
                        }

                        string signText      = gameObject.GetPropertyValue <string>("SignText");
                        long?  targetingTeam = gameObject.GetPropertyValue <long?>("TargetingTeam");

                        if (signText != null && targetingTeam != null)
                        {
                            // Might be a 'Base' sign
                            MatchCollection matcher = basePattern.Matches(signText);
                            if (matcher.Any())
                            {
                                // Found a base sign, add it to the set, automatically replacing duplicates
                                int          tribeId  = (int)targetingTeam;
                                LocationData location = gameObject.Location;
                                string       baseName = matcher[1].Value;
                                float        size     = float.Parse(matcher[2].Value);

                                TribeBase tribeBase = new TribeBase(baseName, location.X, location.Y, location.Z, size);

                                if (!baseMap.ContainsKey(tribeId))
                                {
                                    baseMap[tribeId] = new HashSet <TribeBase>();
                                }

                                baseMap[tribeId].Add(tribeBase);
                            }
                        }
                    }

                    stopwatch.Stop("Collecting bases");
                }
                else
                {
                    baseMap = null;
                }

                if (mapSave.HibernationEntries.Any() && tamed != null)
                {
                    List <GameObject> combinedObjects = context.Savegame.Objects.ToList();

                    foreach (HibernationEntry entry in context.Savegame.HibernationEntries)
                    {
                        ObjectCollector collector = new ObjectCollector(entry, 1);
                        combinedObjects.AddRange(collector.Remap(combinedObjects.Count));
                    }

                    context.ObjectContainer = new GameObjectContainer(combinedObjects);
                }
                else
                {
                    context.ObjectContainer = mapSave;
                }
            }
            else
            {
                baseMap = null;
            }

            List <Action> tasks = GlobalOptions.Parallel ? new List <Action>() : null;

            void mapWriter(JsonTextWriter generator, int tribeId)
            {
                if (!mapNeeded)
                {
                    return;
                }
                List <GameObject>  structures   = new List <GameObject>();
                List <GameObject>  creatures    = new List <GameObject>();
                List <Item>        items        = new List <Item>();
                List <Item>        blueprints   = new List <Item>();
                List <DroppedItem> droppedItems = new List <DroppedItem>();
                // Apparently there is a behavior in ARK causing certain structures to exist twice within a save
                HashSet <ArkName> processedList = new HashSet <ArkName>();
                // Bases
                HashSet <TribeBase> bases = withBases ? baseMap[tribeId] : null;

                foreach (GameObject gameObject in context.ObjectContainer)
                {
                    if (gameObject.IsItem)
                    {
                        continue;
                    }

                    int targetingTeam = gameObject.GetPropertyValue <int>("TargetingTeam", defaultValue: -1);
                    if (targetingTeam == -1)
                    {
                        continue;
                    }

                    TeamType teamType = TeamTypes.ForTeam(targetingTeam);
                    if (tribeId == -1 && teamType != TeamType.Player)
                    {
                        continue;
                    }

                    if (tribeId == 0 && teamType != TeamType.NonPlayer)
                    {
                        continue;
                    }

                    if (tribeId > 0 && tribeId != targetingTeam)
                    {
                        continue;
                    }

                    // Determine base if we have bases
                    TribeBase tribeBase;
                    if (bases != null && gameObject.Location != null)
                    {
                        TribeBase matchedBase = null;
                        foreach (TribeBase potentialBase in bases)
                        {
                            if (potentialBase.InsideBounds(gameObject.Location))
                            {
                                matchedBase = potentialBase;
                                break;
                            }
                        }

                        tribeBase = matchedBase;
                    }
                    else
                    {
                        tribeBase = null;
                    }

                    if (gameObject.IsCreature())
                    {
                        if (!processedList.Contains(gameObject.Names[0]))
                        {
                            if (tribeBase != null)
                            {
                                tribeBase.Creatures.Add(gameObject);
                            }
                            else
                            {
                                creatures.Add(gameObject);
                            }

                            processedList.Add(gameObject.Names[0]);
                        }
                        else
                        {
                            // Duped Creature
                            continue;
                        }
                    }
                    else if (!gameObject.IsPlayer() && !gameObject.IsWeapon() && !gameObject.IsDroppedItem())
                    {
                        // LinkedPlayerDataID: Players ain't structures
                        // AssociatedPrimalItem: Items equipped by sleeping players
                        // MyItem: dropped item
                        if (!processedList.Contains(gameObject.Names[0]))
                        {
                            if (tribeBase != null)
                            {
                                tribeBase.Structures.Add(gameObject);
                            }
                            else
                            {
                                structures.Add(gameObject);
                            }

                            processedList.Add(gameObject.Names[0]);
                        }
                        else
                        {
                            // Duped Structure
                            continue;
                        }
                    }
                    else
                    {
                        if (!processedList.Contains(gameObject.Names[0]))
                        {
                            processedList.Add(gameObject.Names[0]);
                        }
                        else
                        {
                            // Duped Player or dropped Item or weapon
                            continue;
                        }
                    }

                    void itemHandler(ObjectReference itemReference)
                    {
                        GameObject item = itemReference.GetObject(context.Savegame);

                        if (item != null && !Item.isDefaultItem(item))
                        {
                            if (processedList.Contains(item.Names[0]))
                            {
                                // happens for players having items in their quick bar
                                return;
                            }

                            processedList.Add(item.Names[0]);

                            if (item.HasAnyProperty("bIsBlueprint"))
                            {
                                if (tribeBase != null)
                                {
                                    tribeBase.Blueprints.Add(new Item(item));
                                }
                                else
                                {
                                    blueprints.Add(new Item(item));
                                }
                            }
                            else
                            {
                                if (tribeBase != null)
                                {
                                    tribeBase.Items.Add(new Item(item));
                                }
                                else
                                {
                                    items.Add(new Item(item));
                                }
                            }
                        }
                    }

                    void droppedItemHandler(GameObject droppedItemObject)
                    {
                        DroppedItem droppedItem = new DroppedItem(droppedItemObject, context.Savegame);

                        if (tribeBase != null)
                        {
                            tribeBase.DroppedItems.Add(droppedItem);
                        }
                        else
                        {
                            droppedItems.Add(droppedItem);
                        }
                    }

                    if (withItems != null && withInventory == null)
                    {
                        foreach (GameObject inventory in gameObject.Components.Values)
                        {
                            if (!inventory.IsInventory())
                            {
                                continue;
                            }

                            List <ObjectReference> inventoryItems = inventory.GetPropertyValue <IArkArray, ArkArrayObjectReference>("InventoryItems");
                            foreach (ObjectReference itemReference in inventoryItems ?? Enumerable.Empty <ObjectReference>())
                            {
                                itemHandler(itemReference);
                            }

                            List <ObjectReference> equippedItems = inventory.GetPropertyValue <IArkArray, ArkArrayObjectReference>("EquippedItems");
                            foreach (ObjectReference itemReference in equippedItems ?? Enumerable.Empty <ObjectReference>())
                            {
                                itemHandler(itemReference);
                            }
                        }
                    }

                    ObjectReference myItem = gameObject.GetPropertyValue <ObjectReference>("MyItem");

                    if (myItem != null)
                    {
                        if (withItems != null && withInventory == null)
                        {
                            itemHandler(myItem);
                        }
                        else if (withInventory != null)
                        {
                            droppedItemHandler(gameObject);
                        }
                    }
                }

                void writeStructures(IEnumerable <GameObject> structList)
                {
                    if (withStructures == null)
                    {
                        return;
                    }
                    generator.WriteArrayFieldStart("structures");

                    if (structuresLong)
                    {
                        foreach (GameObject structureObject in structList)
                        {
                            Structure structure = new Structure(structureObject, context.Savegame);

                            generator.WriteStartObject();

                            structure.writeAllProperties(generator, context, writeAllFields);

                            if (withInventory != null)
                            {
                                structure.writeInventory(generator, context, writeAllFields, !inventoryLong);
                            }

                            generator.WriteEndObject();
                        }
                    }
                    else
                    {
                        Dictionary <ArkName, long> structMap = structList.GroupBy(o => o.ClassName).ToDictionary(objects => objects.Key, objects => objects.LongCount());
                        foreach (KeyValuePair <ArkName, long> entry in structMap.OrderByDescending(pair => pair.Value))
                        {
                            generator.WriteStartObject();

                            string name = entry.Key.ToString();
                            if (ArkDataManager.HasStructure(name))
                            {
                                name = ArkDataManager.GetStructure(name).Name;
                            }

                            generator.WriteField("name", name);
                            generator.WriteField("count", entry.Value);

                            generator.WriteEndObject();
                        }
                    }

                    generator.WriteEndArray();
                }

                void writeCreatures(List <GameObject> creaList)
                {
                    if (tamed == null)
                    {
                        return;
                    }
                    generator.WriteArrayFieldStart("tamed");

                    if (tamedLong)
                    {
                        foreach (GameObject creatureObject in creaList)
                        {
                            Creature creature = new Creature(creatureObject, context.Savegame);

                            generator.WriteStartObject();

                            creature.writeAllProperties(generator, context, writeAllFields);

                            if (withInventory != null)
                            {
                                creature.writeInventory(generator, context, writeAllFields, !inventoryLong);
                            }

                            generator.WriteEndObject();
                        }
                    }
                    else
                    {
                        Dictionary <ArkName, long> creaMap = creaList.GroupBy(o => o.ClassName).ToDictionary(objects => objects.Key, objects => objects.LongCount());
                        foreach (KeyValuePair <ArkName, long> entry in creaMap.OrderByDescending(pair => pair.Value))
                        {
                            generator.WriteStartObject();

                            string name = entry.Key.ToString();
                            if (ArkDataManager.HasCreature(name))
                            {
                                name = ArkDataManager.GetCreature(name).Name;
                            }

                            generator.WriteField("name", name);
                            generator.WriteField("count", entry.Value);

                            generator.WriteEndObject();
                        }
                    }

                    generator.WriteEndArray();
                }

                void writeDroppedItems(List <DroppedItem> droppedList)
                {
                    if (withInventory == null)
                    {
                        return;
                    }
                    generator.WriteArrayFieldStart("droppedItems");

                    foreach (DroppedItem droppedItem in droppedList)
                    {
                        generator.WriteStartObject();

                        droppedItem.writeAllProperties(generator, context, writeAllFields);
                        droppedItem.writeInventory(generator, context, writeAllFields, !inventoryLong);

                        generator.WriteEndObject();
                    }

                    generator.WriteEndArray();
                }

                if (withBases && bases != null)
                {
                    generator.WriteArrayFieldStart("bases");

                    foreach (TribeBase tribeBase in bases)
                    {
                        generator.WriteStartObject();

                        generator.WriteField("name", tribeBase.Name);
                        generator.WriteField("x", tribeBase.X);
                        generator.WriteField("y", tribeBase.Y);
                        generator.WriteField("z", tribeBase.Z);
                        generator.WriteField("lat", context.MapData.CalculateLat(tribeBase.Y));
                        generator.WriteField("lon", context.MapData.CalculateLon(tribeBase.X));
                        generator.WriteField("radius", tribeBase.Size);
                        writeCreatures(tribeBase.Creatures);
                        writeStructures(tribeBase.Structures);
                        writeDroppedItems(tribeBase.DroppedItems);
                        if (itemsLong)
                        {
                            generator.WritePropertyName("items");
                            Inventory.writeInventoryLong(generator, context, tribeBase.Items, writeAllFields);
                            generator.WritePropertyName("blueprints");
                            Inventory.writeInventoryLong(generator, context, tribeBase.Blueprints, writeAllFields);
                        }
                        else
                        {
                            generator.WritePropertyName("items");
                            Inventory.writeInventorySummary(generator, tribeBase.Items);
                            generator.WritePropertyName("blueprints");
                            Inventory.writeInventorySummary(generator, tribeBase.Blueprints);
                        }

                        generator.WriteEndObject();
                    }

                    generator.WriteStartObject();
                }

                writeCreatures(creatures);
                writeStructures(structures);
                writeDroppedItems(droppedItems);
                if (itemsLong)
                {
                    generator.WritePropertyName("items");
                    Inventory.writeInventoryLong(generator, context, items, writeAllFields);
                    generator.WritePropertyName("blueprints");
                    Inventory.writeInventoryLong(generator, context, blueprints, writeAllFields);
                }
                else
                {
                    generator.WritePropertyName("items");
                    Inventory.writeInventorySummary(generator, items);
                    generator.WritePropertyName("blueprints");
                    Inventory.writeInventorySummary(generator, blueprints);
                }

                if (withBases && bases != null)
                {
                    generator.WriteEndObject();

                    generator.WriteEndArray();
                }
            }

            foreach (string path in Directory.EnumerateFiles(saveDir).Where(path => tribePattern.IsMatch(path)))
            {
                Action task = () => {
                    try {
                        Tribe tribe = new Tribe(path, ReadingOptions.Create());

                        string tribeFileName = tribe.tribeId + ".json";

                        string tribePath = Path.Combine(outputDirectory, tribeFileName);

                        CommonFunctions.WriteJson(tribePath, (generator, writingOptions) => {
                            generator.WriteStartObject();

                            tribe.writeAllProperties(generator, context, writeAllFields);

                            mapWriter(generator, tribe.tribeId);

                            generator.WriteEndObject();
                        }, writingOptions);
                    } catch (Exception ex) {
                        Console.Error.WriteLine("Found potentially corrupt ArkTribe: " + path);
                        if (GlobalOptions.Verbose)
                        {
                            Console.Error.WriteLine(ex.Message);
                            Console.Error.WriteLine(ex.StackTrace);
                        }
                    }
                };

                if (tasks != null)
                {
                    tasks.Add(task);
                }
                else
                {
                    task();
                }
            }

            if (tasks != null)
            {
                Parallel.ForEach(tasks, task => task());
            }

            if (tribeless)
            {
                string tribePath = Path.Combine(outputDirectory, "tribeless.json");

                CommonFunctions.WriteJson(tribePath, (generator, writingOptions) => {
                    generator.WriteStartObject();

                    mapWriter(generator, -1);

                    generator.WriteEndObject();
                }, writingOptions);
            }

            if (nonPlayers)
            {
                string tribePath = Path.Combine(outputDirectory, "non-players.json");

                CommonFunctions.WriteJson(tribePath, (generator, writingOptions) => {
                    generator.WriteStartObject();

                    mapWriter(generator, 0);

                    generator.WriteEndObject();
                }, writingOptions);
            }

            stopwatch.Stop("Loading tribes and writing info");
            stopwatch.Print();
        }
Exemplo n.º 27
0
 public CustomUserStore(CustomDataContext context)
 {
     _context = context;
 }
Exemplo n.º 28
0
 public CustomRoleStore(CustomDataContext context)
 {
     _context = context;
 }
Exemplo n.º 29
0
            [Ignore] // Remove Atom
            // [TestCategory("Partition2"), TestMethod, Variation]
            public void ConfigurationBatchTest()
            {
                CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                    new Dimension("MaxBatchCount", new int[] { -1, 0, 1, 2, 10 }),
                    new Dimension("MaxChangeSetCount", new int[] { -1, 0, 1, 2, 10 }),
                    new Dimension("BatchCount", new int[] { 0, 1, 2 }),
                    new Dimension("ChangeSetCount", new int[] { 0, 1, 2 })
                    );

                TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
                {
                    int maxBatchCount     = (int)values["MaxBatchCount"];
                    int maxChangeSetCount = (int)values["MaxChangeSetCount"];
                    int batchCount        = (int)values["BatchCount"];
                    int changeSetCount    = (int)values["ChangeSetCount"];
                    TestUtil.ClearConfiguration();
                    using (CustomDataContext.CreateChangeScope())
                        using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                            using (StaticCallbackManager <InitializeServiceArgs> .RegisterStatic((sender, args) =>
                            {
                                args.Config.SetEntitySetAccessRule("*", EntitySetRights.All);
                                args.Config.MaxBatchCount = maxBatchCount;
                                args.Config.MaxChangesetCount = maxChangeSetCount;
                                args.Config.UseVerboseErrors = true;
                            }))
                            {
                                request.ServiceType        = typeof(TypedDataService <CustomDataContext>);
                                request.RequestUriString   = "/$batch";
                                request.HttpMethod         = "POST";
                                request.Accept             = "*/*";
                                string boundary            = "boundary";
                                request.RequestContentType = String.Format("{0}; boundary={1}", UnitTestsUtil.MimeMultipartMixed, boundary);

                                int customerId        = 1000;
                                int contentId         = 0;
                                StringBuilder payload = new StringBuilder();
                                for (int i = 0; i < batchCount; i++)
                                {
                                    StringBuilder batchElement = new StringBuilder();
                                    if (i % 2 == 0)
                                    {
                                        string changesetBoundary = "cs";
                                        for (int j = 0; j < changeSetCount; j++)
                                        {
                                            StringBuilder changeSetElement = new StringBuilder();
                                            changeSetElement.AppendLine("<entry " + TestUtil.CommonPayloadNamespaces + ">");
                                            changeSetElement.AppendLine(AtomUpdatePayloadBuilder.GetCategoryXml("AstoriaUnitTests.Stubs.Customer"));
                                            changeSetElement.AppendLine(" <content type='application/xml'><adsm:properties>");
                                            changeSetElement.AppendLine("  <ads:Name>A New Customer</ads:Name>");
                                            changeSetElement.AppendLine("  <ads:ID>" + customerId++ + "</ads:ID>");
                                            changeSetElement.AppendLine(" </adsm:properties></content></entry>");

                                            int length = changeSetElement.Length;
                                            changeSetElement.Insert(0,
                                                                    "--" + changesetBoundary + "\r\n" +
                                                                    "Content-Type: application/http\r\n" +
                                                                    "Content-Transfer-Encoding: binary\r\n" +
                                                                    "Content-ID: " + (++contentId).ToString() + "\r\n" +
                                                                    "\r\n" +
                                                                    "POST /Customers HTTP/1.1\r\n" +
                                                                    "Content-Type: application/atom+xml;type=entry\r\n" +
                                                                    "Content-Length: " + length + "\r\n" +
                                                                    "\r\n");
                                            batchElement.Append(changeSetElement.ToString());
                                        }

                                        batchElement.AppendLine("--" + changesetBoundary + "--");
                                        int batchLength = batchElement.Length;
                                        batchElement.Insert(0,
                                                            "--" + boundary + "\r\n" +
                                                            "Content-Type: multipart/mixed; boundary=" + changesetBoundary + "\r\n" +
                                                            "Content-Length: " + batchLength + "\r\n" +
                                                            "\r\n");
                                    }
                                    else
                                    {
                                        // Do a GET request.
                                        batchElement.AppendLine("--" + boundary);
                                        batchElement.AppendLine("Content-Type: application/http");
                                        batchElement.AppendLine("Content-Transfer-Encoding: binary");
                                        batchElement.AppendLine();
                                        batchElement.AppendLine("GET /Customers HTTP/1.1");
                                        batchElement.AppendLine("Content-Length: 0");
                                        batchElement.AppendLine();
                                    }

                                    payload.Append(batchElement.ToString());
                                }

                                payload.AppendLine("--" + boundary + "--");

                                string payloadText = payload.ToString();
                                Trace.WriteLine("Payload text:");
                                Trace.WriteLine(payloadText);
                                request.SetRequestStreamAsText(payloadText);

                                // Build a payload.
                                Exception exception = TestUtil.RunCatching(request.SendRequest);
                                TestUtil.AssertExceptionExpected(exception,
                                                                 maxBatchCount < 0,
                                                                 maxChangeSetCount < 0);
                                if (exception == null)
                                {
                                    string text = request.GetResponseStreamAsText();
                                    if (maxBatchCount < batchCount ||
                                        (batchCount > 0 && maxChangeSetCount < changeSetCount))
                                    {
                                        TestUtil.AssertContains(text, "error");
                                    }
                                    else
                                    {
                                        TestUtil.AssertContainsFalse(text, "error");
                                    }
                                }
                            }
                });
            }
Exemplo n.º 30
0
        public void EncodingFromAcceptCharsetTest()
        {
            // It takes over a minute to run all combinations.
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("EncodingData", EncodingData.Values),
                new Dimension("StringData", StringData.Values),
                new Dimension("SerializationFormatData", SerializationFormatData.StructuredValues),
                new Dimension("WebServerLocation", new object[] { WebServerLocation.InProcess }));

            engine.Mode = CombinatorialEngineMode.EveryElement;

            TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable table)
            {
                EncodingData encodingData      = (EncodingData)table["EncodingData"];
                StringData stringData          = (StringData)table["StringData"];
                WebServerLocation location     = (WebServerLocation)table["WebServerLocation"];
                SerializationFormatData format = (SerializationFormatData)table["SerializationFormatData"];

                if (encodingData.Encoding == null)
                {
                    return;
                }

                if (!EncodingHandlesString(encodingData.Encoding, "<>#&;\r\n"))
                {
                    return;
                }

                // Transliteration of ISCII characters and Unicode is possible, but round-tripping from
                // Unicode will not work because all phonetic sounds share an ISCII value, but have
                // distinct Unicode points depending on the language.
                if (encodingData.Name.StartsWith("x-iscii") && stringData.TextScript != null && stringData.TextScript.SupportsIscii)
                {
                    return;
                }

                using (CustomDataContext.CreateChangeScope())
                    using (TestWebRequest request = TestWebRequest.CreateForLocation(location))
                    {
                        request.DataServiceType    = typeof(CustomDataContext);
                        request.HttpMethod         = "POST";
                        request.RequestUriString   = "/Customers";
                        request.RequestContentType = UnitTestsUtil.JsonLightMimeType;
                        request.SetRequestStreamAsText("{ " +
                                                       "@odata.type : \"AstoriaUnitTests.Stubs.Customer\" ," +
                                                       "ID: 100," +
                                                       "Name: " +
                                                       System.Data.Test.Astoria.Util.JsonPrimitiveTypesUtil.PrimitiveToString(stringData.Value, typeof(string)) +
                                                       " }");
                        request.SendRequest();

                        request.HttpMethod       = "GET";
                        request.AcceptCharset    = encodingData.Name;
                        request.Accept           = format.MimeTypes[0];
                        request.RequestUriString = "/Customers(100)";

                        bool encoderCanHandleData = EncodingHandlesString(encodingData.Encoding, stringData.Value);
                        Trace.WriteLine("Encoding handles string: " + encoderCanHandleData);

                        Exception exception = TestUtil.RunCatching(request.SendRequest);

                        XmlDocument document = null;
                        Stream byteStream    = new MemoryStream();
                        if (exception == null)
                        {
                            using (Stream stream = request.GetResponseStream())
                            {
                                IOUtil.CopyStream(stream, byteStream);
                            }

                            byteStream.Position = 0;
                            Trace.WriteLine(TestUtil.BuildHexDump(byteStream));
                            byteStream.Position = 0;

                            if (format == SerializationFormatData.Atom)
                            {
                                document = new XmlDocument(TestUtil.TestNameTable);
                                using (StreamReader reader = new StreamReader(byteStream, encodingData.Encoding))
                                {
                                    document.Load(reader);
                                }

                                TestUtil.TraceXml(document);

                                XmlElement nameElement = TestUtil.AssertSelectSingleElement(document, "//ads:Name");
                                if (stringData.Value == null)
                                {
                                    Assert.IsTrue(UnitTestsUtil.HasElementNullValue(nameElement,
                                                                                    new System.Net.Mime.ContentType(request.ResponseContentType).MediaType));
                                }
                                else
                                {
                                    Assert.AreEqual(stringData.Value, nameElement.InnerText);
                                }
                            }
                        }
                        else
                        {
                            TestUtil.AssertExceptionExpected(exception, !encoderCanHandleData);
                        }
                    }
            });
        }
Exemplo n.º 31
0
        protected override void RunCommand(IEnumerable <string> args)
        {
            List <string> argsList = args.ToList();

            if (showCommandHelp(argsList))
            {
                return;
            }

            string clusterDirectory = argsList[0];
            string outputDirectory  = argsList[1];

            ArkDataManager.LoadData(GlobalOptions.Language);

            List <Action> tasks = GlobalOptions.Parallel ? new List <Action>() : null;

            Stopwatch stopwatch = new Stopwatch(GlobalOptions.UseStopWatch);

            foreach (string path in Directory.EnumerateFiles(clusterDirectory))
            {
                Action task = () => {
                    try {
                        ArkCloudInventory cloudInventory = new ArkCloudInventory().ReadBinary <ArkCloudInventory>(path, ReadingOptions.Create());

                        CustomDataContext context = new CustomDataContext {
                            ObjectContainer = cloudInventory
                        };

                        IPropertyContainer arkData = cloudInventory.InventoryData.GetPropertyValue <IPropertyContainer>("MyArkData");

                        CommonFunctions.WriteJson(Path.Combine(outputDirectory, path + ".json"), (generator, writingOptions) => {
                            generator.WriteStartObject();

                            ArkArrayStruct tamedDinosData = arkData.GetPropertyValue <ArkArrayStruct>("ArkTamedDinosData");
                            if (tamedDinosData != null && tamedDinosData.Any())
                            {
                                generator.WriteArrayFieldStart("creatures");
                                foreach (IStruct dinoStruct in tamedDinosData)
                                {
                                    IPropertyContainer dino = (IPropertyContainer)dinoStruct;
                                    ArkContainer container  = null;
                                    if (cloudInventory.InventoryVersion == 1)
                                    {
                                        ArkArrayUInt8 byteData = dino.GetPropertyValue <ArkArrayUInt8>("DinoData");

                                        container = new ArkContainer(byteData);
                                    }
                                    else if (cloudInventory.InventoryVersion == 3)
                                    {
                                        ArkArrayInt8 byteData = dino.GetPropertyValue <ArkArrayInt8>("DinoData");

                                        container = new ArkContainer(byteData);
                                    }

                                    ObjectReference dinoClass = dino.GetPropertyValue <ObjectReference>("DinoClass");
                                    // Skip "BlueprintGeneratedClass " = 24 chars
                                    string dinoClassName = dinoClass.ObjectString.ToString().Substring(24);
                                    generator.WriteStartObject();

                                    generator.WriteField("type",
                                                         ArkDataManager.HasCreatureByPath(dinoClassName) ? ArkDataManager.GetCreatureByPath(dinoClassName).Name : dinoClassName);

                                    // NPE for unknown versions
                                    Creature creature = new Creature(container.Objects[0], container);
                                    generator.WriteObjectFieldStart("data");
                                    creature.writeAllProperties(generator, context, writeAllFields);
                                    generator.WriteEndObject();

                                    generator.WriteEndObject();
                                }

                                generator.WriteEndArray();
                            }

                            ArkArrayStruct arkItems = arkData.GetPropertyValue <ArkArrayStruct>("ArkItems");
                            if (arkItems != null)
                            {
                                List <Item> items = new List <Item>();
                                foreach (IStruct itemStruct in arkItems)
                                {
                                    IPropertyContainer item    = (IPropertyContainer)itemStruct;
                                    IPropertyContainer netItem = item.GetPropertyValue <IPropertyContainer>("ArkTributeItem");

                                    items.Add(new Item(netItem));
                                }

                                if (items.Any())
                                {
                                    generator.WritePropertyName("items");
                                    Inventory.writeInventoryLong(generator, context, items, writeAllFields);
                                }
                            }

                            generator.WriteEndObject();
                        }, writingOptions);
                    } catch (Exception ex) {
                        Console.Error.WriteLine("Found potentially corrupt cluster data: " + path);
                        if (GlobalOptions.Verbose)
                        {
                            Console.Error.WriteLine(ex.Message);
                            Console.Error.WriteLine(ex.StackTrace);
                        }
                    }
                };

                if (tasks != null)
                {
                    tasks.Add(task);
                }
                else
                {
                    task();
                }
            }

            if (tasks != null)
            {
                Parallel.ForEach(tasks, task => task());
            }

            stopwatch.Stop("Loading cluster data and writing info");
            stopwatch.Print();
        }
Exemplo n.º 32
0
            private void GetResponseWithETagFromReflectionBasedProvider(string uri, string responseFormat, string[] xPathsToVerify, bool verifyETagScenarios, bool nullValueExpected)
            {
                CustomDataContext.ClearData();
                using (CustomDataContext.CreateChangeScope())
                {
                    Type   contextType = typeof(CustomDataContext);
                    string etag        = null;

                    if (verifyETagScenarios)
                    {
                        etag = GetETagFromResponse(contextType, uri, responseFormat);
                        Assert.IsTrue(!String.IsNullOrEmpty(etag), "!String.IsNullOrEmpty(etag)");

                        var ifMatch = new KeyValuePair <string, string>("If-Match", etag);
                        GetResponse(uri, responseFormat, contextType, xPathsToVerify, new KeyValuePair <string, string>[] { ifMatch });

                        VerifyStatusCode(uri, responseFormat, etag, contextType, (int)HttpStatusCode.NotModified);

                        ifMatch = new KeyValuePair <string, string>("If-Match", "W/\"sdfsdffweljrwerjwekr\"");
                        VerifyInvalidRequest(contextType, responseFormat, uri, (int)HttpStatusCode.PreconditionFailed, new KeyValuePair <string, string>[] { ifMatch });

                        var ifNoneMatch = new KeyValuePair <string, string>("If-None-Match", "W/\"sdfsdffweljrwerjwekr\"");
                        GetResponse(uri, responseFormat, typeof(CustomDataContext), xPathsToVerify, new KeyValuePair <string, string>[] { ifNoneMatch });


                        // for non-null values, * should behave as if there was no if-match header.
                        // for null values, it should return 412
                        ifMatch = new KeyValuePair <string, string>("If-Match", "*");
                        GetResponse(uri, responseFormat, contextType, xPathsToVerify, new KeyValuePair <string, string>[] { ifMatch });

                        ifNoneMatch = new KeyValuePair <string, string>("If-None-Match", "*");
                        VerifyStatusCode(uri, responseFormat, "*", contextType, (int)HttpStatusCode.NotModified);
                    }
                    else
                    {
                        // check and make sure the etag header is null
                        etag = GetETagFromResponse(contextType, uri, responseFormat);
                        Assert.IsTrue(String.IsNullOrEmpty(etag), "String.IsNullOrEmpty(etag)");

                        int errorCode = (int)HttpStatusCode.BadRequest;
                        if (nullValueExpected)
                        {
                            errorCode = (int)HttpStatusCode.PreconditionFailed;
                        }

                        var ifMatch = new KeyValuePair <string, string>("If-Match", "W/\"" + new Guid().ToString() + "\"");
                        VerifyInvalidRequest(contextType, responseFormat, uri, errorCode, new KeyValuePair <string, string>[] { ifMatch });

                        var ifNoneMatch = new KeyValuePair <string, string>("If-None-Match", "W/\"" + new Guid().ToString() + "\"");
                        GetResponse(uri, responseFormat, typeof(CustomDataContext), xPathsToVerify, new KeyValuePair <string, string>[] { ifNoneMatch });

                        if (nullValueExpected)
                        {
                            ifMatch = new KeyValuePair <string, string>("If-Match", "*");
                            VerifyInvalidRequest(contextType, responseFormat, uri, (int)HttpStatusCode.PreconditionFailed, new KeyValuePair <string, string>[] { ifMatch });

                            VerifyStatusCode(uri, responseFormat, "*", contextType, (int)HttpStatusCode.NoContent);
                        }
                    }
                }
            }
Exemplo n.º 33
0
        public void IncomingMessagePropertiesTest()
        {
            var testCases = new[]
            {
                new
                {
                    ExpectFailure             = false,
                    ErrorCode                 = 0,
                    IncomingMessageProperties = new Dictionary <string, object>()
                    {
                        { "MicrosoftDataServicesRequestUri", new Uri("http://mappedhost/mappedService.svc/Customers", UriKind.Absolute) },
                        { "MicrosoftDataServicesRootUri", new Uri("http://mappedhost/mappedService.svc/", UriKind.Absolute) }
                    }
                },
                new
                {
                    ExpectFailure             = true,
                    ErrorCode                 = 500,
                    IncomingMessageProperties = new Dictionary <string, object>()
                    {
                        { "MicrosoftDataServicesRequestUri", "http://mappedhost/mappedService.svc/Customers" },
                    }
                },
                new
                {
                    ExpectFailure             = true,
                    ErrorCode                 = 500,
                    IncomingMessageProperties = new Dictionary <string, object>()
                    {
                        { "MicrosoftDataServicesRootUri", "http://mappedhost/mappedService.svc/" }
                    }
                },
                new
                {
                    ExpectFailure             = true,
                    ErrorCode                 = 400,
                    IncomingMessageProperties = new Dictionary <string, object>()
                    {
                        { "MicrosoftDataServicesRequestUri", new Uri("http://mappedhost/mappedService.svc/Customers", UriKind.Absolute) },
                    }
                },
                new
                {
                    ExpectFailure             = true,
                    ErrorCode                 = 400,
                    IncomingMessageProperties = new Dictionary <string, object>()
                    {
                        { "MicrosoftDataServicesRootUri", new Uri("http://mappedhost/mappedService.svc/", UriKind.Absolute) }
                    }
                }
            };

            foreach (var testCase in testCases)
            {
                using (CustomDataContext.CreateChangeScope())
                    using (TestWebRequest request = TestWebRequest.CreateForInProcessWcf())
                    {
                        OpenWebDataServiceHelper.ForceVerboseErrors = true;

                        request.DataServiceType  = typeof(CustomDataContext);
                        request.HttpMethod       = "GET";
                        request.RequestUriString = "/Customers?$format=atom";

                        ((InProcessWcfWebRequest)request).IncomingMessageProperties = testCase.IncomingMessageProperties;

                        Exception e = TestUtil.RunCatching(request.SendRequest);
                        TestUtil.AssertExceptionExpected(e, testCase.ExpectFailure);
                        if (e == null)
                        {
                            XDocument response   = request.GetResponseStreamAsXDocument();
                            var       idElements = response.Descendants(UnitTestsUtil.AtomNamespace + "feed").Descendants(UnitTestsUtil.AtomNamespace + "id");
                            foreach (var id in idElements)
                            {
                                TestUtil.AssertContains(id.Value, ((Uri)((InProcessWcfWebRequest)request).IncomingMessageProperties["MicrosoftDataServicesRequestUri"]).AbsoluteUri);
                            }
                        }
                        else
                        {
                            TestUtil.AssertExceptionStatusCode(e, testCase.ErrorCode, null);
                        }
                    }
            }
        }