public async Task RegisterUser_Should_ThrowException_WhenNotAgreedToTerms()
        {
            // Arrange
            var          clientId     = Guid.NewGuid();
            var          repo         = GetMockRepo();
            const string username     = "******";
            var          existingUser = new User {
                Username = username
            };
            await repo.Create(existingUser, clientId);

            var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
            var reg = new UserRegistration {
                EmailAddress = username, AggreedToTerms = false
            };

            // Act & Assert
            try
            {
                await sut.RegisterUser(reg, clientId);

                Assert.True(false, "Method should have failed but did not");
            }
            catch (UserRegistrationException regEx)
            {
                Assert.Contains(regEx.RegistrationErrors, x => x == "Must agree to terms and conditions");
            }
        }
        public async Task RegisterUser_Should_ThrowException_WhenEmailAddressIsInvalidFormat()
        {
            // Arrange
            var          clientId     = Guid.NewGuid();
            var          repo         = GetMockRepo();
            const string username     = "******";
            var          existingUser = new User {
                Username = username
            };
            await repo.Create(existingUser, clientId);

            var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
            var reg = new UserRegistration {
                EmailAddress = username
            };

            // Act & Assert
            try
            {
                await sut.RegisterUser(reg, clientId);

                Assert.True(false, "Method should have failed but did not");
            }
            catch (UserRegistrationException regEx)
            {
                Assert.Contains(regEx.RegistrationErrors, x => x == "Not a valid email address");
            }
        }
        public async Task RegisterUser_Result_ShouldHave_MatchingUser()
        {
            // Arrange
            var clientId = Guid.NewGuid();
            var repo     = GetMockRepo();
            var reg      = new UserRegistration
            {
                AggreedToTerms = true,
                EmailAddress   = "*****@*****.**",
                Password       = "******",
                FirstName      = "FirstName",
                LastName       = "LastName",
                ProviderName   = "Google",
                ProviderId     = "GoogleId"
            };
            var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
            // Act
            var result = await sut.RegisterUser(reg, clientId);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(reg.FirstName, result.UserProfile.FirstName);
            Assert.Equal(reg.LastName, result.UserProfile.LastName);
            Assert.Equal(reg.EmailAddress, result.UserProfile.Email);
        }
 public async Task RegisterUser_Should_ThrowException_OnEmptyClientId()
 {
     // Arrange
     var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
     var reg = new UserRegistration();
     // Act & Assert
     await Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.RegisterUser(reg, Guid.Empty));
 }
 public async Task RegisterUser_Should_ThrowException_WhenEmailAddressIsNull()
 {
     // Arrange
     var clientId = Guid.NewGuid();
     var repo     = GetMockRepo();
     var sut      = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
     var reg      = new UserRegistration();
     // Act & Assert
     await Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.RegisterUser(reg, clientId));
 }
        public async Task RegisterUser_Should_Return_ProviderId_WhenGoogleAuthSelected()
        {
            // Arrange
            var clientId = Guid.NewGuid();
            var repo     = GetMockRepo();
            var reg      = new UserRegistration
            {
                AggreedToTerms = true,
                EmailAddress   = "*****@*****.**",
                FirstName      = "FirstName",
                LastName       = "LastName",
                ProviderName   = "Google",
                ProviderId     = "GoogleId"
            };
            var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
            // Act
            var result = await sut.RegisterUser(reg, clientId);

            // Assert
            Assert.Equal(reg.ProviderId, result.AuthProfile.ProviderId);
        }
        public async Task RegisterUser_Should_Return_PasswordHash_ThatCanBeValidated()
        {
            // Arrange
            var clientId = Guid.NewGuid();
            var repo     = GetMockRepo();
            var reg      = new UserRegistration
            {
                AggreedToTerms = true,
                EmailAddress   = "*****@*****.**",
                Password       = "******",
                FirstName      = "FirstName",
                LastName       = "LastName",
                ProviderName   = "Gibson"
            };
            var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
            // Act
            var result = await sut.RegisterUser(reg, clientId);

            // Assert
            Assert.True(GetPasswordHasher().VerifyHashedPassword(result.AuthProfile.PasswordHash, reg.Password));
        }
        public async Task RegisterUser_Should_Return_GibsonEnum_For_GibsonProvider()
        {
            // Arrange
            var clientId = Guid.NewGuid();
            var repo     = GetMockRepo();
            var reg      = new UserRegistration
            {
                AggreedToTerms = true,
                EmailAddress   = "*****@*****.**",
                Password       = "******",
                FirstName      = "FirstName",
                LastName       = "LastName",
                ProviderName   = "Gibson"
            };
            var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
            // Act
            var result = await sut.RegisterUser(reg, clientId);

            // Assert
            Assert.Equal(GibsonAuthProvider.Gibson, result.AuthProfile.AuthProvider);
        }
        public async Task RegisterUser_Should_Return_Matching_UserType()
        {
            // Arrange
            var clientId = Guid.NewGuid();
            var repo     = GetMockRepo();
            var reg      = new UserRegistration
            {
                AggreedToTerms = true,
                EmailAddress   = "*****@*****.**",
                Password       = "******",
                FirstName      = "FirstName",
                LastName       = "LastName",
                ProviderName   = "Google",
                ProviderId     = "GoogleId",
                UserType       = GibsonUserType.Customer
            };
            var sut = new UserRegistrationService(GetMockRepo(), GetPasswordHasher());
            // Act
            var result = await sut.RegisterUser(reg, clientId);

            // Assert
            Assert.Equal(reg.UserType, result.UserType);
        }