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(); }
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); }
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 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 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(); }
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); }
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); }
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 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); }
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 == "*****@*****.**")); }
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 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 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 == "*****@*****.**")); }