public void OpenTypeIncorrectPropertyNameTest() { string[] invalidNames = new string[] { null, "", " ", "1", "@for", //"a.", "a;", "a`", "a,", //"a-", "a+", "a\'", "a[", "a]", "a ", " a", }; using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { foreach (string name in invalidNames) { using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.Properties[name] = 1; args.Values.Add(o); })) { request.DataServiceType = typeof(OpenTypeContextWithReflection <OpenElement>); request.Accept = "application/atom+xml,application/xml"; request.RequestUriString = "/Values"; Exception exception = TestUtil.RunCatching(request.SendRequest); TestUtil.AssertExceptionExpected(exception, true); } } } }
public void OpenTypeBasicTest() { CombinatorialEngine engine = CombinatorialEngine.FromDimensions( new Dimension("TypeData", TypeData.Values)); using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(OpenTypeContextWithReflection <OpenElement>); request.RequestUriString = "/Values"; TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values) { TypeData data = (TypeData)values["TypeData"]; foreach (object sampleValue in data.SampleValues) { using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.Properties.Add("sampleValue", sampleValue); args.Values.Add(o); })) { Exception exception = TestUtil.RunCatching(request.SendRequest); // If we choose to throw when an open property is, say, IntPtr, use this: // Also check for null, since when the value is null, there is no way to know the datatype of the property TestUtil.AssertExceptionExpected(exception, !data.IsTypeSupported && sampleValue != null); } } }); } }
public void OpenTypeOrderByTest() { string[][] queries = new string[][] { new string[] { "/Values?$orderby=sampleValue1", "abc", "ABC" }, new string[] { "/Values?$orderby=sampleValue1 desc", "ABC", "abc" }, new string[] { "/Values?$orderby=sampleValue1,sampleValue2", "abc", "ABC" }, new string[] { "/Values('101')/sampleValue4()?$orderby=ID", "101", "102" }, }; using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(OpenTypeContextWithReflection <OpenElement>); using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.ID = "101"; o.Properties.Add("sampleValue1", "abc"); o.Properties.Add("sampleValue2", 12345); o.Properties.Add("sampleValue3", true); args.Values.Add(o); o = new OpenElement(); o.Properties.Add("sampleValue1", "ABC"); o.Properties.Add("sampleValue2", 1); o.Properties.Add("sampleValue3", false); args.Values.Add(o); })) { int i = 0; foreach (string[] queryParts in queries) { string query = queryParts[0]; Trace.WriteLine("Running " + query); request.RequestUriString = query; Exception exception = TestUtil.RunCatching(request.SendRequest); TestUtil.AssertExceptionExpected(exception, i == queries.Length - 1); if (exception == null) { string response = request.GetResponseStreamAsText(); int firstOffset = response.IndexOf(queryParts[1]); int secondOffset = response.IndexOf(queryParts[2]); if (firstOffset >= secondOffset) { Assert.Fail( "For '" + query + "' the offset for " + queryParts[1] + " (" + firstOffset + ") should be less than " + "the offset for " + queryParts[2] + " (" + secondOffset + ") in '" + response + "'"); } } i++; } } } }
public void OpenTypeUrlTest() { string[] queries = new string[] { "/Values", "/Values('100')/sampleValue2", "/Values('100')/sampleValue4", // no () after sample value 4, it's an array, gets rejected "/Values('100')/notfound", // This should be bad query since we expect to return 404 for open-properties not found }; string[] badQueries = new string[] { "/Values/sampleValue1", // no () after Values "/Values('100')/sampleValue4()", "/Values('100')/sampleValue4('101')", "/Values('100')/sampleValue4('101')/ID", "/Values('100')/sampleValue4(101)", // Since we don't detect types during runtime, this queries will fail "/Values('100')/sampleValue3/Identity/Name", "/Values('100')/sampleValue3/Identity", }; using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(OpenTypeContextWithReflection <OpenElement>); int i = 0; using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.ID = "100"; o.Properties.Add("sampleValue1", "abc"); o.Properties.Add("sampleValue2", 12345); args.Values.Add(o); })) { foreach (string query in queries) { i++; Trace.WriteLine(query); request.RequestUriString = query; request.SendRequest(); Trace.WriteLine(request.GetResponseStreamAsText()); } foreach (string query in badQueries) { i++; Trace.WriteLine(query); request.RequestUriString = query; Exception exception = TestUtil.RunCatching(request.SendRequest); TestUtil.AssertExceptionExpected(exception, true); } } } }
public void RequestQueryRecursionLimitReached() { using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.Properties["Foo"] = null; args.Values.Add(o); })) { request.DataServiceType = typeof(OpenTypeContextWithReflection <OpenElement>); request.RequestUriString = "/Values?$filter=length(length(length(length(length(length(length(length(length(length(length(length(length(length(length(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((Foo))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) gt 5"; Exception exception = TestUtil.RunCatching(request.SendRequest); Assert.IsTrue(exception != null, "Exception must be thrown"); Assert.IsTrue(exception.InnerException.Message.Contains("Recursion")); } } }
public void OpenTypeGetOpenPropertyValuesWithNull() { using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { using (TestUtil.RestoreStaticValueOnDispose(typeof(OpenTypeContextWithReflectionConfig), "NullOnGetOpenPropertyValues")) using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.Properties["Foo"] = 1; args.Values.Add(o); })) { OpenTypeContextWithReflectionConfig.NullOnGetOpenPropertyValues = true; request.DataServiceType = typeof(OpenTypeContextWithReflection <OpenElement>); request.RequestUriString = "/Values"; Exception exception = TestUtil.RunCatching(request.SendRequest); Assert.IsTrue(exception == null, "GetOpenPropertyValues should handle null as an empty collection."); } } }
private void MessageArrivedCallback(object sender, MqttMsgPublishEventArgs e) { if (e.Topic == "/i5/hololens/instructions") { UnityMainThreadDispatcher.Instance().Enqueue(() => { TextMesh t = (TextMesh)GetComponent(typeof(TextMesh)); t.text = System.Text.Encoding.UTF8.GetString(e.Message); }); } else if (e.Topic == "/i5/hololens/car/ldoor") { UnityMainThreadDispatcher.Instance().Enqueue(() => { OpenElement t = (OpenElement)GetComponent(typeof(OpenElement)); if (System.Text.Encoding.UTF8.GetString(e.Message) == "open") { t.Opening.SetInteger("EtatAnim", 1); } else { t.Opening.SetInteger("EtatAnim", 2); } }); } else if (e.Topic == "/i5/hololens/car/rdoor") { UnityMainThreadDispatcher.Instance().Enqueue(() => { OpenElement t = (OpenElement)GetComponent(typeof(OpenElement)); if (System.Text.Encoding.UTF8.GetString(e.Message) == "open") { t.Opening.SetInteger("EtatAnim", 1); } else { t.Opening.SetInteger("EtatAnim", 2); } }); } }
public void OpenTypeJsonWithNulls() { using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.Properties["Foo"] = null; args.Values.Add(o); })) { request.DataServiceType = typeof(OpenTypeContextWithReflection <OpenElement>); request.RequestUriString = "/Values"; request.Accept = UnitTestsUtil.JsonLightMimeType; Exception exception = TestUtil.RunCatching(request.SendRequest); String response = request.GetResponseStreamAsText(); Assert.AreEqual(exception, null); Assert.IsTrue(response.Contains("\"Foo\":null")); } } }
public void ChangeValues(OpenElement entity, UpdateOperations operation) { OpenChangeInterceptorServiceState.InterceptorFired = true; }
// TODO: enable this once we have support for expanding open properties //[TestMethod] public void OpenTypeExpandTest() { CombinatorialEngine engine = CombinatorialEngine.FromDimensions( new Dimension("SerializationFormatData", SerializationFormatData.StructuredValues)); using (TestWebRequest request = TestWebRequest.CreateForInProcess()) { request.DataServiceType = typeof(TypedCustomDataContext <OpenElement>); using (StaticCallbackManager <PopulatingValuesEventArgs <OpenElement> > .RegisterStatic((sender, args) => { var o = new OpenElement(); o.ID = "100"; o.Properties.Add("sampleValue1", new OpenElement() { ID = "101" }); o.Properties.Add("sampleValue2", new OpenElement[] { new OpenElement() { ID = "102" } }); o.Properties.Add("address", new Address() { StreetAddress = "L1", City = "City", State = "S1", PostalCode = "98052" }); o.Properties.Add("primitive", "abc"); o.Properties.Add("thenull", null); args.Values.Add(o); })) { TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values) { SerializationFormatData format = (SerializationFormatData)values["SerializationFormatData"]; request.Accept = format.MimeTypes[0]; XmlDocument document; string[] validation; request.RequestUriString = "/Values('100')"; request.SendRequest(); document = format.LoadXmlDocumentFromStream(request.GetResponseStream()); if (format == SerializationFormatData.Atom) { validation = new string[] { "/atom:entry/atom:link[@title='OpenTypes_OpenElement']", "/atom:entry/atom:content/adsm:properties/ads:ID[text()='100']", "/atom:entry/atom:link[@title='sampleValue1' and @type='application/atom+xml;type=entry']", "/atom:entry/atom:link[@title='sampleValue2' and @type='application/atom+xml;type=feed']", //"/atom:entry/atom:content/ads:address/ads:Line1[text()='L1']", //"/atom:entry/atom:content/ads:address/ads:Line2[@adsm:null='true']", "/atom:entry/atom:content/adsm:properties/ads:primitive[text()='abc']" }; } else { Debug.Assert(format == SerializationFormatData.Json); validation = new string[] { "/Object/__metadata/type[text()='AstoriaUnitTests.Tests.OpenTypes_OpenElement']", "/Object/ID[text()='100']", "/Object/sampleValue1/__deferred", "/Object/sampleValue2/__deferred", //"/Object/address/Line1[text()='L1']", //"/Object/address/Line2[@IsNull='true']", "/Object/primitive[text()='abc']" }; } TestUtil.TraceXml(document); foreach (string v in validation) { TestUtil.AssertSelectSingleElement(document, v); } request.RequestUriString = "/Values('100')?$expand=sampleValue1"; request.SendRequest(); document = format.LoadXmlDocumentFromStream(request.GetResponseStream()); TestUtil.TraceXml(document); if (format == SerializationFormatData.Atom) { TestUtil.AssertSelectSingleElement( document, "/atom:entry/atom:link[@title='sampleValue1']/*/atom:entry/atom:content/adsm:properties/ads:ID[text()='101']"); } else { TestUtil.AssertSelectSingleElement( document, "/Object/sampleValue1/__metadata/type[text()='AstoriaUnitTests.Tests.OpenTypes_OpenElement']"); } request.RequestUriString = "/Values('100')?$expand=sampleValue2"; request.SendRequest(); document = format.LoadXmlDocumentFromStream(request.GetResponseStream()); TestUtil.TraceXml(document); if (format == SerializationFormatData.Atom) { TestUtil.AssertSelectSingleElement( document, "/atom:entry/atom:link[@title='sampleValue2']/*/atom:feed/atom:entry/atom:content/adsm:properties/ads:ID[text()='102']"); } else { TestUtil.AssertSelectSingleElement( document, "/Object/sampleValue2/Array/Object/__metadata/type[text()='AstoriaUnitTests.Tests.OpenTypes_OpenElement']"); } }); } } }