public void BuyTest() { int id = 1; var fakeHttpContext = new Mock <HttpContext>(); var fakeIdentity = new GenericIdentity("*****@*****.**"); var principal = new GenericPrincipal(fakeIdentity, null); fakeHttpContext.Setup(t => t.User).Returns(principal); cartController.ControllerContext.HttpContext = fakeHttpContext.Object; mockIUnitOfWork.Setup(m => m.UserRepository.GetAll()).Returns(GetTestUser()); mockIUnitOfWork.Setup(m => m.TicketRepository.Get(id.ToString())).Returns(ticket); mockIUnitOfWork.Setup(m => m.FlightRepository.GetAll()).Returns(GetTestFlights); mockIUnitOfWork.Setup(m => m.BoughtTicketRepository.Create(boughtTicket)); var result = cartController.Buy(id); mockIUnitOfWork.Verify(x => x.TicketRepository.Delete('1'.ToString()), Times.Exactly(1)); Assert.NotNull(result); }
public void Task_Buy_Return_View() { Assert.Throws <NullReferenceException>(() => { var controller = new CartController(context); var Id = 1; var data = controller.Buy(Id); Assert.IsType <ViewResult>(data); }); }