示例#1
0
            public void SetsUnconfirmedEmailWhenEmailIsChanged()
            {
                var user    = CreateUser("Bob", "ThePassword", "*****@*****.**");
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                service.ChangeEmailAddress(user, "*****@*****.**");

                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Equal("*****@*****.**", user.UnconfirmedEmailAddress);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }
示例#2
0
            public void DoesNotModifyConfirmationTokenWhenUnconfirmedEmailAddressNotChanged(string confirmedEmailAddress)
            {
                var user = new User {
                    EmailAddress            = confirmedEmailAddress,
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken  = "pending-token"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user },
                };

                service.ChangeEmailAddress(user, "*****@*****.**");
                Assert.Equal("pending-token", user.EmailConfirmationToken);
            }
示例#3
0
            public async Task SetsUnconfirmedEmailWhenEmailIsChanged()
            {
                var user = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                await service.ChangeEmailAddress(user, "*****@*****.**");

                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Equal("*****@*****.**", user.UnconfirmedEmailAddress);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }
示例#4
0
            public async Task ClearsEmailConfirmationToken()
            {
                var user = new User {
                    Username = "******", EmailConfirmationToken = Guid.NewGuid().ToString(), UnconfirmedEmailAddress = "*****@*****.**", EmailAddress = "*****@*****.**"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                await service.CancelChangeEmailAddress(user);

                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Null(user.EmailConfirmationToken);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }
示例#5
0
            public void ModifiesConfirmationTokenWhenEmailAddressChanged()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", EmailConfirmationToken = "pending-token"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user },
                };

                service.ChangeEmailAddress(user, "*****@*****.**");
                Assert.NotNull(user.EmailConfirmationToken);
                Assert.NotEmpty(user.EmailConfirmationToken);
                Assert.NotEqual("pending-token", user.EmailConfirmationToken);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }
示例#6
0
            public void DoesNotModifyAnythingWhenConfirmedEmailAddressNotChanged()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = null, EmailConfirmationToken = null
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user },
                };

                service.ChangeEmailAddress(user, "*****@*****.**");
                Assert.True(user.Confirmed);
                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Null(user.UnconfirmedEmailAddress);
                Assert.Null(user.EmailConfirmationToken);
            }
示例#7
0
            public void ThrowsForDuplicateConfirmedEmailAddresses()
            {
                var user = new User {
                    Username = "******", Key = 1, EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = "*****@*****.**", EmailConfirmationToken = "token"
                };
                var conflictingUser = new User {
                    Username = "******", Key = 2, EmailAddress = "*****@*****.**"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user, conflictingUser }
                };

                var ex = Assert.Throws <EntityException>(() => service.ConfirmEmailAddress(user, "token"));

                Assert.Equal(String.Format(Strings.EmailAddressBeingUsed, "*****@*****.**"), ex.Message);
            }
示例#8
0
            public void ReturnsNullIfMultipleMatchesExist()
            {
                var user = new User {
                    Username = "******", Key = 1, EmailAddress = "*****@*****.**"
                };
                var conflictingUser = new User {
                    Username = "******", Key = 2, EmailAddress = "*****@*****.**"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user, conflictingUser }
                };

                var result = service.FindByEmailAddress("*****@*****.**");

                Assert.Null(result);
            }
示例#9
0
            public void DoesNotLetYouUseSomeoneElsesConfirmedEmailAddress()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Key = 1
                };
                var conflictingUser = new User {
                    EmailAddress = "*****@*****.**", Key = 2
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user, conflictingUser },
                };

                var e = Assert.Throws <EntityException>(() => service.ChangeEmailAddress(user, "*****@*****.**"));

                Assert.Equal(string.Format(Strings.EmailAddressBeingUsed, "*****@*****.**"), e.Message);
                Assert.Equal("*****@*****.**", user.EmailAddress);
            }
示例#10
0
            public async Task WritesAuditRecord()
            {
                // Arrange
                var user = new User {
                    Username = "******", EmailAddress = "*****@*****.**"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                // Act
                await service.ChangeEmailAddress(user, "*****@*****.**");

                // Assert
                Assert.True(service.Auditing.WroteRecord <UserAuditRecord>(ar =>
                                                                           ar.Action == AuditedUserAction.ChangeEmail &&
                                                                           ar.AffectedEmailAddress == "*****@*****.**" &&
                                                                           ar.EmailAddress == "*****@*****.**"));
            }
示例#11
0
            public async Task WritesAuditRecord()
            {
                // Arrange
                var user = new User {
                    Username = "******", EmailConfirmationToken = Guid.NewGuid().ToString(), UnconfirmedEmailAddress = "*****@*****.**", EmailAddress = "*****@*****.**"
                };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                // Act
                await service.CancelChangeEmailAddress(user);

                // Assert
                Assert.True(service.Auditing.WroteRecord <UserAuditRecord>(ar =>
                                                                           ar.Action == AuditedUserAction.CancelChangeEmail &&
                                                                           ar.AffectedEmailAddress == "*****@*****.**" &&
                                                                           ar.EmailAddress == "*****@*****.**"));
            }
            public async Task DoesNotLetYouUseSomeoneElsesConfirmedEmailAddress()
            {
                var user = new User { EmailAddress = "*****@*****.**", Key = 1 };
                var conflictingUser = new User { EmailAddress = "*****@*****.**", Key = 2 };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user, conflictingUser },
                };

                var e = await AssertEx.Throws<EntityException>(() => service.ChangeEmailAddress(user, "*****@*****.**"));
                Assert.Equal(string.Format(Strings.EmailAddressBeingUsed, "*****@*****.**"), e.Message);
                Assert.Equal("*****@*****.**", user.EmailAddress);
            }
            public void ReturnsNullIfMultipleMatchesExist()
            {
                var user = new User { Username = "******", Key = 1, EmailAddress = "*****@*****.**" };
                var conflictingUser = new User { Username = "******", Key = 2, EmailAddress = "*****@*****.**" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user, conflictingUser }
                };

                var result = service.FindByEmailAddress("*****@*****.**");
                Assert.Null(result);
            }
            public async Task ThrowsForDuplicateConfirmedEmailAddresses()
            {
                var user = new User { Username = "******", Key = 1, EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = "*****@*****.**", EmailConfirmationToken = "token" };
                var conflictingUser = new User { Username = "******", Key = 2, EmailAddress = "*****@*****.**" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user, conflictingUser }
                };

                var ex = await AssertEx.Throws<EntityException>(() => service.ConfirmEmailAddress(user, "token"));
                Assert.Equal(String.Format(Strings.EmailAddressBeingUsed, "*****@*****.**"), ex.Message);
            }
            public async Task SetsUnconfirmedEmailWhenEmailIsChanged()
            {
                var user = new User { Username = "******", EmailAddress = "*****@*****.**" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                await service.ChangeEmailAddress(user, "*****@*****.**");

                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Equal("*****@*****.**", user.UnconfirmedEmailAddress);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }
            public async Task WritesAuditRecord()
            {
                // Arrange
                var user = new User { Username = "******", EmailConfirmationToken = Guid.NewGuid().ToString(), UnconfirmedEmailAddress = "*****@*****.**", EmailAddress = "*****@*****.**" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                // Act
                await service.CancelChangeEmailAddress(user);

                // Assert
                Assert.True(service.Auditing.WroteRecord<UserAuditRecord>(ar =>
                    ar.Action == AuditedUserAction.CancelChangeEmail &&
                    ar.AffectedEmailAddress == "*****@*****.**" &&
                    ar.EmailAddress == "*****@*****.**"));
            }
            public async Task ClearsEmailConfirmationToken()
            {
                var user = new User { Username = "******", EmailConfirmationToken = Guid.NewGuid().ToString() ,UnconfirmedEmailAddress = "*****@*****.**", EmailAddress = "*****@*****.**" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                await service.CancelChangeEmailAddress(user);

                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Null(user.EmailConfirmationToken);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }
            public async Task ModifiesConfirmationTokenWhenEmailAddressChanged()
            {
                var user = new User { EmailAddress = "*****@*****.**", EmailConfirmationToken = "pending-token" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user },
                };

                await service.ChangeEmailAddress(user, "*****@*****.**");
                Assert.NotNull(user.EmailConfirmationToken);
                Assert.NotEmpty(user.EmailConfirmationToken);
                Assert.NotEqual("pending-token", user.EmailConfirmationToken);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }
            public async Task DoesNotModifyAnythingWhenConfirmedEmailAddressNotChanged()
            {
                var user = new User { EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = null, EmailConfirmationToken = null };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user },
                };

                await service.ChangeEmailAddress(user, "*****@*****.**");
                Assert.True(user.Confirmed);
                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Null(user.UnconfirmedEmailAddress);
                Assert.Null(user.EmailConfirmationToken);
            }
            public async Task DoesNotModifyConfirmationTokenWhenUnconfirmedEmailAddressNotChanged(string confirmedEmailAddress)
            {
                var user = new User {
                    EmailAddress = confirmedEmailAddress,
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken = "pending-token" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new User[] { user },
                };

                await service.ChangeEmailAddress(user, "*****@*****.**");
                Assert.Equal("pending-token", user.EmailConfirmationToken);
            }
            public async Task WritesAuditRecord()
            {
                // Arrange
                var user = new User { Username = "******", EmailAddress = "*****@*****.**" };
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                // Act
                await service.ChangeEmailAddress(user, "*****@*****.**");

                // Assert
                Assert.True(service.Auditing.WroteRecord<UserAuditRecord>(ar =>
                    ar.Action == AuditedUserAction.ChangeEmail &&
                    ar.AffectedEmailAddress == "*****@*****.**" &&
                    ar.EmailAddress == "*****@*****.**"));
            }
示例#22
0
            public void SetsUnconfirmedEmailWhenEmailIsChanged()
            {
                var user = CreateUser("Bob", "ThePassword", "*****@*****.**");
                var service = new TestableUserServiceWithDBFaking
                {
                    Users = new[] { user }
                };

                service.ChangeEmailAddress(user, "*****@*****.**");

                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Equal("*****@*****.**", user.UnconfirmedEmailAddress);
                service.FakeEntitiesContext.VerifyCommitChanges();
            }