public async Task ShouldDeleteCrew() { // Create 2 crews await CreateCrew(_crewName2); await CreateCrew(_crewName3); // Delete the first CrewService crewService = new CrewService(_dbContext, _mainEventProvider); CrewController crewController = new CrewController(crewService); CrewVm crewVm = new CrewVm { CrewId = 2 }; await crewController.DeleteCrewAsync(crewVm); // Check that we have deleted only one // Check that the others still has data Crew crew1 = _dbContext.Crews.Find(1); Assert.IsNotNull(crew1); Crew crew2 = _dbContext.Crews.Find(2); Assert.IsNull(crew2); Crew crew3 = _dbContext.Crews.Find(3); Assert.IsNotNull(crew3); Assert.AreEqual(_crewName3, crew3.Name); }
public void ShouldNotDeleteCrewIfDoesntExist() { CrewService crewService = new CrewService(_dbContext, _mainEventProvider); CrewController crewController = new CrewController(crewService); var ex = Assert.ThrowsAsync <HttpException>(async() => { ActionResult <CrewVm> result = await crewController.DeleteCrewAsync(new CrewVm { CrewId = 123, CrewName = "New Name" }); }); Assert.That(ex.Message == "Fant ikke arbeidslaget: New Name"); }