public void ThrowArgumentNullException_WhenInvokedWithVisitIdParameterThatDoesNotExist() { //Arrange var dbContextMock = new Mock <ISportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); var expectedVisit = new Visit() { Id = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271325"), IsDeleted = true }; var data = new List <Visit> { new Visit { Id = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271325"), IsDeleted = false } }; var mockSet = new Mock <DbSet <Visit> >(); mockSet.SetupData(data); dbContextMock .Setup(x => x.Visits) .Returns(mockSet.Object); var visitService = new VisitService(dbContextMock.Object, mapperMock.Object); //Act && Assert Assert.ThrowsException <ArgumentNullException>(() => visitService.DeleteVisit(new Guid("0097a0eb-9411-4f1d-9ead-3997e6271325"))); }
public async Task <IActionResult> Delete(Guid id) { var visit = await _visitService.GetVisitById(id); await _visitService.DeleteVisit(visit); return(RedirectToAction("Index")); }
public IHttpActionResult Delete(int?id) { if (id == null) { return(BadRequest()); } VisitService service = CreateVisitService(); if (service.DeleteVisit(id.Value)) { return(Ok()); } return(InternalServerError()); }
public void InvokeSaveChangesMethod_WhenSportscardWithVisitIdThatExists() { //Arrange var dbContextMock = new Mock <ISportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); var expectedVisit = new Visit() { Id = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271325"), IsDeleted = true }; var data = new List <Visit> { new Visit { Id = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271325"), IsDeleted = false } }; var mockSet = new Mock <DbSet <Visit> >(); mockSet.SetupData(data); dbContextMock .Setup(x => x.Visits) .Returns(mockSet.Object); var visitService = new VisitService(dbContextMock.Object, mapperMock.Object); //Act visitService.DeleteVisit(expectedVisit.Id); //Assert dbContextMock.Verify(x => x.SaveChanges(), Times.Once); Assert.AreEqual(expectedVisit.IsDeleted, true); }