コード例 #1
0
        public async Task ValidateUniqueEmail_UniqueEmail()
        {
            // Arrange
            var existingEmailToTest = "*****@*****.**";
            var newEmailToTest      = "*****@*****.**";
            var existingUser        = new ApplicationUser {
                UserName = existingEmailToTest, Email = existingEmailToTest
            };

            _applicationUserManagerMock.Setup(x => x.FindByEmailAsync(existingEmailToTest)).Returns(Task.FromResult(existingUser));


            var newUser = new ApplicationUser {
                UserName = newEmailToTest, Email = newEmailToTest
            };
            var validator = new Section14cUserValidator <ApplicationUser>(_applicationUserManagerMock.Object)
            {
                RequireUniqueEmail = true
            };

            // Act
            var validatorResult = await validator.ValidateAsync(newUser);

            // Assert
            Assert.IsTrue(validatorResult.Succeeded);
        }
コード例 #2
0
        public async Task ValidateUniqueEmail_DuplicateEmail()
        {
            // Arrange
            var emailToTest  = "*****@*****.**";
            var existingUser = new ApplicationUser {
                UserName = emailToTest, Email = emailToTest
            };

            _applicationUserManagerMock.Setup(x => x.FindByEmailAsync(emailToTest)).Returns(Task.FromResult(existingUser));


            var newUser = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**"
            };
            var validator = new Section14cUserValidator <ApplicationUser>(_applicationUserManagerMock.Object)
            {
                RequireUniqueEmail = true
            };

            // Act
            var validatorResult = await validator.ValidateAsync(newUser);

            // Assert
            Assert.IsTrue(validatorResult.Errors.Contains($"Email '{emailToTest}' is already taken."));
        }
コード例 #3
0
        public async Task DoesntValidateUniqueEINOnPasswordChange()
        {
            // Arrange
            var ein          = "12-3456789";
            var existingUser = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**"
            };

            existingUser.Organizations.Add(new OrganizationMembership {
                EIN = ein, IsAdmin = true
            });
            _applicationUserManagerMock.Setup(x => x.Users).Returns(new List <ApplicationUser> {
                existingUser
            }.AsQueryable());
            var validator = new Section14cUserValidator <ApplicationUser>(_applicationUserManagerMock.Object)
            {
                RequireUniqueEINAdmin = true
            };

            // Act (running the validator on a user already in the store simulates what happens when a user changes their password)
            var result = await validator.ValidateAsync(existingUser);

            // Assert
            Assert.IsTrue(result.Succeeded);
        }
コード例 #4
0
        public async Task ValidateUniqueEIN_UniqueEIN()
        {
            // Arrange
            var existingEmailToTest = "*****@*****.**";
            var newEmailToTest      = "*****@*****.**";
            var existingEINToTest   = "12-3456789";
            var newEINToTest        = "98-7654321";
            var existingUser        = new ApplicationUser {
                UserName = existingEmailToTest, Email = existingEmailToTest
            };

            existingUser.Organizations.Add(new OrganizationMembership {
                EIN = existingEINToTest, IsAdmin = true
            });
            _applicationUserManagerMock.Setup(x => x.Users).Returns(new List <ApplicationUser> {
                existingUser
            }.AsQueryable());


            var newUser = new ApplicationUser {
                UserName = newEmailToTest, Email = newEmailToTest
            };

            newUser.Organizations.Add(new OrganizationMembership {
                EIN = newEINToTest, IsAdmin = true
            });
            var validator = new Section14cUserValidator <ApplicationUser>(_applicationUserManagerMock.Object)
            {
                RequireUniqueEINAdmin = true
            };

            // Act
            var validatorResult = await validator.ValidateAsync(newUser);

            // Assert
            Assert.IsTrue(validatorResult.Succeeded);
        }
        public async Task ValidateUniqueEIN_DuplicateEIN()
        {
            // Arrange
            var existingEmailToTest = "*****@*****.**";
            var newEmailToTest      = "*****@*****.**";
            var einToTest           = "12-3456789";
            var existingUser        = new ApplicationUser {
                UserName = existingEmailToTest, Email = existingEmailToTest
            };

            existingUser.Organizations.Add(new OrganizationMembership {
                EIN = einToTest, IsPointOfContact = true
            });
            _applicationUserManagerMock.Setup(x => x.Users).Returns(new List <ApplicationUser> {
                existingUser
            }.AsQueryable());


            var newUser = new ApplicationUser {
                UserName = newEmailToTest, Email = newEmailToTest
            };

            newUser.Organizations.Add(new OrganizationMembership {
                EIN = einToTest, IsPointOfContact = true
            });
            var validator = new Section14cUserValidator <ApplicationUser>(_applicationUserManagerMock.Object)
            {
                RequireUniqueEINAdmin = true
            };

            // Act
            var validatorResult = await validator.ValidateAsync(newUser);

            // Assert
            Assert.IsTrue(validatorResult.Errors.Contains("Id is already registered"));
        }