public async Task Cannot_add_SiteManager_when_it_already_exists() { const string SITE_MANAGER_ID = "EMP1"; const string FIRST_NAME = "First Name"; const string LAST_NAME = "Last Name"; const string MOBILE = "0718958874"; using (var context = new ProcurementDbContext(ContextOptions)) { SiteManagersController siteManagersController = new SiteManagersController(context); SiteManager siteManager = new SiteManager { StaffId = SITE_MANAGER_ID, FirstName = FIRST_NAME, LastName = LAST_NAME, MobileNo = MOBILE };; try { await siteManagersController.PostSiteManager(siteManager); } catch (Exception exception) { Assert.NotNull(exception); return; } Assert.True(false); } }
public async Task Can_add_new_SiteManager_when_it_not_existing() { const string SITE_MANAGER_ID = "EMP4"; const string FIRST_NAME = "First Name"; const string LAST_NAME = "Last Name"; const string MOBILE = "0718958874"; using (var context = new ProcurementDbContext(ContextOptions)) { SiteManagersController siteManagersController = new SiteManagersController(context); SiteManager siteManager = new SiteManager { StaffId = SITE_MANAGER_ID, FirstName = FIRST_NAME, LastName = LAST_NAME, MobileNo = MOBILE }; var result = await siteManagersController.PostSiteManager(siteManager); var viewResult = Assert.IsType <ActionResult <SiteManager> >(result); var actionResult = Assert.IsType <CreatedAtActionResult>(viewResult.Result); var model = Assert.IsType <SiteManager>(actionResult.Value); Assert.Equal(SITE_MANAGER_ID, model.StaffId); } }