public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Gender,Birthday,Address,PhoneNumber,Department,Email")] Employee employee) { if (ModelState.IsValid) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <ActionResult <Employee> > PostTodoItem(Employee data) { _context.Employees.Add(data); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetEmployees), new { id = data.Id }, data)); }
public async Task Remove_Should_Delete_Employee(Employee employee) { var options = DbContextOptionsFactory.Create(nameof(Remove_Should_Delete_Employee)); using (var context = new EmployeeManagerContext(options)) { context.Add(employee); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeWriter(context); await sut.Remove(employee); employee.DeletedAt.Should().NotBeNull(); } }
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 Read_When_EmployeeId_Exists_Should_Return_Employee(Employee employee) { var options = DbContextOptionsFactory.Create(nameof(Read_When_EmployeeId_Exists_Should_Return_Employee)); 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.Read(employee.Id); actual.Should().NotBeNull(); actual.Value.Id.Should().Be(employee.Id); } }
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(); } }
public async Task Read_When_EmployeeId_Does_Not_Exist_Should_Return_Maybe_None( Employee employee, int someEmployeeId) { var options = DbContextOptionsFactory.Create(nameof(Read_When_EmployeeId_Does_Not_Exist_Should_Return_Maybe_None)); 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.Read(someEmployeeId); actual.Should().Be(Maybe <Employee> .None); } }
public async Task Read_Should_Paginated_Employees(List <Employee> employees) { const int pageIndex = 1; const int pageSize = 1; var options = DbContextOptionsFactory.Create(nameof(Read_Should_Paginated_Employees)); using (var context = new EmployeeManagerContext(options)) { context.AddRange(employees); await context.SaveChangesAsync(); } using (var context = new EmployeeManagerContext(options)) { var sut = new EmployeeReader(context); var actual = await sut.Read(pageIndex, pageSize); actual.Count.Should().Be(pageSize); } }