Ejemplo n.º 1
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.º 2
0
        public async Task UpdateObjectTagAsyncTest()
        {
            string tagToRemove = "one";
            string tagPersist  = "two";
            string tagToAdd    = "three";

            // Create the object
            dynamic obj = new APObject("object");
            decimal pi  = 22.0m / 7.0m;

            obj.intfield     = 1;
            obj.decimalfield = pi;

            //Add tag
            obj.AddTag(tagToRemove);
            obj.AddTag(tagPersist);

            var saved = await ObjectHelper.CreateNewAsync(obj as APObject);

            // Get the newly created object
            var afterFirstUpdate = await APObjects.GetAsync("object", saved.Id);

            Assert.IsNotNull(afterFirstUpdate);
            Assert.IsTrue(afterFirstUpdate.Tags.Count(tag => string.Equals(tag, tagPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Tags.Count(tag => string.Equals(tag, tagToRemove, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Tags.Count() == 2);

            //Add/Remove tag
            afterFirstUpdate.RemoveTag(tagToRemove);
            afterFirstUpdate.AddTag(tagToAdd);
            await afterFirstUpdate.SaveAsync();

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

            Assert.IsTrue(afterSecondUpdate.Tags.Count(tag => string.Equals(tag, tagToRemove, StringComparison.OrdinalIgnoreCase)) == 0);
            Assert.IsTrue(afterSecondUpdate.Tags.Count(tag => string.Equals(tag, tagToAdd, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Tags.Count() == 2);

            //Cleanup
            await APObjects.DeleteAsync(afterSecondUpdate.Type, afterSecondUpdate.Id);
        }
Ejemplo n.º 3
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.º 4
0
        public async Task UpdateObjectTagAsyncTest()
        {
            string tagToRemove = "one";
            string tagPersist = "two";
            string tagToAdd = "three";

            // Create the object
            dynamic obj = new APObject("object");
            decimal pi = 22.0m / 7.0m;
            obj.intfield = 1;
            obj.decimalfield = pi;

            //Add tag
            obj.AddTag(tagToRemove);
            obj.AddTag(tagPersist);

            var saved = await ObjectHelper.CreateNewAsync(obj as APObject);

            // Get the newly created object
            var afterFirstUpdate = await APObjects.GetAsync("object", saved.Id);
            Assert.IsNotNull(afterFirstUpdate);
            Assert.IsTrue(afterFirstUpdate.Tags.Count(tag => string.Equals(tag, tagPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Tags.Count(tag => string.Equals(tag, tagToRemove, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Tags.Count() == 2);

            //Add/Remove tag
            afterFirstUpdate.RemoveTag(tagToRemove);
            afterFirstUpdate.AddTag(tagToAdd);
            await afterFirstUpdate.SaveAsync();

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

            Assert.IsTrue(afterSecondUpdate.Tags.Count(tag => string.Equals(tag, tagToRemove, StringComparison.OrdinalIgnoreCase)) == 0);
            Assert.IsTrue(afterSecondUpdate.Tags.Count(tag => string.Equals(tag, tagToAdd, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Tags.Count() == 2);

            //Cleanup
            await APObjects.DeleteAsync(afterSecondUpdate.Type, afterSecondUpdate.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);
        }