public async Task ShouldRemoveClaimByTypeAndValue() { await Login(); var newUser = UserViewModelFaker.GenerateUserViewModel().Generate(); var response = await _client.PostAsync("/sign-up", new StringContent(newUser.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); var claim = UserViewModelFaker.GenerateClaim().Generate(); response = await _client.PostAsync($"/admin/users/{newUser.Username}/claims", new StringContent(claim.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); string firstClaimValue = claim.Value; claim.Value = _faker.Internet.DomainName(); response = await _client.PostAsync($"/admin/users/{newUser.Username}/claims", new StringContent(claim.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); response = await _client.DeleteAsync($"/admin/users/{newUser.Username}/claims/{claim.Type}?value={claim.Value}"); response.EnsureSuccessStatusCode(); // List all claims var claimResponse = await _client.GetAsync($"/admin/users/{newUser.Username}/claims"); var claims = (await claimResponse.Content.ReadAsStringAsync()).FromJson <IEnumerable <ClaimViewModel> >(); claims.FirstOrDefault(model => model.Value.Equals(firstClaimValue)).Should().NotBeNull(); }
public async Task Should_Register_New_User_As_Admin_With_Email_Confirmed() { var command = UserViewModelFaker.GenerateRegisterAdminViewModel(false).Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.UserName == command.Username).EmailConfirmed.Should().BeTrue(); }
public async Task Should_Not_Email_Be_Confirmed_After_User_Register() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.Email == command.Email)?.EmailConfirmed.Should().BeFalse(); }
public async Task ShouldRegisterNewUser() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.UserName == command.Username).Should().NotBeNull(); }
public async Task Should_Find_Username() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); var result = await _userManagerAppService.FindByUsernameAsync(command.Username); result.Should().NotBeNull(); }
public async Task Should_Register_New_User_Without_Password() { var command = UserViewModelFaker.GenerateSocialViewModel().Generate(); var result = await _userAppService.RegisterWithoutPassword(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.UserName == command.Username).Should().NotBeNull(); }
public async Task ShouldEmailExist() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); var result = await _userAppService.CheckEmail(command.Email); result.Should().BeTrue(); }
public async Task ShouldFindEmail() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); var result = await _userAppService.FindByEmailAsync(command.Email); result.Should().NotBeNull(); }
public async Task ShouldAddNewUser() { var newUser = UserViewModelFaker.GenerateUserViewModel().Generate(); var response = await _client.PostAsync("/sign-up", new StringContent(newUser.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); }
public async Task Should_Save_SocialNumber() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); var userClaims = await _userManagerAppService.GetClaims(command.Username); userClaims.FirstOrDefault(f => f.Type == JwtClaimTypes.BirthDate).Should().NotBeNull(); }
public async Task Should_Register_New_User_With_LockOut_Disabled() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); var user = _database.Users.FirstOrDefault(f => f.UserName == command.Username); user.Should().NotBeNull(); user.LockoutEnd.Should().BeNull(); }
public async Task User_LockoutDate_Should_Be_Null() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); var savedUser = await _userManagerAppService.GetUserDetails(command.Username); savedUser.LockoutEnd.Should().BeNull(); }
public async Task New_User_Could_Have_Claim_Picture() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); var userClaims = await _userManagerAppService.GetClaims(command.Username); userClaims.FirstOrDefault(f => f.Type == JwtClaimTypes.Picture).Should().NotBeNull(); }
public async Task ShouldSendResetLinkByUsername() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); var emailSent = await _userAppService.SendResetLink(new ForgotPasswordViewModel(command.Username)); _notifications.GetNotifications().Select(s => s.Value).ToList().ForEach(_output.WriteLine); emailSent.Should().BeTrue(); }
public async Task ShouldNotRegisterUserWithoutPassword() { var command = UserViewModelFaker.GenerateUserWithProviderViewModel().Generate(); command.Password = null; command.ConfirmPassword = null; var result = await _userAppService.Register(command); result.Should().BeFalse(); _database.Users.FirstOrDefault(f => f.UserName == command.Username).Should().BeNull(); }
public async Task ShouldFindLoginByProvider() { var command = UserViewModelFaker.GenerateSocialViewModel().Generate(); var result = await _userAppService.RegisterWithoutPassword(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.UserName == command.Username).Should().NotBeNull(); var user = await _userAppService.FindByProviderAsync(command.Provider, command.ProviderId); user.Should().NotBeNull(); }
public async Task Should_Register_User_Without_Email() { _identityOptions.Value.User.RequireUniqueEmail = false; var command = UserViewModelFaker.GenerateUserLdapViewModel(setEmail: false).Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); var user = _database.Users.FirstOrDefault(f => f.UserName == command.Username); user.Should().NotBeNull(); user?.Email.Should().BeNullOrEmpty(); }
public async Task ShouldFindByIds() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); var users = _database.Users.Select(s => s.Id).ToArray(); var usersFound = await _userManagerAppService.GetUsersById(users); usersFound.Should().HaveCountGreaterOrEqualTo(2); }
public async Task ShouldAddClaim() { await Login(); var newUser = UserViewModelFaker.GenerateUserViewModel().Generate(); var response = await _client.PostAsync("/sign-up", new StringContent(newUser.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); var claim = UserViewModelFaker.GenerateClaim().Generate(); response = await _client.PostAsync($"/admin/users/{newUser.Username}/claims", new StringContent(claim.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); }
public async Task Should_Get_Events_And_Have_Details_As_Json() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.UserName == command.Username).Should().NotBeNull(); var events = _eventStoreAppService.GetEvents(new SearchEventByAggregate()); events.Collection.Should().HaveCountGreaterOrEqualTo(1); foreach (var eventHistoryData in events.Collection) { eventHistoryData.Details.Should().Contain("{"); } }
public async Task ShouldAddLogin() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); var socialUser = UserViewModelFaker.GenerateSocialViewModel(command.Email, command.Username).Generate(); socialUser.Email = command.Email; socialUser.Username = command.Username; var result = await _userAppService.AddLogin(socialUser); result.Should().BeTrue(); var userId = await _userAppService.FindByEmailAsync(command.Email); _database.UserLogins.Any(s => s.UserId == userId.Id).Should().BeTrue(); }
public async Task ShouldNotRegisterDuplicatedEmail() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.Email == command.Email).Should().NotBeNull(); var email = command.Email; command = UserViewModelFaker.GenerateUserViewModel().Generate(); command.Email = email; result = await _userAppService.Register(command); result.Should().BeFalse(); _database.Users.Count(f => f.Email == command.Email).Should().Be(1); }
public async Task Should_Update_User() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); var user = await _userManagerAppService.GetUserDetails(command.Username); user.Birthdate = DateTime.Now.Date.AddYears(-18); result = await _userManagerAppService.UpdateUser(user); result.Should().BeTrue(); user = await _userManagerAppService.GetUserDetails(command.Username); user.Birthdate.Should().Be(DateTime.Now.Date.AddYears(-18)); }
public async Task Should_Not_Register_Duplicated_Username() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); _database.Users.FirstOrDefault(f => f.UserName == command.Username).Should().NotBeNull(); var username = command.Username; command = UserViewModelFaker.GenerateUserViewModel().Generate(); command.Username = username; result = await _userAppService.Register(command); result.Should().BeFalse(); _database.Users.Count(f => f.UserName == command.Username).Should().Be(1); }
public async Task Should_Search_User_By_Ssn() { string ssn = string.Empty; var commands = UserViewModelFaker.GenerateUserViewModel().Generate(_faker.Random.Int(1, 10)); foreach (var command in commands) { var result = await _userAppService.Register(command); result.Should().BeTrue(); ssn = command.SocialNumber; } var search = new UserFindByProperties(ssn); var users = await _userManagerAppService.SearchUsersByProperties(search); users.Total.Should().BeGreaterOrEqualTo(1); users.Collection.ToList().Count.Should().Be(users.Total); }
public async Task Should_Search_Return_All_Users() { var commands = UserViewModelFaker.GenerateUserViewModel().Generate(50); foreach (var command in commands) { var result = await _userAppService.Register(command); result.Should().BeTrue(); } var search = new UserSearch <TKey>() { Limit = 50 }; var users = await _userManagerAppService.Search(search); users.Total.Should().BeGreaterOrEqualTo(1); users.Collection.ToList().Count.Should().Be(50); users.Total.Should().Be(users.Total); }
public async Task ShouldListUsers() { await Login(); var newUser = UserViewModelFaker.GenerateUserViewModel().Generate(); var response = await _client.PostAsync("/sign-up", new StringContent(newUser.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); var httpResponse = await _client.GetAsync("/admin/users"); httpResponse.EnsureSuccessStatusCode(); // Deserialize and examine results. var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var users = stringResponse.FromJson <ListOf <UserListViewModel> >(); users.Should().NotBeNull(); }
public async Task Should_Find_By_Ids() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); command = UserViewModelFaker.GenerateUserViewModel().Generate(); await _userAppService.Register(command); var users = _database.Users.Select(s => s.Id).ToArray(); var search = new UserSearch <TKey>() { Id = users }; var usersFound = await _userManagerAppService.Search(search); usersFound.Total.Should().BeGreaterOrEqualTo(1); usersFound.Collection.ToList().Count.Should().Be(usersFound.Total); }
public async Task Should_Search_By_Claim_And_Count_Be_Equal_Limit() { var commands = UserViewModelFaker.GenerateUserViewModel().Generate(50); foreach (var command in commands) { var result = await _userAppService.Register(command); result.Should().BeTrue(); } var search = new UserFindByProperties(null) { Limit = 10 }; var users = await _userManagerAppService.SearchUsersByProperties(search); users.Total.Should().BeGreaterOrEqualTo(1); users.Collection.ToList().Count.Should().Be(10); users.Total.Should().Be(users.Total); }
public async Task Should_Synchronize_Claims() { var command = UserViewModelFaker.GenerateUserViewModel().Generate(); var result = await _userAppService.Register(command); result.Should().BeTrue(); var userClaims = await _userManagerAppService.GetClaims(command.Username); userClaims.FirstOrDefault(f => f.Type == "social_number").Should().NotBeNull(); var newSSN = _faker.Person.Ssn(); var newClaims = new List <ClaimViewModel>() { new ClaimViewModel("social_number", newSSN) }; await _userManagerAppService.SynchronizeClaims(command.Username, newClaims); userClaims = await _userManagerAppService.GetClaims(command.Username); userClaims.FirstOrDefault(f => f.Type == "social_number").Should().NotBeNull(); userClaims.FirstOrDefault(f => f.Type == "social_number").Value.Should().Be(newSSN); userClaims.Count(f => f.Type == "social_number").Should().Be(1); }