public async Task UserDALSameEmailTestAsync()
        {
            var userDAL  = new DemoUsersDAL();
            var userList = await userDAL.GetUsersAsync();

            Assert.Empty(userList);

            var email = "*****@*****.**";

            await userDAL.AddUserAsync(email, "test");

            await userDAL.AddUserAsync("*****@*****.**", "test2");

            userList = await userDAL.GetUsersAsync();

            Assert.Collection(userList.OrderBy(user => user.Id),
                              user => {
                Assert.Equal(1, user.Id);
                Assert.Equal(email, user.Email);
                Assert.Equal("test", user.Name);
            },
                              user => {
                Assert.Equal(2, user.Id);
                Assert.Equal("*****@*****.**", user.Email);
                Assert.Equal("test2", user.Name);
            });

            // Attempt to add a user with the same email as an existing one, exception should be thrown
            var exception = await Assert.ThrowsAsync <ValidationException>(() => userDAL.AddUserAsync(email, "test3"));

            Assert.Equal("Email already exists for a different user.", exception.Message);

            await userDAL.RemoveUserByIdAsync(1);

            await userDAL.AddUserAsync(email, "test3");

            userList = await userDAL.GetUsersAsync();

            Assert.Collection(userList.OrderBy(user => user.Id),
                              user => {
                Assert.Equal(2, user.Id);
                Assert.Equal("*****@*****.**", user.Email);
                Assert.Equal("test2", user.Name);
            },
                              user => {
                Assert.Equal(3, user.Id);
                Assert.Equal(email, user.Email);
                Assert.Equal("test3", user.Name);
            });
        }
        public async Task UserDALValidationTestAsync()
        {
            async Task TestValidation(Func <string, string, Task <TasklifyUser> > testMethod)
            {
                var exception = await Assert.ThrowsAsync <ValidationException>(() => testMethod("", "test"));

                Assert.Equal("Email cannot be empty or all whitespace.", exception.Message);

                exception = await Assert.ThrowsAsync <ValidationException>(() => testMethod("  ", "test"));

                Assert.Equal("Email cannot be empty or all whitespace.", exception.Message);

                exception = await Assert.ThrowsAsync <ValidationException>(() => testMethod(new String('a', 101), "test"));

                Assert.Equal("User email should be less than or equal to 100 characters", exception.Message);

                exception = await Assert.ThrowsAsync <ValidationException>(() => testMethod("*****@*****.**", ""));

                Assert.Equal("Name cannot be empty or all whitespace.", exception.Message);

                exception = await Assert.ThrowsAsync <ValidationException>(() => testMethod("*****@*****.**", "     "));

                Assert.Equal("Name cannot be empty or all whitespace.", exception.Message);

                exception = await Assert.ThrowsAsync <ValidationException>(() => testMethod("*****@*****.**", new String('a', 151)));

                Assert.Equal("User name should be less than or equal to 150 characters", exception.Message);
            }

            var uDAL = new DemoUsersDAL();

            await TestValidation((string email, string name) => uDAL.AddUserAsync(email, name));

            await uDAL.AddUserAsync("*****@*****.**", "test");

            await TestValidation((string email, string name) => uDAL.UpdateUserByIdAsync(1, new TasklifyUser(1, email, name)));

            await uDAL.UpdateUserByIdAsync(1, new TasklifyUser(1, "*****@*****.**", "newname"));

            var userList = await uDAL.GetUsersAsync();

            Assert.Collection(userList,
                              user => {
                Assert.Equal(1, user.Id);
                Assert.Equal("*****@*****.**", user.Email);
                Assert.Equal("newname", user.Name);
            });
        }
        public async Task TaskBLLValidAssigneeIdTest()
        {
            async Task TestValidation(Func <Task <TasklifyTask> > testMethod)
            {
                var exception = await Assert.ThrowsAsync <ValidationException>(() => testMethod());

                Assert.Equal("User with id 1 does not exist.", exception.Message);
            }

            var uDAL = new DemoUsersDAL();
            var tBLL = new DemoTasksBLL(uDAL);

            await TestValidation(() => tBLL.AddAsync("summary", "description", 1));
            await TestValidation(() => tBLL.UpdateByIdAsync(1, new TasklifyTask(1, "newsummary", "description", 1)));

            var patchDocument = new JsonPatchDocument <TasklifyTask>();

            patchDocument.Replace(task => task.Assignee_Id, 1);
            await TestValidation(() => tBLL.PatchByIdAsync(1, patchDocument));

            // Add a user with id 1, now the above operations should go through
            await uDAL.AddUserAsync("*****@*****.**", "test");

            await tBLL.AddAsync("summary", "description", 1);

            await tBLL.UpdateByIdAsync(1, new TasklifyTask(1, "newsummary", "description", 1));

            // Add another user so a user with id 2 exists
            await uDAL.AddUserAsync("*****@*****.**", "test2");

            // Now this id can be assigned to the assignee_id for task 1
            patchDocument = new JsonPatchDocument <TasklifyTask>();
            patchDocument.Replace(task => task.Assignee_Id, 2);
            var task = await tBLL.PatchByIdAsync(1, patchDocument);

            Assert.Equal(1, task.Id);
            Assert.Equal("newsummary", task.Summary);
            Assert.Equal("description", task.Description);
            Assert.Equal(2, task.Assignee_Id);
        }
        public async Task UserDALGetByEmailTestAsync()
        {
            async Task TestSearchByEmail(DemoUsersDAL userDAL, string email, int expectedId, string expectedName)
            {
                var user = await userDAL.GetUserByEmailAsync(email);

                Assert.Equal(expectedId, user.Id);
                Assert.Equal(email, user.Email);
                Assert.Equal(expectedName, user.Name);
            }

            var uDAL = new DemoUsersDAL();
            await uDAL.AddUserAsync("*****@*****.**", "test1");

            await uDAL.AddUserAsync("*****@*****.**", "test2");

            await uDAL.AddUserAsync("*****@*****.**", "test3");

            await TestSearchByEmail(uDAL, "*****@*****.**", 2, "test2");
            await TestSearchByEmail(uDAL, "*****@*****.**", 1, "test1");
            await TestSearchByEmail(uDAL, "*****@*****.**", 3, "test3");
        }