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 FreeTextSearchWithMinusOperatorTest() { var mandatoryToken = Unique.String; var optionalToken = Unique.String; // Create one object with only the mandatory token. var obj1 = new APObject("object"); obj1.Set <string>("stringfield", mandatoryToken); // Create one object with the mandatory token and optional token. var obj2 = new APObject("object"); obj2.Set <string>("stringfield", mandatoryToken + " " + optionalToken); // Create one object with only optional token var obj3 = new APObject("object"); obj3.Set <string>("stringfield", optionalToken); #if NET40 await TaskEx.WhenAll(obj1.SaveAsync(), obj2.SaveAsync(), obj3.SaveAsync()); #else await Task.WhenAll(obj1.SaveAsync(), obj2.SaveAsync(), obj3.SaveAsync()); #endif var results = await APObjects.FreeTextSearchAsync("object", mandatoryToken + " -" + optionalToken); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].Id == obj1.Id); }
public async Task FreeTextSearchWithProximityOperatorTest() { var prefix = Unique.String; var suffix = Unique.String; // Create one object with only the mandatory token. var obj1 = new APObject("object"); obj1.Set <string>("stringfield", prefix + " word1" + " word2" + " word3 " + suffix); // Create one object with the mandatory token and optional token. var obj2 = new APObject("object"); obj2.Set <string>("stringfield", prefix + " word1" + " word2" + " word3" + " word4" + " word5 " + suffix); #if NET40 await TaskEx.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #else await Task.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #endif var results = await APObjects.FreeTextSearchAsync("object", "\"" + prefix + " " + suffix + "\"~4"); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].Id == obj1.Id); }
public async Task FreeTextSearchWithQuestionMarkOperatorTest() { var prefix = Unique.String; var suffix = Unique.String; // Create one object with only the mandatory token. var obj1 = new APObject("object"); obj1.Set <string>("stringfield", prefix + "X" + suffix); // Create one object with the mandatory token and optional token. var obj2 = new APObject("object"); obj2.Set <string>("stringfield", prefix + "Y" + suffix); #if NET40 await TaskEx.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #else await Task.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #endif // Delay for index propagation on test bench. await Utilities.Delay(1500); var results = await APObjects.FreeTextSearchAsync("object", prefix + "?" + suffix); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 2); Assert.IsTrue(results[0].Id == obj1.Id || results[0].Id == obj2.Id); Assert.IsTrue(results[1].Id == obj1.Id || results[1].Id == obj2.Id); }
public void TestGeocodeSet() { var apObject = new APObject("object"); apObject.Set("geofield", new Geocode(80.0m, 81.0m)); var value = apObject.Get <string>("geofield"); Assert.IsTrue(value == "80.0,81.0"); }
public void TestGeocodeGet() { var apObject = new APObject("object"); apObject.Set("geofield", new Geocode(80.0m, 81.0m)); var geo = apObject.Get <Geocode>("geofield"); Assert.IsTrue(geo.ToString() == "80.0,81.0"); }
public async Task FindObjectsWithInQueryTest() { var value = Unique.String; var queryValues = new[] { Unique.String, value, Unique.String, Unique.String }; var obj = new APObject("object"); obj.Set("stringfield", value); obj = await ObjectHelper.CreateNewAsync(obj); var results = await APObjects.FindAllAsync("object", Query.Property("stringfield").IsIn(queryValues), sortOrder: SortOrder.Descending, orderBy: "__id", pageSize: 5); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results.Single().Id == obj.Id); }
public async Task PropertyNotInIntegerTest() { var value = DateTime.UtcNow.Ticks; var obj = new APObject("object"); obj.Set("intfield", value); await obj.SaveAsync(); var objects = await APObjects.FindAllAsync("object", Query.Property("intfield").IsNotIn(new[] { 100L }), orderBy: "__id", sortOrder: SortOrder.Descending, pageSize: 1); Assert.AreEqual(obj.Id, objects.Single().Id); objects = await APObjects.FindAllAsync("object", Query.Property("intfield").IsNotIn(new[] { value }), orderBy: "__id", sortOrder: SortOrder.Descending, pageSize: 1); Assert.AreNotEqual(obj.Id, objects.Single().Id); }
public async Task PropertyNotInStringTest() { var value = Unique.String; var obj = new APObject("object"); obj.Set("stringfield", value); await obj.SaveAsync(); var objects = await APObjects.FindAllAsync("object", Query.Property("stringfield").IsNotIn(new[] { Unique.String }), orderBy: "__id", sortOrder: SortOrder.Descending, pageSize: 1); Assert.AreEqual(obj.Id, objects.Single().Id); objects = await APObjects.FindAllAsync("object", Query.Property("stringfield").IsNotIn(new [] { value }), orderBy: "__id", sortOrder: SortOrder.Descending, pageSize: 1); Assert.AreNotEqual(obj.Id, objects.Single().Id); }
public async Task EntityCreateAndUpdatedDateTimeTest() { var obj = new APObject("object"); obj.Set<string>("stringfield", Unique.String); await obj.SaveAsync(); var createDuration = obj.CreatedAt.Subtract(DateTime.Now).Duration(); Assert.IsTrue(createDuration.Minutes < 2); var updateDuration = obj.LastUpdatedAt.Subtract(DateTime.Now).Duration(); Assert.IsTrue(updateDuration.Minutes < 2); }
public async Task AtomicCountersTest() { var obj = new APObject("object"); obj.Set <int>("intfield", 0); await obj.SaveAsync(); await obj.IncrementAsync("intfield", 10); await obj.DecrementAsync("intfield", 5); Assert.AreEqual(5, obj.Get <int>("intfield")); }
public async Task EntityCreateAndUpdatedDateTimeTest() { var obj = new APObject("object"); obj.Set <string>("stringfield", Unique.String); await obj.SaveAsync(); var createDuration = obj.CreatedAt.Subtract(DateTime.Now).Duration(); Assert.IsTrue(createDuration.Minutes < 2); var updateDuration = obj.LastUpdatedAt.Subtract(DateTime.Now).Duration(); Assert.IsTrue(updateDuration.Minutes < 2); }
public async Task AggregateGetTest() { var objA = new APObject("object"); objA.Set("decimalfield", 100.0m); var root = new APObject("object"); root.Set("decimalfield", 50m); await APConnection .New("sibling") .FromNewObject("object", root) .ToNewObject("object", objA) .SaveAsync(); await Task.Delay(20000); var rootCopy = await APObjects.GetAsync("object", root.Id); Assert.AreEqual(100.0m, rootCopy.GetAggregate("decimal_aggregate")); }
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 EntityDateTimePropertyTest() { var dateTime = DateTime.Now; var obj1 = new APObject("object"); obj1.Set<DateTime>("datetimefield", dateTime); await obj1.SaveAsync(); var obj2 = new APObject("object"); obj2.Set<DateTime>("datetimefield", dateTime.ToUniversalTime()); await obj2.SaveAsync(); var obj1Copy = await APObjects.GetAsync("object", obj1.Id); var obj2Copy = await APObjects.GetAsync("object", obj2.Id); Assert.IsTrue(obj1Copy.Get<DateTime>("datetimefield") == dateTime); Assert.IsTrue(obj2Copy.Get<DateTime>("datetimefield") == dateTime); }
public async Task FreeTextSearchTest() { var value = Unique.String + " " + Unique.String; var obj = new APObject("object"); obj.Set <string>("stringfield", value); await obj.SaveAsync(); // Delay for index propagation on test bench. await Utilities.Delay(1500); var results = await APObjects.FreeTextSearchAsync("object", value); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].Id == obj.Id); }
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 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 EntityDateTimePropertyTest() { var dateTime = DateTime.Now; var obj1 = new APObject("object"); obj1.Set <DateTime>("datetimefield", dateTime); await obj1.SaveAsync(); var obj2 = new APObject("object"); obj2.Set <DateTime>("datetimefield", dateTime.ToUniversalTime()); await obj2.SaveAsync(); var obj1Copy = await APObjects.GetAsync("object", obj1.Id); var obj2Copy = await APObjects.GetAsync("object", obj2.Id); Assert.IsTrue(obj1Copy.Get <DateTime>("datetimefield") == dateTime); Assert.IsTrue(obj2Copy.Get <DateTime>("datetimefield") == dateTime); }
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 void TryGetSetMultiValuedPropertyTest() { var apObject = new APObject("object"); try { apObject.Set <int[]>("field1", new[] { 1, 3, 4, 5, 6 }); Assert.Fail("Multivalue set should not be allowed on Object.Set<T>()."); } catch (ArgumentException) { } try { var values = apObject.Get <int[]>("field1"); Assert.Fail("Multivalue get should not be allowed on Object.Get<T>()."); } catch (ArgumentException) { } }
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); }
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 FindObjectsWithInWithIntegerQueryTest() { var value = Unique.String; long[] queryValues = new long[] { 1,2,3 }; var obj = new APObject("object"); obj.Set("intfield", 1); obj = await ObjectHelper.CreateNewAsync(obj); var results = await APObjects.FindAllAsync("object", Query.Property("intfield").IsIn(queryValues), sortOrder: SortOrder.Descending, orderBy: "__id", pageSize: 5); Assert.IsTrue(results.Exists(x => x.Id == obj.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); }
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 FreeTextSearchWithQuestionMarkOperatorTest() { var prefix = Unique.String; var suffix = Unique.String; // Create one object with only the mandatory token. var obj1 = new APObject("object"); obj1.Set<string>("stringfield", prefix + "X" + suffix); // Create one object with the mandatory token and optional token. var obj2 = new APObject("object"); obj2.Set<string>("stringfield", prefix + "Y" + suffix); #if NET40 await TaskEx.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #else await Task.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #endif // Delay for index propagation on test bench. await Utilities.Delay(1500); var results = await APObjects.FreeTextSearchAsync("object", prefix + "?" + suffix); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 2); Assert.IsTrue(results[0].Id == obj1.Id || results[0].Id == obj2.Id); Assert.IsTrue(results[1].Id == obj1.Id || results[1].Id == obj2.Id); }
public async Task FreeTextSearchWithProximityOperatorTest() { var prefix = Unique.String; var suffix = Unique.String; // Create one object with only the mandatory token. var obj1 = new APObject("object"); obj1.Set<string>("stringfield", prefix + " word1" + " word2" + " word3 " + suffix); // Create one object with the mandatory token and optional token. var obj2 = new APObject("object"); obj2.Set<string>("stringfield", prefix + " word1" + " word2" + " word3" + " word4" + " word5 " + suffix); #if NET40 await TaskEx.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #else await Task.WhenAll(obj1.SaveAsync(), obj2.SaveAsync()); #endif var results = await APObjects.FreeTextSearchAsync("object", "\"" + prefix + " " + suffix + "\"~4"); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].Id == obj1.Id); }
public async Task FreeTextSearchWithMinusOperatorTest() { var mandatoryToken = Unique.String; var optionalToken = Unique.String; // Create one object with only the mandatory token. var obj1 = new APObject("object"); obj1.Set<string>("stringfield", mandatoryToken); // Create one object with the mandatory token and optional token. var obj2 = new APObject("object"); obj2.Set<string>("stringfield", mandatoryToken + " " + optionalToken); // Create one object with only optional token var obj3 = new APObject("object"); obj3.Set<string>("stringfield", optionalToken); #if NET40 await TaskEx.WhenAll(obj1.SaveAsync(), obj2.SaveAsync(), obj3.SaveAsync()); #else await Task.WhenAll(obj1.SaveAsync(), obj2.SaveAsync(), obj3.SaveAsync()); #endif var results = await APObjects.FreeTextSearchAsync("object", mandatoryToken + " -" + optionalToken); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].Id == obj1.Id ); }
public async Task FreeTextSearchTest() { var value = Unique.String + " " + Unique.String; var obj = new APObject("object"); obj.Set<string>("stringfield", value); await obj.SaveAsync(); // Delay for index propagation on test bench. await Utilities.Delay(1500); var results = await APObjects.FreeTextSearchAsync("object", value); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 1); Assert.IsTrue(results[0].Id == obj.Id); }
public async Task FreetextAndQueryWithTagsMatchOneOrMoreTest() { var tag1 = Unique.String; var tag2 = Unique.String; var field1 = Unique.String; var field2 = Unique.String; // Create the test object 1. APObject obj1 = new APObject("object"); obj1.Set<string>("stringfield", field1); obj1.AddTag(tag1); await obj1.SaveAsync(); APObject obj2 = new APObject("object"); obj2.Set<string>("stringfield", field2); obj2.AddTag(tag2); await obj2.SaveAsync(); // Search for the object with tags and freetext as field1. var matches = await APObjects.FindAllAsync("object", field1, Query.Tags.MatchOneOrMore(tag1, tag2)); Assert.IsTrue(matches != null); Assert.IsTrue(matches.Count == 1); Assert.IsTrue(matches[0] != null); Assert.IsTrue(matches[0].Id == obj1.Id); // Search for the object with tag1 and freetext as field2. matches = await APObjects.FindAllAsync("object", field2, Query.Tags.MatchOneOrMore(tag1)); Assert.IsTrue(matches == null || matches.Count == 0); // Search for the object with tag2 and freetext as field2. matches = await APObjects.FindAllAsync("object", field2, Query.Tags.MatchOneOrMore(tag2)); Assert.IsTrue(matches != null); Assert.IsTrue(matches.Count == 1); Assert.IsTrue(matches[0] != null); Assert.IsTrue(matches[0].Id == obj2.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 AtomicCountersTest() { var obj = new APObject("object"); obj.Set<int>("intfield", 0); await obj.SaveAsync(); await obj.IncrementAsync("intfield", 10); await obj.DecrementAsync("intfield", 5); Assert.AreEqual(5, obj.Get<int>("intfield")); }