public async Task Write(Employee employee) { var emailAlreadyExists = await EmployeeReader.Any(employee.Email.Address); if (emailAlreadyExists) { var notification = new Notification("Email already registred"); NotificationStore.AddNotification(notification); return; } await EmployeeWriter.Write(employee); }
public async Task Any_When_EmailAddress_Exists_Should_Return_True( Employee employee) { var options = DbContextOptionsFactory.Create(nameof(Any_When_EmailAddress_Exists_Should_Return_True)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeReader(context); var actual = await sut.Any(employee.Email.Address); actual.Should().BeTrue(); } }
public async Task Any_When_EmailAddress_Does_Not_Exist_Should_Return_False( Employee employee, string someEmployeeEmail) { var options = DbContextOptionsFactory.Create(nameof(Any_When_EmailAddress_Does_Not_Exist_Should_Return_False)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeReader(context); var actual = await sut.Any(someEmployeeEmail); actual.Should().BeFalse(); } }