Пример #1
0
        public async Task DeleteObjectAsyncTest()
        {
            // Create apObject
            var     now = DateTime.Now;
            dynamic obj = new APObject("object");

            obj.intfield      = 1;
            obj.decimalfield  = 10.0m;
            obj.datefield     = "2012-12-20";
            obj.datetimefield = now.ToString("o");
            obj.stringfield   = "string value";
            obj.textfield     = "text value";
            obj.boolfield     = false;
            obj.geofield      = "11.5,12.5";
            obj.listfield     = "a";
            obj.SetAttribute("attr1", "value1");
            obj.SetAttribute("attr2", "value2");

            CreateObjectResponse response = null;

            response = await(new CreateObjectRequest()
            {
                Object = obj
            }).ExecuteAsync();
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Status);
            Assert.IsTrue(response.Status.IsSuccessful);
            Assert.IsNotNull(response.Object);
            Console.WriteLine("Created apObject id {0}", response.Object.Id);
            Console.WriteLine("Time taken: {0} seconds", response.TimeTaken);

            // Delete the apObject
            var deleteObjectResponse = await(new DeleteObjectRequest()
            {
                Id   = response.Object.Id,
                Type = response.Object.Type
            }).ExecuteAsync();

            Assert.IsNotNull(deleteObjectResponse, "Delete apObjectr response is null.");
            Assert.IsTrue(deleteObjectResponse.Status.IsSuccessful == true,
                          deleteObjectResponse.Status.Message ?? "Delete apObject operation failed.");

            // Try get the deleted apObject
            var getObjectResponse = await(
                new GetObjectRequest()
            {
                Id   = response.Object.Id,
                Type = response.Object.Type
            }).ExecuteAsync();

            Assert.IsNotNull(getObjectResponse, "Get apObject response is null.");
            Assert.IsNull(getObjectResponse.Object, "Should not be able to get a deleted apObject.");
            Assert.IsTrue(getObjectResponse.Status.Code == "404", "Error code expected was not 404.");
        }
        public async Task DeleteObjectAsyncTest()
        {
            // Create apObject
            var now = DateTime.Now;
            dynamic obj = new APObject("object");
            obj.intfield = 1;
            obj.decimalfield = 10.0m;
            obj.datefield = "2012-12-20";
            obj.datetimefield = now.ToString("o");
            obj.stringfield = "string value";
            obj.textfield = "text value";
            obj.boolfield = false;
            obj.geofield = "11.5,12.5";
            obj.listfield = "a";
            obj.SetAttribute("attr1", "value1");
            obj.SetAttribute("attr2", "value2");

            CreateObjectResponse response = null;
            response = await (new CreateObjectRequest()
                {
                    Object = obj
                }).ExecuteAsync();
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Status);
            Assert.IsTrue(response.Status.IsSuccessful);
            Assert.IsNotNull(response.Object);
            Console.WriteLine("Created apObject id {0}", response.Object.Id);
            Console.WriteLine("Time taken: {0} seconds", response.TimeTaken);

            // Delete the apObject
            var deleteObjectResponse = await (new DeleteObjectRequest()
                {
                    Id = response.Object.Id,
                    Type = response.Object.Type
                }).ExecuteAsync();
            Assert.IsNotNull(deleteObjectResponse, "Delete apObjectr response is null.");
            Assert.IsTrue(deleteObjectResponse.Status.IsSuccessful == true,
                          deleteObjectResponse.Status.Message ?? "Delete apObject operation failed.");

            // Try get the deleted apObject
            var getObjectResponse = await (
                new GetObjectRequest()
                    {
                        Id = response.Object.Id,
                        Type = response.Object.Type
                    }).ExecuteAsync();
            Assert.IsNotNull(getObjectResponse, "Get apObject response is null.");
            Assert.IsNull(getObjectResponse.Object, "Should not be able to get a deleted apObject.");
            Assert.IsTrue(getObjectResponse.Status.Code == "404", "Error code expected was not 404.");

        }
Пример #3
0
 public static APObject NewInstance()
 {
     Console.WriteLine("Creating new apObject instance without saving");
     var now = DateTime.Now;
     dynamic obj = new APObject("object");
     obj.intfield = 1;
     obj.decimalfield = 10.0m;
     obj.datefield = "2012-12-20";
     obj.datetimefield = now.ToString("o");
     obj.stringfield = "string value";
     obj.textfield = "text value";
     obj.boolfield = false;
     obj.geofield = "11.5,12.5";
     obj.listfield = "a";
     obj.SetAttribute("attr1", "value1");
     obj.SetAttribute("attr2", "value2");
     return obj as APObject;
 }
Пример #4
0
        public static APObject NewInstance()
        {
            Console.WriteLine("Creating new apObject instance without saving");
            var     now = DateTime.Now;
            dynamic obj = new APObject("object");

            obj.intfield      = 1;
            obj.decimalfield  = 10.0m;
            obj.datefield     = "2012-12-20";
            obj.datetimefield = now.ToString("o");
            obj.stringfield   = "string value";
            obj.textfield     = "text value";
            obj.boolfield     = false;
            obj.geofield      = "11.5,12.5";
            obj.listfield     = "a";
            obj.SetAttribute("attr1", "value1");
            obj.SetAttribute("attr2", "value2");
            return(obj as APObject);
        }
Пример #5
0
        public async Task UpdateObjectAttributeAsyncTest()
        {
            string attrToRemove = "one";
            string attrPersist  = "two";
            string attrToAdd    = "three";

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

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

            //Add Attributes
            obj.SetAttribute(attrToRemove, attrToRemove);
            obj.SetAttribute(attrPersist, attrPersist);

            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.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToRemove, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Attributes.Count() == 2);

            //Add/Remove Attribute
            afterFirstUpdate.RemoveAttribute(attrToRemove);
            afterFirstUpdate.SetAttribute(attrToAdd, attrToAdd);
            await afterFirstUpdate.SaveAsync();

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

            Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToAdd, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Attributes.Count() == 2);

            //Cleanup
            await APObjects.DeleteAsync(afterSecondUpdate.Type, afterSecondUpdate.Id);
        }
Пример #6
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);
        }
        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);
        }
Пример #8
0
        public async Task UpdateObjectAttributeAsyncTest()
        {
            string attrToRemove = "one";
            string attrPersist = "two";
            string attrToAdd = "three";

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

            //Add Attributes
            obj.SetAttribute(attrToRemove, attrToRemove);
            obj.SetAttribute(attrPersist, attrPersist);

            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.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToRemove, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Attributes.Count() == 2);

            //Add/Remove Attribute
            afterFirstUpdate.RemoveAttribute(attrToRemove);
            afterFirstUpdate.SetAttribute(attrToAdd, attrToAdd);
            await afterFirstUpdate.SaveAsync();

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

            Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToAdd, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Attributes.Count() == 2);

            //Cleanup
            await APObjects.DeleteAsync(afterSecondUpdate.Type, afterSecondUpdate.Id);
        }