public async Task UpdateAsync_HasUser_RoleWasChanged_OkAsync()
        {
            using (var context = new IdentitySqliteContext())
            {
                var addedUser = await new UserFactory(Role.Employee, email: "*****@*****.**")
                                .PleaseAsync(context);

                var target = new UserServiceForIdentityServer(context, new Mock <ILogger <UserServiceForIdentityServer> >().Object);

                var user = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                user.Role = Role.HRManager;

                await target.UpdateAsync(user);

                var userInDb = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                // was changed
                Assert.Equal(Role.HRManager, userInDb.Role);

                // Was not changed
                Assert.Equal("*****@*****.**", userInDb.Email);
                Assert.Equal("*****@*****.**", userInDb.UserName);
            }
        }
        public async Task UpdateAsync_UserDoesNotExist_OkAsync()
        {
            using (var context = new IdentitySqliteContext())
            {
                var addedUser = await new UserFactory(Role.Employee, email: "*****@*****.**")
                                .PleaseAsync(context);

                var target = new UserServiceForIdentityServer(context, new Mock <ILogger <UserServiceForIdentityServer> >().Object);

                var user = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                Assert.NotNull(user);
                Assert.Equal(addedUser.Id, user.Id);
                Assert.Equal(Role.Employee, user.Role);

                var newUser = new IdentityServer.Database.Models.User
                {
                    FirstName = Faker.Name.First(),
                    LastName  = Faker.Name.Last(),
                    UserName  = "******"
                };

                await target.UpdateAsync(newUser);

                user = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                Assert.NotNull(user);
                Assert.Equal(addedUser.Id, user.Id);
                Assert.Equal(Role.Employee, user.Role);
            }
        }
        public async Task RemoveAsync_HasUser_BeingRemoved_OkAsync()
        {
            using (var context = new IdentitySqliteContext())
            {
                var addedUser = await new UserFactory(Role.Employee, email: "*****@*****.**")
                                .Outdated()
                                .PleaseAsync(context);

                var target = new UserServiceForIdentityServer(context, new Mock <ILogger <UserServiceForIdentityServer> >().Object);

                var user = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                Assert.NotNull(user);
                Assert.False(user.Active());

                await target.RemoveAsync(addedUser.UserName);

                user = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                Assert.Null(user);

                Assert.False(await context.Users.AnyAsync());
                Assert.False(await context.UserRoles.AnyAsync());
            }
        }
        public async Task UserByEmailAsync_HasNoUser_ReturnsNull_OkAsync()
        {
            using (var context = new IdentitySqliteContext())
            {
                var user = await new UserFactory(
                    Role.Employee,
                    "*****@*****.**")
                           .PleaseAsync(context);

                var target = new UserServiceForIdentityServer(context, new Mock <ILogger <UserServiceForIdentityServer> >().Object);

                Assert.Null(await target.UserByUserNameOrNullAsync("No_email_like_this"));
            }
        }
        public async Task DeleteAsync_UserDoesNotExist_OkAsync()
        {
            using (var context = new IdentitySqliteContext())
            {
                var addedUser = await new UserFactory(Role.Employee, email: "*****@*****.**")
                                .PleaseAsync(context);

                var target = new UserServiceForIdentityServer(context, new Mock <ILogger <UserServiceForIdentityServer> >().Object);

                var user = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                Assert.NotNull(user);
                Assert.Equal(addedUser.Id, user.Id);
                Assert.Equal(Role.Employee, user.Role);

                await target.DeleteAsync("*****@*****.**");

                user = await target.UserByUserNameOrNullAsync(addedUser.UserName);

                Assert.NotNull(user);
                Assert.Equal(addedUser.Id, user.Id);
                Assert.Equal(Role.Employee, user.Role);
            }
        }