Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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.");
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public async Task AtomicCountersWithoutPreInitializationTest()
        {
            var obj = new APObject("object");
            await obj.SaveAsync();

            await obj.IncrementAsync("intfield", 10);

            await obj.DecrementAsync("intfield", 5);

            Assert.AreEqual(5, obj.Get <int>("intfield"));
        }
Ejemplo n.º 7
0
        public async Task AddItemsToMultiValuedFieldAsyncTest()
        {
            var obj = new APObject("object");
            await obj.SaveAsync();

            await obj.AddItemsAsync("multifield", "1", "2", "3");

            var list = obj.GetList <string>("multifield");

            Assert.IsTrue(list.Except(new[] { "1", "2", "3" }).Count() == 0);
        }
        public async Task SaveMultivaluedAsyncTest()
        {
            var array = new[] { 1, 3, 4, 5, 6, 7 };
            var obj = new APObject("object");
            obj.SetList<int>("multifield", array);
            await obj.SaveAsync();

            var saved = await APObjects.GetAsync("object", obj.Id);
            var array2 = saved.GetList<int>("multifield");
            Assert.IsTrue(array.Intersect(array2).Count() == array.Length);
        }
 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);
 }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        public async Task MultiValueObjectTest()
        {
            var obj = new APObject("object");

            obj.SetList <string>("multifield", new[] { "1", "2", "3", "4" });
            await obj.SaveAsync();

            var read = await APObjects.GetAsync("object", obj.Id);

            var value   = read.GetList <string>("multifield");
            var strList = read.GetList <string>("multifield");
            var intList = read.GetList <int>("multifield");
        }
Ejemplo n.º 14
0
        public async Task RemoveItemsFromMultiValuedFieldAsyncTest()
        {
            var obj = new APObject("object");

            obj.SetList("multifield", new int[] { 1, 2, 3 });
            await obj.SaveAsync();

            await obj.RemoveItemsAsync("multifield", "1", "2");

            var list = obj.GetList <string>("multifield");

            Assert.IsTrue(list.Count() == 1);
            Assert.IsTrue(list.Except(new[] { "3" }).Count() == 0);
        }
Ejemplo n.º 15
0
        public async Task AddUniqueItemsToMultiValuedFieldAsyncTest()
        {
            var obj = new APObject("object");

            obj.SetList("multifield", new int[] { 1, 2, 3 });
            await obj.SaveAsync();

            await obj.AddItemsAsync("multifield", true, "1", "2", "3", "4", "5");

            var list = obj.GetList <string>("multifield");

            Assert.IsTrue(list.Count() == 5);
            Assert.IsTrue(list.Except(new[] { "1", "2", "3", "4", "5" }).Count() == 0);
        }
Ejemplo n.º 16
0
        public async Task SaveMultivaluedAsyncTest()
        {
            var array = new[] { 1, 3, 4, 5, 6, 7 };
            var obj   = new APObject("object");

            obj.SetList <int>("multifield", array);
            await obj.SaveAsync();

            var saved = await APObjects.GetAsync("object", obj.Id);

            var array2 = saved.GetList <int>("multifield");

            Assert.IsTrue(array.Intersect(array2).Count() == array.Length);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 public async Task ForceUpdateEmptyShouldUpdateNothingTest()
 {
     var obj = await ObjectHelper.CreateNewAsync();
     var copy = new APObject("object", obj.Id);
     await copy.SaveAsync(forceUpdate: true);
     var existingProperties = obj.Properties.ToList();
     var updateProperties = copy.Properties.ToList();
     
     var existing = existingProperties
                         .Select(x => new KeyValuePair<string, string>(x.Key, x.Value.ToString()))
                         .ToList();
     var updated = updateProperties.Select(x => new KeyValuePair<string, string>(x.Key, x.Value.ToString())).ToList();
     Assert.IsTrue(updated.Count == existing.Count);
 }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        public async Task ForceUpdateEmptyShouldUpdateNothingTest()
        {
            var obj = await ObjectHelper.CreateNewAsync();

            var copy = new APObject("object", obj.Id);
            await copy.SaveAsync(forceUpdate : true);

            var existingProperties = obj.Properties.ToList();
            var updateProperties   = copy.Properties.ToList();

            var existing = existingProperties
                           .Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString()))
                           .ToList();
            var updated = updateProperties.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString())).ToList();

            Assert.IsTrue(updated.Count == existing.Count);
        }
Ejemplo n.º 23
0
        public async Task CreateObjectAsyncTest()
        {
            dynamic obj = new APObject("object");

            obj.intfield     = 1;
            obj.decimalfield = 22m / 7m;
            await obj.SaveAsync();

            var saved = obj as APObject;

            Assert.IsNotNull(saved);
            Assert.IsTrue(string.IsNullOrWhiteSpace(saved.Id) == false);
            Assert.IsTrue(saved.Type == "object");
            Assert.IsTrue(saved.Revision == 1);
            Assert.IsTrue(saved.CreatedAt.Subtract(DateTime.Now).Duration().Seconds < 15);
            Assert.IsTrue(saved.LastUpdatedAt.Subtract(DateTime.Now).Duration().Seconds < 15);
            Console.WriteLine("Created apObject with id {0}.", saved.Id);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        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);
        }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
0
        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);
        }
Ejemplo n.º 31
0
        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 );
        }
Ejemplo n.º 32
0
        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);
        }
Ejemplo n.º 33
0
        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);
        }
Ejemplo n.º 34
0
 public async Task RemoveItemsFromMultiValuedFieldAsyncTest()
 {
     var obj = new APObject("object");
     obj.SetList("multifield", new int[] { 1, 2, 3 });
     await obj.SaveAsync();
     await obj.RemoveItemsAsync("multifield", "1", "2");
     var list = obj.GetList<string>("multifield");
     Assert.IsTrue(list.Count() == 1);
     Assert.IsTrue(list.Except(new[] { "3" }).Count() == 0);
 }
Ejemplo n.º 35
0
        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 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);
        }
Ejemplo n.º 37
0
        public async Task MultiValueObjectTest()
        {
            var obj = new APObject("object");
            obj.SetList<string>("multifield", new[] { "1", "2", "3", "4" });
            await obj.SaveAsync();

            var read = await APObjects.GetAsync("object", obj.Id);
            var value = read.GetList<string>("multifield");
            var strList = read.GetList<string>("multifield");
            var intList = read.GetList<int>("multifield");
        }
Ejemplo n.º 38
0
 public async Task AtomicCountersWithoutPreInitializationTest()
 {
     var obj = new APObject("object");
     await obj.SaveAsync();
     await obj.IncrementAsync("intfield", 10);
     await obj.DecrementAsync("intfield", 5);
     Assert.AreEqual(5, obj.Get<int>("intfield"));
 }
Ejemplo n.º 39
0
 public async Task AddItemsToMultiValuedFieldAsyncTest()
 {
     var obj = new APObject("object");
     await obj.SaveAsync();
     await obj.AddItemsAsync("multifield", "1", "2", "3");
     var list = obj.GetList<string>("multifield");
     Assert.IsTrue(list.Except(new[] { "1", "2", "3" }).Count() == 0);
 }
Ejemplo n.º 40
0
        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);
        }
Ejemplo n.º 41
0
        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);
        }
Ejemplo n.º 42
0
        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);
        }
Ejemplo n.º 43
0
        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);
        }
Ejemplo n.º 44
0
 public async Task CreateObjectAsyncTest()
 {
     dynamic obj = new APObject("object");
     obj.intfield = 1;
     obj.decimalfield = 22m / 7m;
     await obj.SaveAsync();
     var saved = obj as APObject;
     Assert.IsNotNull(saved);
     Assert.IsTrue(string.IsNullOrWhiteSpace(saved.Id) == false);
     Assert.IsTrue(saved.Type == "object");
     Assert.IsTrue(saved.Revision == 1);
     Assert.IsTrue(saved.CreatedAt.Subtract(DateTime.Now).Duration().Seconds < 15);
     Assert.IsTrue(saved.LastUpdatedAt.Subtract(DateTime.Now).Duration().Seconds < 15);
     Console.WriteLine("Created apObject with id {0}.", saved.Id);
 }
Ejemplo n.º 45
0
 public async Task AddUniqueItemsToMultiValuedFieldAsyncTest()
 {
     var obj = new APObject("object");
     obj.SetList("multifield", new int[] { 1, 2, 3 });
     await obj.SaveAsync();
     await obj.AddItemsAsync("multifield", true, "1", "2", "3", "4", "5");
     var list = obj.GetList<string>("multifield");
     Assert.IsTrue(list.Count() == 5);
     Assert.IsTrue(list.Except(new[] { "1", "2", "3", "4", "5" }).Count() == 0);
 }