public void Projections_Batch() { using (TestUtil.MetadataCacheCleaner()) using (ocs.PopulateData.CreateTableAndPopulateData()) using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { TestUtil.RunCombinations( new Type[] { typeof(CustomDataContext), typeof(ocs.CustomObjectContext), typeof(CustomRowBasedContext), typeof(CustomRowBasedOpenTypesContext) }, CustomerSelects.Variations(2), (dataServiceType, selects) => { request.DataServiceType = dataServiceType; BatchWebRequest batchRequest = new BatchWebRequest(); foreach (var select in selects) { InMemoryWebRequest part = new InMemoryWebRequest(); part.Accept = "application/atom+xml,application/xml"; part.RequestUriString = "/Customers?$select=" + select.Select; batchRequest.Parts.Add(part); } batchRequest.SendRequest(request); for (int i = 0; i < selects.Length; i++) { UnitTestsUtil.VerifyXPathExists(UnitTestsUtil.GetResponseAsAtomXLinq(batchRequest.Parts[i]), selects[i].VerificationXPaths); } }); } }
public void GeographyCollection_Serialize() { Dictionary <Type, object> data = new Dictionary <Type, object>(); foreach (var sample in testData) { data.Add(SpatialTestUtil.GeographyTypeFor(sample.Key), sample.Value.Select(wkt => wktFormatter.Read <Geography>(new StringReader(wkt))).ToList()); } using (TestWebRequest request = CreateCollectionReadService(data).CreateForInProcess()) { System.Data.Test.Astoria.TestUtil.RunCombinations(UnitTestsUtil.ResponseFormats, (format) => { var response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/Entities", format); // feed/entry/content/properties/CollectionGeographyPoint[@type = \"Collection(Edm.Point)\"]" UnitTestsUtil.VerifyXPaths(response, testData.Keys.Select(type => String.Format("atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}[@adsm:type = \"#Collection({1})\"]", SpatialTestUtil.GeographyTypeFor(type).Name, SpatialTestUtil.GeographyEdmNameFor(type))).ToArray()); UnitTestsUtil.VerifyXPaths(response, testData.Select(d => String.Format("count(atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}/adsm:element) = {1}", SpatialTestUtil.GeographyTypeFor(d.Key).Name, d.Value.Length)).ToArray()); }); } }
private static XElement GetAtomEntryProperties(TestWebRequest request, string resourceSetName, int id) { request.HttpMethod = "GET"; XDocument response = UnitTestsUtil.GetResponseAsAtomXLinq(request, string.Format("/{0}({1})", resourceSetName, id), "application/atom+xml,application/xml"); XElement entry = response.Root.Element(UnitTestsUtil.AtomNamespace + "content"); Assert.IsNotNull(entry, "Expected the request to produce an ATOM entry."); return(entry.Element(UnitTestsUtil.MetadataNamespace + "properties")); }
private void VerifyEntryIDsAndXPaths(string requestUri, TestWebRequest request, int[] expectedIDs, params string[] xpaths) { var response = UnitTestsUtil.GetResponseAsAtomXLinq(request, requestUri); List <string> ids = response.Root.Elements(UnitTestsUtil.AtomNamespace + "entry").Elements(UnitTestsUtil.AtomNamespace + "id") .Select(e => (string)e).ToList(); Assert.AreEqual(expectedIDs.Length, ids.Count, "The number of returned entries doesn't match."); for (int i = 0; i < expectedIDs.Length; i++) { if (!ids[i].Contains("(" + expectedIDs[i].ToString() + ")")) { Assert.Fail("Entries not reported correctly, \r\nexpected: " + expectedIDs.Select(n => n.ToString()).Concatenate(", ") + "\r\nactual: " + ids.Concatenate(", ") + "\r\n" + response.ToString()); } } UnitTestsUtil.VerifyXPathExists(response, xpaths); }
private static void TestSpatialMetadata(DSPDataProviderKind providerKind) { DSPMetadata metadata = new DSPMetadata("SpatialMetadata", "AstoriaUnitTests.Tests"); // Entity with all types of geography properties KeyValuePair <string, Type>[] geographyProperties = new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("GeographyProperty", typeof(Geography)), new KeyValuePair <string, Type>("PointProperty", typeof(GeographyPoint)), new KeyValuePair <string, Type>("LineStringProperty", typeof(GeographyLineString)), }; string entityTypeName = "AllGeographyTypes"; SpatialTestUtil.AddEntityType(metadata, entityTypeName, geographyProperties, useComplexType: false, useOpenTypes: false); metadata.SetReadOnly(); var service = new DSPUnitTestServiceDefinition(metadata, providerKind, new DSPContext()); using (TestWebRequest request = service.CreateForInProcess()) { request.StartService(); request.HttpMethod = "GET"; XDocument response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/$metadata"); XElement schemaElement = response.Root.Element(UnitTestsUtil.EdmxNamespace + "DataServices").Elements().Single(e => e.Name.LocalName == "Schema"); XNamespace edmNs = schemaElement.Name.Namespace; XElement entityElement = schemaElement.Elements(edmNs + "EntityType").Single(e => (string)e.Attribute("Name") == entityTypeName); foreach (KeyValuePair <string, Type> property in geographyProperties) { XElement propertyElement = entityElement.Elements(edmNs + "Property").Single(e => (string)e.Attribute("Name") == property.Key); // EF provider currently represents all types as Edm.Geography in metadata (property is DbGeography on the entity), otherwise it should reflect the actual type string expectedEdmTypeName = providerKind == DSPDataProviderKind.EF ? "Edm.Geography" : GetExpectedEdmTypeName(property.Value); Assert.AreEqual(expectedEdmTypeName, propertyElement.Attribute("Type").Value, "Wrong property type for property {0},", property.Key); XAttribute attribute = propertyElement.Attributes().Where(a => a.Name == "SRID").Single(); Assert.AreEqual("Variable", attribute.Value); } } }
public void GeographyAsOpenProperty_Serialize() { var testCases = testData.Select(kvp => new { Type = SpatialTestUtil.GeographyTypeFor(kvp.Key), EdmName = SpatialTestUtil.GeographyEdmNameFor(kvp.Key), Data = kvp.Value.Select(wkt => wktFormatter.Read <Geography>(new StringReader(wkt))).ToArray() }); TestUtil.RunCombinations(testCases, UnitTestsUtil.ResponseFormats, (tcase, format) => { using (TestWebRequest request = CreateSpatialPropertyService(tcase.Data, tcase.Type, true).CreateForInProcessWcf()) { var response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/Entities", format); string rootXpath = "atom:feed/atom:entry/atom:content/adsm:properties/ads:" + tcase.Type.Name; UnitTestsUtil.VerifyXPaths(response, tcase.Data.Select((v, i) => rootXpath + i + "[@adsm:type = '" + tcase.EdmName + "' and namespace-uri(*) = 'http://www.opengis.net/gml']").ToArray()); } }); }
public void CheckRelationshipLinks() { using (TestWebRequest request = TestWebRequest.CreateForInProcessWcf()) { request.ServiceType = typeof(RelationshipLinksService); request.StartService(); var requests = new string[] { "/Customers", "/Customers?$expand=Orders", "/Customers?$expand=BestFriend", "/Customers?$expand=Orders,BestFriend", "/Customers(0)", "/Customers(1)?$expand=Orders", "/Customers(1)?$expand=BestFriend", "/Customers(1)?$expand=Orders,BestFriend", "/Customers(1)?$expand=Orders($expand=OrderDetails),BestFriend", "/Customers(1)?$expand=BestFriend($expand=Orders)", "/Customers(1)/BestFriend", "/Customers(1)/BestFriend?$expand=BestFriend", "/Customers(1)/BestFriend?$expand=Orders", "/Customers(1)/BestFriend?$expand=BestFriend($expand=Orders($expand=OrderDetails))", "/Customers(1)/BestFriend?$expand=Orders($expand=OrderDetails)", "/Orders?$expand=OrderDetails,Customer,Customer($expand=BestFriend)", "/Customers?$select=Name", "/Customers?$select=Name,Orders", "/Customers?$select=Name,BestFriend", "/Customers?$select=Name,Orders&$expand=Orders", "/Customers?$select=Name,Orders&$expand=BestFriend", "/Customers(1)?$select=Name", "/Customers(1)?$select=Name,Orders", "/Customers(1)?$select=Name,BestFriend", "/Customers(1)?$select=Name,Orders&$expand=Orders", "/Customers(1)?$select=Name,Orders&$expand=BestFriend", "/Customers(1)?$select=Name&$expand=Orders($select=Customer)", "/Customers(1)?$select=Name&$expand=Orders($select=Customer,OrderDetails)", }; TestUtil.RunCombinations(UnitTestsUtil.ResponseFormats, requests, (format, requestUri) => { XDocument response = UnitTestsUtil.GetResponseAsAtomXLinq(request, requestUri, format); Assert.AreEqual("4.0;", request.ResponseVersion); var entries = response.Descendants(UnitTestsUtil.AtomNamespace + "entry"); foreach (var entry in entries) { var links = entry.Elements(UnitTestsUtil.AtomNamespace + "link"); // for each entry there must be only 1 edit link" var editLinks = (from link in links where link.Attribute("rel").Value == "edit" select link.Attribute("href").Value).ToList(); Assert.IsTrue(editLinks.Count == 1, "for each entry there must be only 1 edit link"); var editLink = editLinks[0]; var navigationLinks = (from link in links where link.Attribute("rel").Value.StartsWith(UnitTestsUtil.NavigationLinkNamespace.NamespaceName) select link).ToDictionary((l) => { return(l.Attribute("title").Value); }); var relationshipLinks = (from link in links where link.Attribute("rel").Value.StartsWith(UnitTestsUtil.RelationshipLinkNamespace.NamespaceName) select link).ToDictionary((l) => { return(l.Attribute("title").Value); }); // for projections, we should only write out property links if it's selected // TODO: fix server relationship links test. // TODO: this is broken because select doesn't contain what it used to... need // TODO: rework this, but its not high priority because its a server test. //int index = requestUri.IndexOf("$select"); //if (index > 0) //{ // string selectClause = requestUri.Substring(index + 8); // index = selectClause.IndexOf("&"); // if (index > 0) // { // selectClause = selectClause.Substring(0, index); // } // var selectedProperties = selectClause.Split(','); // string entryType = entry.Elements(UnitTestsUtil.AtomNamespace + "category").Single().Attribute("term").Value; // if (entryType.Equals("AstoriaUnitTests.Stubs.Customer", StringComparison.Ordinal)) // { // Assert.AreEqual(selectedProperties.Intersect(new string[] { "Orders", "BestFriend" }, StringComparer.Ordinal).Count() * 2, relationshipLinks.Count); // } // else if (entryType.Equals("AstoriaUnitTests.Stubs.Order", StringComparison.Ordinal)) // { // if (selectClause.Contains("Orders/")) // { // Assert.AreEqual(selectedProperties.Intersect(new string[] { "Orders/Customer", "Orders/OrderDetails" }, StringComparer.Ordinal).Count(), relationshipLinks.Count); // } // } //} if (format != UnitTestsUtil.JsonLightMimeType) { // json format does not write out nav links if the 1-1 property is null, atom does. Assert.AreEqual(navigationLinks.Count, relationshipLinks.Count, "there should be equal number of relationship and navigation links"); } foreach (var navigationLink in navigationLinks.Values) { VerifyNavigationLink(navigationLink, editLink); XElement relationshipLink = null; string propertyName = navigationLink.Attribute("title").Value; if (relationshipLinks.TryGetValue(propertyName, out relationshipLink)) { VerifyRelationshipLink(relationshipLink, editLink); } else { Assert.Fail("Relationship link is missing for navigation property: " + propertyName); } } } }); }; }