public async Task AddGetDeleteTaskTestAsync() { void TestParameters(TasklifyTask task, int id, string summary, string description, int?assignee_id) { Assert.Equal(id, task.Id); Assert.Equal(summary, task.Summary); Assert.Equal(description, task.Description); Assert.Equal(assignee_id, task.Assignee_Id); } var tDAL = new DemoTasksDAL(); var result = await tDAL.AddAsync("Summary1", "Description1", null); TestParameters(result, 1, "Summary1", "Description1", null); result = await tDAL.AddAsync("Summary2", "Description2", null); TestParameters(result, 2, "Summary2", "Description2", null); result = await tDAL.AddAsync("Summary3", "Description3", null); TestParameters(result, 3, "Summary3", "Description3", null); // Try to remove a task with an id that does not exist, should return false var removeResult = await tDAL.RemoveByIdAsync(5); Assert.False(removeResult); // A task with ID 1 should exist and thus the operation should go through removeResult = await tDAL.RemoveByIdAsync(1); Assert.True(removeResult); var taskList = await tDAL.GetAllAsync(); Assert.Collection(taskList.OrderBy(task => task.Id), task => { Assert.Equal(2, task.Id); Assert.Equal("Summary2", task.Summary); Assert.Equal("Description2", task.Description); }, task => { Assert.Equal(3, task.Id); Assert.Equal("Summary3", task.Summary); Assert.Equal("Description3", task.Description); }); result = await tDAL.GetByIdAsync(5); Assert.Null(result); result = await tDAL.GetByIdAsync(2); TestParameters(result, 2, "Summary2", "Description2", null); }
public async Task TaskDALPatchTestAsync() { var tDAL = new DemoTasksDAL(); var patchDocument = new JsonPatchDocument <TasklifyTask>(); patchDocument.Replace(task => task.Description, "newdescription"); var result = await tDAL.PatchByIdAsync(1, patchDocument); Assert.Null(result); await tDAL.AddAsync("summary", "description"); await tDAL.PatchByIdAsync(1, patchDocument); var task = await tDAL.GetByIdAsync(1); Assert.Equal(1, task.Id); Assert.Equal("summary", task.Summary); Assert.Equal("newdescription", task.Description); }