public async Task FindAndDisplayAllObjectsTest() { var waitHandle = new ManualResetEvent(false); // Create the object dynamic obj = new APObject("object"); obj.stringfield = Unique.String; await obj.SaveAsync(); var saved = obj as APObject; Console.WriteLine("Created apObj with id {0}", saved.Id); var index = 1; // Search var objects = await APObjects.FindAllAsync("object", Query.None, null, 1, 100); do { objects.ForEach(a => Console.WriteLine("{0}) {1}", index++, a.Id)); Console.WriteLine("page:{0} pageSize:{1} total: {2}", objects.PageNumber, objects.PageSize, objects.TotalRecords); if (objects.IsLastPage == false) { objects = await objects.NextPageAsync(); } else { break; } } while (true); Console.WriteLine("Finished."); }
public async Task QueryWithTagsMatchOneOrMoreTest() { var tag1 = Unique.String; var tag2 = Unique.String; // Create the test object 1. APObject obj1 = new APObject("object"); obj1.Set <string>("stringfield", Unique.String); obj1.AddTag(tag1); await obj1.SaveAsync(); APObject obj2 = new APObject("object"); obj2.Set <string>("stringfield", Unique.String); obj2.AddTag(tag2); await obj2.SaveAsync(); // Search for the object with tags. var matches = await APObjects.FindAllAsync("object", Query.Tags.MatchOneOrMore(tag1, tag2)); Assert.IsTrue(matches != null); Assert.IsTrue(matches.Count == 2); Assert.IsTrue(matches[0] != null && matches[1] != null); Assert.IsTrue(matches[0].Id == obj1.Id || matches[1].Id == obj1.Id); Assert.IsTrue(matches[0].Id == obj2.Id || matches[1].Id == obj2.Id); }
public async Task FindAllObjectsAsyncWithNestedQueryTest() { // Create the object dynamic apObject = new APObject("object"); apObject.stringfield = Unique.String; apObject.intfield = 10; dynamic obj = await ObjectHelper.CreateNewAsync(apObject as APObject); // Search string stringToSearch = obj.stringfield; var query = Query.And(new[] { Query.Property("stringfield").IsEqualTo(stringToSearch), Query.Property("intfield").IsEqualTo(10) }); // Delay for index propagation on test bench. await Utilities.Delay(1500); var objects = await APObjects.FindAllAsync("object", query); Assert.IsNotNull(objects); Assert.IsTrue(objects.Count == 1); Console.WriteLine("page:{0} pageSize:{1} total: {2}", objects.PageNumber, objects.PageSize, objects.TotalRecords); }
public async Task TypeMappingTest() { Score s1 = new Score { Points = 100 }; s1.Badges.Add("novice"); s1.Badges.Add("alcolyte"); await s1.SaveAsync(); Score s2 = new Score { Points = 100 }; await s2.SaveAsync(); AppContext.Types.MapObjectType <Score>("score"); var saved = await APObjects.GetAsync("score", s1.Id); Assert.IsNotNull(saved); Assert.IsTrue(saved is Score); Assert.IsTrue(((Score)saved).Badges.SequenceEqual(new [] { "novice", "alcolyte" })); var scores = await APObjects.FindAllAsync("score"); foreach (var score in scores) { Assert.IsNotNull(score); Assert.IsTrue(score is Score); } }
public async Task FindNonExistantPageTest() { // Search var objects = await APObjects.FindAllAsync("object", Query.None, null, 10000, 500); Assert.IsNotNull(objects); Console.WriteLine("page:{0} pageSize:{1} total: {2}", objects.PageNumber, objects.PageSize, objects.TotalRecords); }
public async Task GetUsersShouldReturnUserObjectsTest() { var created = await UserHelper.CreateNewUserAsync(); var users = await APObjects.FindAllAsync("user"); Assert.IsFalse(users.Exists(d => d is APUser == false)); }
public async Task GetDevicesShouldReturnDeviceObjectsTest() { var created = await DeviceHelper.CreateNewAsync(); var devices = await APObjects.FindAllAsync("device"); Assert.IsFalse(devices.Exists(d => d is APDevice == false)); }
public async Task FindAllObjectsAsyncTest() { // Create the object var saved = await ObjectHelper.CreateNewAsync(); // Search var objects = await APObjects.FindAllAsync("object"); objects.ForEach(a => Console.WriteLine(a.Id)); Console.WriteLine("page:{0} pageSize:{1} total: {2}", objects.PageNumber, objects.PageSize, objects.TotalRecords); }
public async Task QueryObjectWithSingleQuotedValueTest() { dynamic obj = new APObject("object"); var stringValue = "Pan's Labyrinth" + Unique.String; obj.stringfield = stringValue; await obj.SaveAsync(); PagedList <APObject> result = await APObjects.FindAllAsync("object", Query.Property("stringfield").IsEqualTo(stringValue)); Assert.IsTrue(result.TotalRecords == 1, "Expected single record but multiple records were returned."); Assert.IsTrue(result.Single().Id == obj.Id); }
public async Task FindAllObjectsAsyncWithQueryTest() { // Create the object dynamic apObject = new APObject("object"); apObject.stringfield = Unique.String; dynamic obj = await ObjectHelper.CreateNewAsync(apObject as APObject); // Search string stringToSearch = obj.stringfield; var objects = await APObjects.FindAllAsync("object", Query.Property("stringfield").IsEqualTo(stringToSearch)); Assert.IsNotNull(objects); Assert.IsTrue(objects.Count == 1); Console.WriteLine("page:{0} pageSize:{1} total: {2}", objects.PageNumber, objects.PageSize, objects.TotalRecords); }
public async Task FindAllObjectsAsyncWithSpecialCharacterInQueryTest() { // Create the object dynamic apObject = new APObject("object"); apObject.stringfield = Unique.String + " 129764_TouricoTGS_Museum (tunnels in the city’s cliffs)"; //Unique.String + "&" + "12las@"; dynamic obj = await ObjectHelper.CreateNewAsync(apObject as APObject); // Search string stringToSearch = obj.stringfield; var objects = await APObjects.FindAllAsync("object", Query.Property("stringfield").IsEqualTo(stringToSearch)); Assert.IsNotNull(objects); Assert.IsTrue(objects.Count == 1); Console.WriteLine("page:{0} pageSize:{1} total: {2}", objects.PageNumber, objects.PageSize, objects.TotalRecords); }
public async Task StartsWithAndEndsWithFiltersTest() { var prefix = Unique.String; var suffix = Unique.String; var obj = new APObject("object"); obj.Set <string>("stringfield", prefix + suffix); await obj.SaveAsync(); var found = (await APObjects.FindAllAsync("object", Query.Property("stringfield").StartsWith(prefix))).SingleOrDefault(); Assert.IsTrue(found != null); Assert.IsTrue(found.Id == obj.Id); found = (await APObjects.FindAllAsync("object", Query.Property("stringfield").EndsWith(suffix))).SingleOrDefault(); Assert.IsTrue(found != null); Assert.IsTrue(found.Id == obj.Id); }
public async Task FindObjectByDataTimeField() { var time = DateTime.Now; var obj = ObjectHelper.NewInstance(); obj.Set("datetimefield", time); await obj.SaveAsync(); #if (NET40) await TaskEx.Delay(1000); #else await Task.Delay(1000); #endif var results = await APObjects.FindAllAsync("object", Query.Property("datetimefield").IsGreaterThanEqualTo(time)); Assert.IsTrue(results.Count > 0); Assert.IsTrue(results.Exists(x => x.Id == obj.Id)); }
public async Task RawQueryTest() { var propertyValue = Unique.String; var obj = new APObject("object"); obj.Set <string>("stringfield", propertyValue); await obj.SaveAsync(); var rawQuery = string.Format("*stringfield == '{0}'", propertyValue); // Delay for index propagation on test bench. await Utilities.Delay(1500); var results = await APObjects.FindAllAsync("object", Query.FromRawQuery(rawQuery)); Assert.IsNotNull(results); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results.Single().Id == obj.Id); }
public async Task QueryWithTagsMatchAllTest() { // Create the test object. APObject obj = new APObject("object"); var tags = new string[] { Unique.String, Unique.String }; obj.Set <string>("stringfield", Unique.String); obj.AddTags(tags); await obj.SaveAsync(); // Delay for index propagation on test bench. await Utilities.Delay(1500); // Search for the object with tags. var matches = await APObjects.FindAllAsync("object", Query.Tags.MatchAll(tags)); Assert.IsTrue(matches != null); Assert.IsTrue(matches.Count == 1); Assert.IsTrue(matches[0] != null); Assert.IsTrue(matches[0].Id == obj.Id); }
public async Task ListingWithAclTest() { var obj = await ObjectHelper.CreateNewAsync(); var user = await UserHelper.CreateNewUserAsync(); await AppContext.LoginAsync(new UsernamePasswordCredentials(user.Username, user.Password)); var obj1 = await ObjectHelper.CreateNewAsync(); var obj2 = await ObjectHelper.CreateNewAsync(); await Task.Delay(1500); var list = await APObjects.FindAllAsync("object", options : new ApiOptions { ApiKey = TestConfiguration.ClientApiKey }); Assert.IsTrue(list.Count == 2); Assert.IsTrue(list[0].Id == obj1.Id || list[0].Id == obj2.Id); Assert.IsTrue(list[1].Id == obj1.Id || list[1].Id == obj2.Id); }
public async Task MatchQueryTest() { var propertyValue = Unique.String; var attrValue = Unique.String; var obj = new APObject("object"); obj.Set <string>("stringfield", propertyValue); obj.SetAttribute("test_attribute", attrValue); await obj.SaveAsync(); var propertyQuery = Query.Property("stringfield").FreeTextMatches(propertyValue); var attrQuery = Query.Attribute("test_attribute").FreeTextMatches(attrValue); var result1 = await APObjects.FindAllAsync("object", propertyQuery); var result2 = await APObjects.FindAllAsync("object", attrQuery); Assert.IsNotNull(result1); Assert.IsTrue(result1.Count == 1); Assert.IsNotNull(result2); Assert.IsTrue(result2.Count == 1); Assert.IsTrue(result1.Single().Id == obj.Id); Assert.IsTrue(result2.Single().Id == obj.Id); }