public void RemoveTicket_Does_Nothing_When_Ticket_Not_Found() { var contextMock = new Mock <ISupportAppContext>(); var ticketSetMock = new Mock <DbSet <Ticket> >(); contextMock.Setup(c => c.Set <Ticket>()) .Returns(ticketSetMock.Object); var sut = new TicketsModifier(contextMock.Object); contextMock.Setup(c => c.FindById <Ticket>(232)) .Returns((Ticket)null); //act sut.RemoveTicket(232); ticketSetMock.Verify(c => c.Remove(It.IsAny <Ticket>()), Times.Never); contextMock.Verify(c => c.SaveChanges(), Times.Never); }
public void RemoveTicket_Removes_Ticket_From_Database_By_Id() { var fixture = new Fixture(); var contextMock = new Mock <ISupportAppContext>(); var ticketSetMock = new Mock <DbSet <Ticket> >(); contextMock.Setup(c => c.Set <Ticket>()) .Returns(ticketSetMock.Object); var sut = new TicketsModifier(contextMock.Object); var ticket = fixture.Create <Ticket>(); contextMock.Setup(c => c.FindById <Ticket>(ticket.Id)) .Returns(ticket); //act sut.RemoveTicket(ticket.Id); ticketSetMock.Verify(c => c.Remove(ticket)); contextMock.Verify(c => c.SaveChanges()); }