public async Task Cannot_add_AccountingStaff_when_it_already_exists() { const string ACCOUNTING_STAFF_ID = "EMP21"; const string FIRST_NAME = "First Name"; const string LAST_NAME = "Last Name"; const string MOBILE = "0718958874"; using (var context = new ProcurementDbContext(ContextOptions)) { AccountingStaffsController accountingStaffsController = new AccountingStaffsController(context); AccountingStaff accountingStaff = new AccountingStaff { StaffId = ACCOUNTING_STAFF_ID, FirstName = FIRST_NAME, LastName = LAST_NAME, MobileNo = MOBILE }; try { await accountingStaffsController.PostAccountingStaff(accountingStaff); } catch (Exception exception) { Assert.NotNull(exception); return; } Assert.True(false); } }
public async Task Can_add_new_AccountingStaff_when_it_not_existing() { const string ACCOUNTING_STAFF_ID = "EMP24"; const string FIRST_NAME = "First Name"; const string LAST_NAME = "Last Name"; const string MOBILE = "0718958874"; using (var context = new ProcurementDbContext(ContextOptions)) { AccountingStaffsController accountingStaffsController = new AccountingStaffsController(context); AccountingStaff accountingStaff = new AccountingStaff { StaffId = ACCOUNTING_STAFF_ID, FirstName = FIRST_NAME, LastName = LAST_NAME, MobileNo = MOBILE }; var result = await accountingStaffsController.PostAccountingStaff(accountingStaff); var viewResult = Assert.IsType <ActionResult <AccountingStaff> >(result); var actionResult = Assert.IsType <CreatedAtActionResult>(viewResult.Result); var model = Assert.IsType <AccountingStaff>(actionResult.Value); Assert.Equal(ACCOUNTING_STAFF_ID, model.StaffId); } }