public async Task ReadAclVerificationTest() { var user = await UserHelper.CreateNewUserAsync(); var obj = await ObjectHelper.CreateNewAsync(); await AppContext.LoginAsync(new UsernamePasswordCredentials(user.Username, user.Password)); try { var read = await APObjects.GetAsync("object", obj.Id, options : new ApiOptions { ApiKey = TestConfiguration.ClientApiKey }); Assert.Fail("Test should have failed as user does not have access on the object."); } catch (AccessDeniedException) { } obj.Acl.AllowUser(user.Id, Access.Read); await obj.SaveAsync(); var read2 = await APObjects.GetAsync("object", obj.Id, options : new ApiOptions { ApiKey = TestConfiguration.ClientApiKey }); Assert.IsNotNull(read2); }
public async Task BulkDeleteObjectAsyncTest() { var a1 = await ObjectHelper.CreateNewAsync(); var a2 = await ObjectHelper.CreateNewAsync(); var a3 = await ObjectHelper.CreateNewAsync(); var a4 = await ObjectHelper.CreateNewAsync(); await APObjects.MultiDeleteAsync(a1.Type, a1.Id, a2.Id, a3.Id, a4.Id); var ids = new[] { a1.Id, a2.Id, a3.Id, a4.Id }; for (int i = 0; i < ids.Length; i++) { try { var copy = await APObjects.GetAsync("object", ids[i]); Assert.Fail("Operation should have faulted since the object has been deleted."); } catch (AppacitiveApiException) { } } }
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 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"); }
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 RefreshAsyncTest() { var obj = await ObjectHelper.CreateNewAsync(); var copy = await APObjects.GetAsync("object", obj.Id); var updatedValue = Unique.String; copy.Set("stringfield", updatedValue); await copy.SaveAsync(); Assert.AreNotEqual(obj.Get <string>("stringfield"), updatedValue); await obj.RefreshAsync(); Assert.AreEqual(obj.Get <string>("stringfield"), updatedValue); }
public async Task DeleteObjectAsyncTest() { // Create the object var saved = await ObjectHelper.CreateNewAsync(); // Delete the object await APObjects.DeleteAsync("object", saved.Id); // Try and get and confirm that the object is deleted. try { var copy = await APObjects.GetAsync("object", saved.Id); Assert.Fail("Operation should have faulted since the object has been deleted."); } catch (AppacitiveApiException) { } }
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 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); }
public async Task UpdateObjectPropertyAsyncTest() { // Create the object dynamic obj = new APObject("object"); decimal pi = 22.0m / 7.0m; obj.intfield = 1; obj.decimalfield = pi; var saved = await ObjectHelper.CreateNewAsync(obj as APObject); // Get the newly created object dynamic copy = await APObjects.GetAsync("object", saved.Id); Assert.IsNotNull(copy); int intfield = copy.intfield; decimal decimalField = copy.decimalfield; Assert.IsTrue(intfield == 1); Assert.IsTrue(Math.Abs(decimalField - pi) < 0.0001m); // Update the object copy.intfield = 2; copy.decimalfield = 30m; copy.stringfield = "Test"; await copy.SaveAsync(); // Get updated copy and verify dynamic updated = await APObjects.GetAsync("object", saved.Id); Assert.IsNotNull(updated); intfield = updated.intfield; decimalField = updated.decimalfield; string stringField = updated.stringfield; Assert.IsTrue(intfield == 2, "intfield not updated."); Assert.IsTrue(decimalField == 30, "decimal field not updated."); Assert.IsTrue(stringField == "Test", "stringfield not updated."); }
public async Task GetObjectAsyncTest() { // Create new object dynamic obj = new APObject("object"); decimal pi = 22.0m / 7.0m; obj.intfield = 1; obj.decimalfield = pi; var saved = await ObjectHelper.CreateNewAsync(obj as APObject); // Get the created object dynamic copy = await APObjects.GetAsync("object", saved.Id); Assert.IsNotNull(copy); int intfield = copy.intfield; decimal decimalField = copy.decimalfield; Assert.IsTrue(intfield == 1); Assert.IsTrue(Math.Abs(decimalField - pi) < 0.0001m); Assert.IsTrue(copy.Type == "object"); Assert.IsTrue(copy.Revision == 1); Assert.IsTrue(copy.CreatedAt.Subtract(DateTime.Now).Duration().Seconds < 15); Assert.IsTrue(copy.LastUpdatedAt.Subtract(DateTime.Now).Duration().Seconds < 15); }