public void RequestUriProcessorKeySpecialRealTest() { double[] doubleValues = new double[] { double.PositiveInfinity, double.NegativeInfinity, double.NaN }; string[] findText = new string[] { "INF", "-INF", "NaN" }; int textIndex = 0; // Index corresponds to the findText array CombinatorialEngine engine = CombinatorialEngine.FromDimensions( new Dimension("doubleValue", doubleValues)); using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(TypedCustomDataContext <TypedEntity <double, string> >); TypedCustomDataContext <TypedEntity <double, string> > .ClearHandlers(); TypedCustomDataContext <TypedEntity <double, string> > .ClearValues(); TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values) { double doubleValue = (double)values["doubleValue"]; TypedCustomDataContext <TypedEntity <double, string> > .ValuesRequested += (sender, args) => { TypedCustomDataContext <TypedEntity <double, string> > s = (TypedCustomDataContext <TypedEntity <double, string> >)sender; TypedEntity <double, string> entity = new TypedEntity <double, string>(); entity.ID = doubleValue; s.SetValues(new object[] { entity }); }; try { Assert.IsTrue(textIndex < 3, "Out of bounds for test data array. Please check the doubleValues variable."); string searchValue = findText[textIndex]; // Increment textIndex for next test case ++textIndex; request.RequestUriString = "/Values"; request.Accept = "application/json"; request.SendRequest(); string responseText = request.GetResponseStreamAsText(); Assert.IsTrue(responseText.IndexOf(searchValue) > 0, String.Format("ID \"{0}\" expected in response.", searchValue)); Trace.WriteLine(String.Format("Found ID: {0}", searchValue)); // Finish the test suite after we've ran through all the strings. If we continue, the test suite continues and fails. // Researching into that is a expensive at this time. if (textIndex == 3) { return; } } finally { TypedCustomDataContext <TypedEntity <double, string> > .ClearHandlers(); TypedCustomDataContext <TypedEntity <double, string> > .ClearValues(); } }); } }
public void RequestUriProcessorKeySpecialRealTest() { double[] doubleValues = new double[] { double.PositiveInfinity, double.NegativeInfinity, double.NaN }; CombinatorialEngine engine = CombinatorialEngine.FromDimensions( new Dimension("doubleValue", doubleValues)); using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(TypedCustomDataContext <TypedEntity <double, string> >); TypedCustomDataContext <TypedEntity <double, string> > .ClearHandlers(); TypedCustomDataContext <TypedEntity <double, string> > .ClearValues(); TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values) { double doubleValue = (double)values["doubleValue"]; TypedCustomDataContext <TypedEntity <double, string> > .ValuesRequested += (sender, args) => { TypedCustomDataContext <TypedEntity <double, string> > s = (TypedCustomDataContext <TypedEntity <double, string> >)sender; TypedEntity <double, string> entity = new TypedEntity <double, string>(); entity.ID = doubleValue; s.SetValues(new object[] { entity }); }; try { request.RequestUriString = "/Values"; request.Accept = "application/atom+xml,application/xml"; request.SendRequest(); XmlDocument document = request.GetResponseStreamAsXmlDocument(); XmlElement element = TestUtil.AssertSelectSingleElement(document, "/atom:feed/atom:entry/atom:id"); Trace.WriteLine("Found ID: " + element.InnerText); request.FullRequestUriString = element.InnerText; Exception exception = TestUtil.RunCatching(request.SendRequest); // One NaN value won't match another except throug the use of the .IsNaN // method. It's probably OK to not support this. TestUtil.AssertExceptionExpected(exception, double.IsNaN(doubleValue)); string responseText = request.GetResponseStreamAsText(); Trace.WriteLine(responseText); } finally { TypedCustomDataContext <TypedEntity <double, string> > .ClearHandlers(); TypedCustomDataContext <TypedEntity <double, string> > .ClearValues(); } }); } }
[Ignore] // Remove Atom // [TestMethod] public void RequestQueryParserReproTests() { using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(TypedCustomDataContext <AllTypes>); string[] filters = new string[] { // Protocol: Can't compare decimal value to literal greater than maxint "DecimalType eq 100000000000000000000000M", // Protocol: Can't use large Decimal in filter expression "79228162514264337593543950335M gt 0", // Protocol: Filter does not match large float values "DoubleType eq 3.4E%2B38", //(double)(3.4E+38f) will be 3.3999999521443642E+38 // Protocol: filter can't compare two byte properties "ByteType eq ByteType", "NullableByteType eq NullableByteType", "ByteType eq (1 add 1 sub 2)", // Protocol: contains in filter expression can not find single extended char "null ne StringType and contains(StringType,'\x00A9 \x0040')", "null ne StringType and contains(StringType,'\x00A9')" }; TypedCustomDataContext <AllTypes> .ClearValues(); TypedCustomDataContext <AllTypes> .ValuesRequested += (sender, y) => { AllTypes[] values = new AllTypes[] { new AllTypes() { ID = 1, DecimalType = 100000000000000000000000m }, new AllTypes() { ID = 2, DoubleType = 3.4E+38 }, new AllTypes() { ID = 3, StringType = "\x00A9 \x0040" }, }; TypedCustomDataContext <AllTypes> c = (TypedCustomDataContext <AllTypes>)sender; c.SetValues(values); }; foreach (string filter in filters) { request.RequestUriString = "/Values?$format=atom&$filter=" + filter; Trace.WriteLine("Sending request for " + request.RequestUriString); Exception exception = TestUtil.RunCatching(request.SendRequest); TestUtil.AssertExceptionExpected(exception, false); XmlDocument document = request.GetResponseStreamAsXmlDocument(); TestUtil.AssertSelectNodes(document, "/atom:feed/atom:entry"); } } }
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)')])"); } } }