private void GetResponse(string uri, string responseFormat, Type contextType, string[] xPathsToVerify, KeyValuePair <string, string>[] headerValues, string httpMethodName, string requestPayload) { using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = contextType; request.RequestUriString = uri; request.Accept = responseFormat; request.HttpMethod = httpMethodName; UnitTestsUtil.SetHeaderValues(request, headerValues); if (requestPayload != null) { request.RequestContentType = responseFormat; request.RequestStream = new MemoryStream(); StreamWriter writer = new StreamWriter(request.RequestStream); writer.Write(requestPayload); writer.Flush(); } request.SendRequest(); Stream responseStream = request.GetResponseStream(); if (xPathsToVerify != null) { UnitTestsUtil.VerifyXPaths(responseStream, responseFormat, xPathsToVerify); } } }
public void ExpressionHookTest() { // This is just a constant expression with the resultant array var q = ExpressionTreeTestUtils.CreateRequestAndGetQueryable(typeof(CustomDataContext), "/Customers").Expression; Assert.AreEqual(q.NodeType, ExpressionType.Constant); // this is a call to IQueryable.Where q = ExpressionTreeTestUtils.CreateRequestAndGetQueryable(typeof(CustomDataContext), "/Customers?$filter=ID eq 0").Expression; Assert.AreEqual(q.NodeType, ExpressionType.Call); XmlDocument xDoc = ExpressionTreeTestUtils.CreateRequestAndGetExpressionTreeXml(typeof(CustomDataContext), "/Customers?$filter=ID eq 0"); UnitTestsUtil.VerifyXPaths(xDoc, "/Call[Method='Where']", "/Call/Arguments/Constant[position()=1]"); using (TestUtil.RestoreStaticValueOnDispose(typeof(ExpressionTreeToXmlSerializer), "UseFullyQualifiedTypeNames")) { xDoc = ExpressionTreeTestUtils.CreateRequestAndGetExpressionTreeXml(typeof(CustomDataContext), "/Customers?$filter=isof('AstoriaUnitTests.Stubs.Customer')"); UnitTestsUtil.VerifyXPaths(xDoc, "/Call/Arguments/Quote/Lambda/Body/TypeIs[TypeOperand='Customer']"); ExpressionTreeToXmlSerializer.UseFullyQualifiedTypeNames = true; xDoc = ExpressionTreeTestUtils.CreateRequestAndGetExpressionTreeXml(typeof(CustomDataContext), "/Customers?$filter=isof('AstoriaUnitTests.Stubs.Customer')"); UnitTestsUtil.VerifyXPaths(xDoc, "/Call/Arguments/Quote/Lambda/Body/TypeIs[TypeOperand='AstoriaUnitTests.Stubs.Customer']"); } }
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()); }); } }
public void GeometryAsOpenProperty_AtomWithTypeDeserialize() { // tests atom deserialization with m:type information var testCases = testData.Select(kvp => new { Type = SpatialTestUtil.GeometryTypeFor(kvp.Key), EdmName = SpatialTestUtil.GeometryEdmNameFor(kvp.Key), WktData = kvp.Value }); TestUtil.RunCombinations(testCases, (tcase) => { using (TestWebRequest request = CreateSpatialPropertyService(new Geometry[tcase.WktData.Length], tcase.Type, true, true).CreateForInProcessWcf()) { request.RequestUriString = "/Entities"; request.HttpMethod = "POST"; request.Accept = "application/atom+xml,application/xml"; request.RequestContentType = UnitTestsUtil.AtomFormat; request.SetRequestStreamAsText(AggregateAtomPayloadFromWkt(tcase.Type.Name, tcase.WktData, tcase.EdmName)); request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); string rootXpath = "atom:entry/atom:content/adsm:properties/ads:" + tcase.Type.Name; UnitTestsUtil.VerifyXPaths(response, tcase.WktData.Select((v, i) => rootXpath + i + "[@adsm:type = '" + tcase.EdmName + "' and namespace-uri(*) = 'http://www.opengis.net/gml']").ToArray()); } }); }
private static void ResponseShouldMatchXPath(string requestUriString, bool openType, int statusCode, string xpath) { ResponseShouldHaveStatusCode(requestUriString, openType, statusCode, request => { var responsePayload = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(responsePayload, new[] { xpath }); }); }
private static void GetResponseAndVerify(TestWebRequest request, int expectedStatusCode, string xpath) { TestUtil.RunCatching(request.SendRequest); Assert.AreEqual(expectedStatusCode, request.ResponseStatusCode); var responsePayload = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(responsePayload, new[] { xpath }); }
private static void ResponseShouldMatchXPath(string requestUriString, int statusCode, string xpath, Type serviceType = null) { ResponseShouldHaveStatusCode( requestUriString, statusCode, request => { var responsePayload = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(responsePayload, new[] { xpath }); }, serviceType); }
private static void ResponseShouldContainEntities(string requestUriString, params string[] expectedEditLinks) { RunGetRequest( requestUriString, request => { Assert.AreEqual(200, request.ResponseStatusCode); var responsePayload = request.GetResponseStreamAsXDocument(); const string xpath = "//atom:entry/atom:link[@rel='edit' and @href=\"{0}\"]"; var xpaths = expectedEditLinks.Select(e => string.Format(xpath, e)).Concat(new[] { "count(//atom:entry)=" + expectedEditLinks.Length }).ToArray(); UnitTestsUtil.VerifyXPaths(responsePayload, xpaths); }); }
public void GeometryCollection_Deserialize() { StringBuilder payload = new StringBuilder(); payload.Append("{ \"__metadata\":{ \"uri\": \"http://host/Entities(0)\" }, \"ID\": 0"); foreach (var kvp in testData) { payload.AppendLine(","); payload.Append(JsonCollectionPropertyFromWkt(SpatialTestUtil.GeometryTypeFor(kvp.Key).Name, kvp.Value, SpatialTestUtil.GeometryEdmNameFor(kvp.Key))); } payload.AppendLine("}"); var svc = CreateCollectionWriteService(testData.Keys.Select(t => SpatialTestUtil.GeometryTypeFor(t)).ToList()); using (TestWebRequest request = svc.CreateForInProcess()) { System.Data.Test.Astoria.TestUtil.RunCombinations(UnitTestsUtil.ResponseFormats, (format) => { request.RequestUriString = "/Entities"; request.HttpMethod = "POST"; request.Accept = "application/atom+xml,application/xml"; request.RequestContentType = format; if (format == UnitTestsUtil.JsonLightMimeType) { request.SetRequestStreamAsText(payload.ToString()); } else { var xDoc = JsonValidator.ConvertToXDocument(payload.ToString()); var atomPayload = UnitTestsUtil.Json2AtomXLinq(xDoc, true).ToString(); request.SetRequestStreamAsText(atomPayload); } request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(response, testData.Select(d => String.Format("count(atom:entry/atom:content/adsm:properties/ads:Collection{0}/adsm:element) = {1}", SpatialTestUtil.GeometryTypeFor(d.Key).Name, d.Value.Length)).ToArray()); }); } }
public void RequestUriResourceSetPropertyTest() { Func <Hashtable, XmlDocument, bool> testCallBack = (values, document) => { string responseFormat = (string)values["ResponseFormat"]; string xPath; if (responseFormat == UnitTestsUtil.JsonLightMimeType) { xPath = String.Format("/{0}/{1}/ID", JsonValidator.ArrayString, JsonValidator.ObjectString); } else { Assert.IsTrue(responseFormat == UnitTestsUtil.AtomFormat, "unexpected format"); xPath = "/atom:feed/atom:entry/atom:content/adsm:properties/ads:ID"; } XmlElement order = (XmlElement)document.SelectSingleNode(xPath, TestUtil.TestNamespaceManager); using (TestWebRequest request = TestWebRequest.CreateForLocation(WebServerLocation.InProcess)) { request.RequestUriString = "/Customers(0)/Orders(" + order.InnerText + ")"; request.Accept = responseFormat; request.DataServiceType = typeof(CustomDataContext); request.SendRequest(); UnitTestsUtil.VerifyXPaths(request.GetResponseStream(), responseFormat, new string[] { "/cdc:Order" }, new string[] { JsonValidator.GetJsonTypeXPath(typeof(Order), false /*isArray*/) }, new string[0]); return(true); } }; UnitTestsUtil.VerifyPayload("/Customers(0)/Orders", typeof(CustomDataContext), testCallBack, new string[] { "/cdc:Orders", "/cdc:Orders/cdc:Order" }, new string[] { String.Format("/{0}", JsonValidator.ArrayString), JsonValidator.GetJsonTypeXPath(typeof(Order), true /*isArray*/) }, new string[0]); // TODO: When this is fixed, we should uncomment this test cases //UnitTestsUtil.VerifyInvalidUri("/Customers!1000/Orders", typeof(CustomDataContext)); UnitTestsUtil.VerifyInvalidUri("/Customers(1)/Orders(10000)", typeof(CustomDataContext)); }
[Ignore] // test case issue, request uri and service root in this case is null. public void RequestQueryParserTestFilterTest() { var service = new OpenWebDataService <CustomDataContext>(); service.AttachHost(new TestServiceHost2()); CustomDataContext context = ServiceModelData.InitializeAndGetContext(service); Prov.ResourceType customerType = GetResourceTypeForContainer(service, "Customers"); object customerSet = GetResourceSetWrapper(service, "Customers"); IQueryable result = InvokeWhere(service, GetRequestDescription(customerType, customerSet, "Customers"), context.Customers, "ID eq 5"); XmlDocument document = CreateDocumentFromIQueryable(result); Trace.WriteLine(document.InnerXml); UnitTestsUtil.VerifyXPaths(document, "/Source//*[@NodeType='Lambda']", "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']", "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']/*[@NodeType='Constant' and @Value='5']", "/Source//*[@NodeType='Lambda']/Body[@Type='System.Boolean']/*[@NodeType='MemberAccess' and contains(@Member, 'ID')]"); }
public void 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 GeometryAsOpenProperty_Deserialize() { var testCases = testData.Select(kvp => new { Type = SpatialTestUtil.GeometryTypeFor(kvp.Key), EdmName = SpatialTestUtil.GeometryEdmNameFor(kvp.Key), Data = new Geometry[kvp.Value.Length], Payload = AggregateJsonPayloadFromWkt(SpatialTestUtil.GeometryTypeFor(kvp.Key).Name, kvp.Value, SpatialTestUtil.GeometryEdmNameFor(kvp.Key)) }); TestUtil.RunCombinations(testCases, UnitTestsUtil.ResponseFormats, (tcase, format) => { using (TestWebRequest request = CreateSpatialPropertyService(tcase.Data, tcase.Type, true, true).CreateForInProcessWcf()) { request.RequestUriString = "/Entities"; request.HttpMethod = "POST"; request.Accept = "application/atom+xml,application/xml"; request.RequestContentType = format; if (format == UnitTestsUtil.JsonLightMimeType) { request.SetRequestStreamAsText(tcase.Payload); } else { // atom from Json - this payload has no m:type var xDoc = JsonValidator.ConvertToXDocument(tcase.Payload.ToString()); var atomPayload = UnitTestsUtil.Json2AtomXLinq(xDoc, true).ToString(); request.SetRequestStreamAsText(atomPayload); } request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); string rootXpath = "atom:entry/atom:content/adsm:properties/ads:" + tcase.Type.Name; string[] xpaths = tcase.Data.Select((v, i) => rootXpath + i + "[@adsm:type = '" + tcase.EdmName + "' and namespace-uri(*) = 'http://www.opengis.net/gml']").ToArray(); UnitTestsUtil.VerifyXPaths(response, xpaths); } }); }
public void DataServiceHostServiceRootUriTest() { // Edit link "../Product(1)" incorrectly produced when base uri is http://service.svc using IDSH // Make sure service root URIs always end in '/' when using an IDataServiceHost/IDataServiceHost2 // // Verifies that the service root URI for a IDSH is always terminated in a '/' // NOTE: if the service URI would not be properly terminated in a '/', the created edit link in the resulting // entry would be incorrect. Uri[] uris = new Uri[] { new Uri("http://host"), new Uri("http://host/a/b"), new Uri("http://host/a/b.svc"), new Uri("http://host/a/b/c.svc") }; TestUtil.RunCombinations(uris, (uri) => { TestServiceHost host = new TestServiceHost(uri) { RequestAccept = "application/atom+xml", RequestPathInfo = "/Customers(0)", }; DataService <CustomDataContext> context = new OpenWebDataService <CustomDataContext>(); context.AttachHost(host); Exception exception = TestUtil.RunCatching(delegate() { context.ProcessRequest(); }); XmlDocument document = new XmlDocument(TestUtil.TestNameTable); host.ResponseStream.Seek(0, SeekOrigin.Begin); document.Load(host.ResponseStream); UnitTestsUtil.VerifyXPaths(document, "/atom:entry/atom:link[@rel='edit' and @href='Customers(0)']"); TestUtil.AssertExceptionExpected(exception, false); }); }
public void FilterNavigationWithAnyAll() { ocs.PopulateData.EntityConnection = null; using (OpenWebDataServiceHelper.AcceptAnyAllRequests.Restore()) using (System.Data.EntityClient.EntityConnection connection = ocs.PopulateData.CreateTableAndPopulateData()) { OpenWebDataServiceHelper.AcceptAnyAllRequests.Value = true; Type[] types = new Type[] { typeof(ocs.CustomObjectContext), typeof(CustomDataContext), typeof(CustomRowBasedContext) }; var testCases = new[] { new { filters = new string[] { "Orders/any() eq false", "Orders/any() and ID eq 100", "Orders/any(o: o/ID eq 500)", "Orders/any(o: o/ID eq 100 and o/$(Customer)/ID ne 0)", "Orders/any(o: isof(o/$(Customer),'$(CustomerWithBirthDayType)') and o/$(Customer)/ID ne 1)", "Orders/all(o: o/$(Customer)/ID eq 1 and $it/ID ne 1)", "Orders/all(o: o/ID eq 100)", "Orders/all(o: o/ID eq $it/ID)", "Orders/all(o: o/$(Customer)/Orders/any() eq false)", "Orders/all(o: $it/ID eq 1 and o/$(Customer)/Orders/any(o1: o1/ID eq 500))", "Orders/all(o: isof(o/$(Customer),'$(CustomerWithBirthDayType)') and o/$(Customer)/ID ne 1)", }, xpaths = new string[] { "count(//atom:entry)=0" } }, new { filters = new string[] { "Orders/any()", "Orders/any() and ID lt 100", "ID lt 100 and Orders/any()", "Orders/all(o: o/$(Customer)/Orders/any())", }, xpaths = new string[] { "count(//atom:entry)=3" } }, new { filters = new string[] { "Orders/any() and (ID eq 1)", "Orders/any() and isof('$(CustomerWithBirthDayType)')", "Orders/any(o: $it/ID eq 1)", "Orders/any(o: o/$(Customer)/ID eq 1)", "Orders/any(o: isof(o/$(Customer), '$(CustomerWithBirthDayType)'))", "Orders/all(o: $it/ID eq 1)", "Orders/all(o: o/$(Customer)/ID eq 1)", "Orders/all(o: isof(o/$(Customer), '$(CustomerWithBirthDayType)'))", // using the same range variable name in multiple not-nested predicates "Orders/any(o: o/$(Customer)/ID eq 1) and Orders/all(o: o/$(Customer)/ID eq 1)", // nested queries "Orders/any(o: o/$(Customer)/Orders/any(o1: o1/$(Customer)/Orders/all(o2: o2/$(Customer)/ID eq 1)) or $it/ID eq 1)", "Orders/all(o: $it/ID eq 1 and o/$(Customer)/Orders/all(o1: o1/$(Customer)/Orders/any(o2: o2/$(Customer)/ID eq 1)))", // keywords "Orders/any(event: event/$(Customer)/ID eq 1)", "Orders/any(while: while/$(Customer)/ID eq 1)", }, xpaths = new string[] { "count(//atom:entry)=1", "boolean(//atom:entry/atom:category[contains(@term,'CustomerWithBirthday')])" } } }; TestUtil.RunCombinations(types, (type) => { using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = type; request.StartService(); TestUtil.RunCombinations(testCases, (testCase) => { foreach (var str in testCase.filters) { string filter = UnitTestsUtil.ProcessStringVariables(str, (variable) => { if (type == typeof(ocs.CustomObjectContext)) { switch (variable) { case "Customer": return("Customers"); case "CustomerWithBirthDayType": return("AstoriaUnitTests.ObjectContextStubs.Types.CustomerWithBirthday"); } } else if (type == typeof(CustomDataContext)) { switch (variable) { case "CustomerWithBirthDayType": return("AstoriaUnitTests.Stubs.CustomerWithBirthday"); } } else if (type == typeof(CustomRowBasedContext)) { switch (variable) { case "CustomerWithBirthDayType": return("AstoriaUnitTests.Stubs.CustomerWithBirthday"); } } return(variable); }); request.RequestUriString = "/Customers?$format=atom&$filter=" + filter; request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(response, testCase.xpaths); } }); } }); } }
[Ignore] // Remove Atom // [TestMethod] public void ChangingFeedCollectionValueForTopLevel() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteEntryStart.Restore()) using (MyODataWriter.WriteFeedStart.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (MyODataWriter.WriteEndDelegate.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return(testODataWriter); }; int CustomerCount = 0; int insideIgnoreCustomer = 0; MyODataWriter.WriteEntryStart.Value = (args) => { if (args.Entry.TypeName.Contains("Customer")) { // Only write the first instance of the customer on the wire CustomerCount++; if (CustomerCount != 1) { insideIgnoreCustomer = 1; return(true); } } return(false); }; MyODataWriter.WriteFeedStart.Value = (args) => { if (args.Feed.Id.OriginalString.Contains("Customers")) { testODataWriter.CallBaseWriteStart(new ODataResourceSet() { Id = args.Feed.Id, Count = 88 }); return(true); } return(false); }; MyODataWriter.WriteLinkStart.Value = (args) => { if (insideIgnoreCustomer > 0) { insideIgnoreCustomer++; return(true); } return(false); }; MyODataWriter.WriteEndDelegate.Value = () => { if (insideIgnoreCustomer > 0) { insideIgnoreCustomer--; return(true); } return(false); }; request.RequestUriString = "/Customers?$format=atom&$inlineCount=allpages"; request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); // verify that the count is 100 // verify that there is one customer written on the wire UnitTestsUtil.VerifyXPaths(response, new string[] { "/atom:feed[adsm:count=88]" }); UnitTestsUtil.VerifyXPathResultCount(response, 1, "/atom:feed/atom:entry"); } }
public void WebDataServiceBaseTypeContainer() { AdHocEntityType customersBase = new AdHocEntityType("CustomerBase"); AdHocEntityType customersDerived = new AdHocEntityType(customersBase) { Name = "CustomerDerived" }; AdHocEntityType referencingType = new AdHocEntityType("ReferencingType"); AdHocEntitySet customerSet = new AdHocEntitySet() { Name = "Customers", Type = customersBase }; AdHocAssociationType associationType = new AdHocAssociationType() { Name = "ReferenceToDerivedCustomerType", Ends = new List <AdHocAssociationTypeEnd>() { new AdHocAssociationTypeEnd() { Multiplicity = "1", RoleName = "Reference", Type = referencingType }, new AdHocAssociationTypeEnd() { Multiplicity = "*", RoleName = "Customer", Type = customersDerived }, } }; AdHocEntitySet referencingSet = new AdHocEntitySet() { Name = "ReferenceHolder", Type = referencingType }; AdHocContainer container = new AdHocContainer() { AssociationSets = new List <AdHocAssociationSet>() { new AdHocAssociationSet() { Name = "ReferenceToDerivedCustomer", Type = associationType, Ends = new List <AdHocAssociationSetEnd>() { new AdHocAssociationSetEnd() { EndType = associationType.Ends[0], EntitySet = referencingSet }, new AdHocAssociationSetEnd() { EndType = associationType.Ends[1], EntitySet = customerSet } }, } }, EntitySets = new List <AdHocEntitySet>() { customerSet, referencingSet }, ExtraEntityTypes = new List <AdHocEntityType>() { customersDerived }, }; associationType.AddNavigationProperties(); AdHocModel model = new AdHocModel(container) { ConceptualNs = TestXmlConstants.EdmV1Namespace }; Assembly assembly = model.GenerateModelsAndAssembly("WebDataServiceBaseTypeContainer", false /* isReflectionProviderBased */); using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = TestUtil.LoadDerivedTypeFromAssembly(assembly, typeof(System.Data.Objects.ObjectContext)); request.RequestUriString = "/$metadata"; request.SendRequest(); using (var s = new StreamReader(request.GetResponseStream())) Trace.WriteLine(s.ReadToEnd()); } using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(ContextWithBaseType); request.RequestUriString = "/$metadata"; request.SendRequest(); XmlDocument document = request.GetResponseStreamAsXmlDocument(); UnitTestsUtil.VerifyXPaths(document, "//csdl:Schema/csdl:EntityType[@Name='WebDataServiceTest_SimpleBaseType']", "//csdl:Schema/csdl:EntityType[@Name='WebDataServiceTest_ReferencingType']", "//csdl:Schema/csdl:EntityType[@Name='WebDataServiceTest_DerivedType' and @BaseType='AstoriaUnitTests.Tests.WebDataServiceTest_SimpleBaseType']", "//csdl:Schema/csdl:EntityContainer/csdl:EntitySet[@Name='B']", "//csdl:Schema/csdl:EntityContainer/csdl:EntitySet[@Name='R']/csdl:NavigationPropertyBinding[@Path='DerivedReference' and @Target='B']"); } }
public void TestAnyAllWithQueryInterceptor() { using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(CustomDataContextWithQueryInterception); request.StartService(); var testCases = new[] { new{ filter = "Orders/any()", xpaths = new string[] { "count(//atom:entry)=2", "/atom:feed/atom:entry[atom:id='http://host/Customers(1)']", "/atom:feed/atom:entry[atom:id='http://host/Customers(2)']", } }, new{ filter = "BestFriend/Orders/any()", xpaths = new string[] { "count(//atom:entry)=1", "/atom:feed/atom:entry[atom:id='http://host/Customers(2)']", } }, new{ // use the same name for the parameter for the any() and QueryInterceptor filter = "Orders/any(o: o/Customer/ID eq 1)", xpaths = new string[] { "count(//atom:entry)=1", "/atom:feed/atom:entry[atom:id='http://host/Customers(1)']", } }, new{ filter = "Orders/any(o: isof(o/Customer, 'AstoriaUnitTests.Stubs.CustomerWithBirthday'))", xpaths = new string[] { "count(//atom:entry)=1", "/atom:feed/atom:entry[atom:id='http://host/Customers(1)']", } }, new{ filter = "Orders/any(o: o/Customer/ID eq $it/ID)", xpaths = new string[] { "count(//atom:entry)=2", "/atom:feed/atom:entry[atom:id='http://host/Customers(1)']", "/atom:feed/atom:entry[atom:id='http://host/Customers(2)']", } }, new{ // since QueryInterceptor filters Orders for Customer 0, all() returns true even if predicate says it has to be 1. filter = "Orders/all(o: o/Customer/ID eq 1)", xpaths = new string[] { "count(//atom:entry)=2", "/atom:feed/atom:entry[atom:id='http://host/Customers(0)']", "/atom:feed/atom:entry[atom:id='http://host/Customers(1)']", } }, }; TestUtil.RunCombinations(testCases, (testCase) => { request.RequestUriString = "/Customers?$format=atom&$filter=" + testCase.filter; request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(response, testCase.xpaths); }); } }
public void FilterCollectionWithAnyAll() { using (OpenWebDataServiceHelper.AcceptAnyAllRequests.Restore()) using (TestWebRequest request = TestWebRequest.CreateForInProcessWcf()) using (TestUtil.RestoreStaticValueOnDispose(typeof(TypedCustomDataContext <EntityForQuery>), "PreserveChanges")) { OpenWebDataServiceHelper.AcceptAnyAllRequests.Value = true; request.Accept = UnitTestsUtil.AtomFormat; request.DataServiceType = typeof(TypedCustomDataContext <EntityForQuery>); TypedCustomDataContext <EntityForQuery> .ClearHandlers(); TypedCustomDataContext <EntityForQuery> .ClearValues(); TypedCustomDataContext <EntityForQuery> .PreserveChanges = true; TypedCustomDataContext <EntityForQuery> .ValuesRequested += (sender, args) => { TypedCustomDataContext <EntityForQuery> typedContext = (TypedCustomDataContext <EntityForQuery>)sender; typedContext.SetValues(new EntityForQuery[] { new EntityForQuery { ID = 0, CollectionOfInt = new List <int>() { 1, 2, 3 }, CollectionOfString = new List <string>() { "a", "b", "c" }, CollectionOfComplexType = new List <MVComplexType>() }, new EntityForQuery { ID = 1, CollectionOfInt = new List <int>() { 4, 5, 6 }, CollectionOfString = new List <string>() { "d", "e", "f" }, CollectionOfComplexType = new List <MVComplexType>() }, new EntityForQuery { ID = 2, CollectionOfInt = new List <int>() { 7, 8, 9 }, CollectionOfString = new List <string>() { "x", "y", "z" }, CollectionOfComplexType = new List <MVComplexType>() { new MVComplexType { Name = "mvcomplextype", Numbers = new List <int>() { 100, 101 } } } }, }); }; request.StartService(); string[] requestStrings = new string[] { "/Values?$filter=CollectionOfInt/any() and (ID eq 2)", "/Values?$filter=CollectionOfString/any(s: s eq 'y')", "/Values?$filter=CollectionOfInt/any(i: cast(i, 'Edm.Int64') eq 7)", "/Values?$filter=CollectionOfInt/all(i: (i ge 7) and (i le 9))", "/Values?$filter=CollectionOfInt/all(i: isof(i, 'Edm.Int32') and ($it/ID eq 2))", "/Values?$filter=CollectionOfComplexType/any(ct: (ct/Name eq 'mvcomplextype') and ct/Numbers/all(n: (n ge 100) and (ct/Name eq 'mvcomplextype')))" }; foreach (var uri in requestStrings) { request.RequestUriString = uri; request.ForceVerboseErrors = true; Exception e = TestUtil.RunCatching(request.SendRequest); Assert.IsNull(e, "Not expecting exception."); var xdoc = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(xdoc, "count(//atom:entry)=1", "boolean(//atom:entry/atom:id[contains(.,'Values(2)')])"); } } }