public async Task TestDelete() { Res = await DS.FindByIdAsync(100); Assert.IsTrue(Res.Success); Res = await DS.DeleteAsync(100); Assert.IsTrue(Res.Success, "Failed to delete an existing dataset."); Res = await DS.DeleteAsync(100); Assert.IsFalse(Res.Success, "Deleting a nonexistant dataset returns a success."); }
public async Task TestFindById() { Res = await DS.FindByIdAsync(100); // Assumed correct from AddTestData Assert.IsTrue(Res.Success, "Object is not returned for correct test data ID."); Res = await DS.FindByIdAsync(-1); Assert.IsFalse(Res.Success, "Object is returned for negative ID."); Res = await DS.FindByIdAsync(5); Assert.IsFalse(Res.Success, "Object is returned for an ID that should not exist."); }
public async Task TestSave() { Res = await DS.FindByIdAsync(ExampleV.Id); Assert.IsFalse(Res.Success, "Object ID is found before saving."); Res = await DS.SaveAsync(ExampleV); Assert.IsTrue(Res.Success, "Error on saving a valid object."); Res = await DS.FindByIdAsync(ExampleV.Id); Assert.IsTrue(Res.Success, "Object ID not found after saving."); Assert.AreEqual(ExampleV, Res.Resource, "Object returned for given ID is not equal to our text object."); Res = await DS.FindByIdAsync(5); Assert.IsFalse(Res.Success, "Object is returned for an ID that should not exist."); Dataset exampleI = new Dataset { Id = 1, Title = "ExampleI", }; Res = await DS.FindByIdAsync(exampleI.Id); Assert.IsFalse(Res.Success, "Invalid Object ID is found before saving."); Res = await DS.SaveAsync(exampleI); Assert.IsFalse(Res.Success, "Success on saving an invalid object."); Res = await DS.FindByIdAsync(exampleI.Id); Assert.IsFalse(Res.Success, "Object is returned for an ID that should not exist."); }
public async Task TestUpdate() { Res = await DS.FindByIdAsync(5); Assert.IsFalse(Res.Success); Res = await DS.UpdateAsync(5, ExampleV); Assert.IsFalse(Res.Success, "Success on updating an ID that should not exist."); Res = await DS.FindByIdAsync(100); Assert.IsTrue(Res.Success); Dataset exampleA = Res.Resource; // Should use clone() var exampleAImg = DatasetSnapshot(exampleA); // DatasetSnapshot is not a good function, and should be replaced by clone and equals in Dataset Res = await DS.UpdateAsync(100, ExampleV); Assert.IsTrue(Res.Success, "Failed to update an existing ID with a new valid state."); Dataset exampleB = Res.Resource; var exampleBImg = DatasetSnapshot(exampleB); /* TODO: Use this when UpdateAsync is functional, and we have an equals method and a clone method * Assert.AreNotEqual(exampleA, exampleB, "Object before update is equal to object after update."); * Assert.AreEqual(exampleB, ExampleV, "Updated object is not equal to inputted object."); * // If only some values are changeable, break this up into multiple AreEqual(exampleA.Title, exampleB.Title), etc */ /* Use this when UpdateAsync is functional, and we have an equals method, but no clone method * Assert.AreNotEqual(exampleAImg, exampleBImg, "Object before update is equal to object after update."); * Assert.AreEqual(DatasetSnapshot(ExampleV), exampleBImg, "Updated object is not equal to inputted object."); * // Fails, because UpdateAsync only updates title */ Assert.AreNotEqual(exampleAImg.Title, exampleB.Title, "Title before update is equal to title after update."); Assert.AreEqual(ExampleV.Title, exampleB.Title, "Updated title is not equal to inputted title."); }