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();
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
        public async Task ShouldEmailExist()
        {
            var command = UserViewModelFaker.GenerateUserViewModel().Generate();
            await _userAppService.Register(command);

            var result = await _userAppService.CheckEmail(command.Email);

            result.Should().BeTrue();
        }
Beispiel #8
0
        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();
        }
Beispiel #10
0
        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();
        }
Beispiel #11
0
        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();
        }
Beispiel #12
0
        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();
        }
Beispiel #13
0
        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();
        }
Beispiel #14
0
        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();
        }
Beispiel #15
0
        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();
        }
Beispiel #16
0
        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();
        }
Beispiel #17
0
        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();
        }
Beispiel #18
0
        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("{");
            }
        }
Beispiel #21
0
        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();
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        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));
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        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();
        }
Beispiel #28
0
        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);
        }
Beispiel #29
0
        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);
        }
Beispiel #30
0
        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);
        }