public void Details_GuestDoesNotExist_ReturnsNotFoundResults() { // Arrange var guestsRepo = new Mock <IGuestService>(); guestsRepo.Setup(g => g.ReadSingle(It.IsAny <int>())).Throws(It.IsAny <Exception>()); var controller = new GuestController(guestsRepo.Object); // Act var result = controller.Details(123); // Assert Assert.That(result, Is.TypeOf <BadRequestResult>()); }
public void Details__NotNull_ViewResultIsNotNull() { //Arrange var guest = new GuestViewModel(); var mock = new Mock <IGuestService>(); mock.Setup(g => g.ReadSingle(guest.Id)); var controller = new GuestController(mock.Object); //Act ViewResult result = controller.Details(guest.Id) as ViewResult; //Assert Assert.IsNotNull(result); }
public void DetailsTest() { var mockS = new Mock <IGuestService>(); GuestViewModel guest = new GuestViewModel() { LastName = "Hasan" }; mockS.Setup(p => p.GetGuest(1)).ReturnsAsync(guest); GuestController guestController = new GuestController(mockS.Object); var result = guestController.Details(1).Result as ViewResult; Assert.AreEqual("Hasan", (result.Model as GuestViewModel).LastName); }
public void Details_GuestExists_ReturnsAViewResultWithGuest() { //Arrange var guestId = 1; var testGuest = new GuestViewModel() { Id = guestId }; var guestsRepo = new Mock <IGuestService>(); guestsRepo.Setup(g => g.ReadSingle(guestId)).Returns(testGuest); var controller = new GuestController(guestsRepo.Object); // Act var result = controller.Details(guestId); // Assert var viewResult = result as ViewResult; var model = viewResult.ViewData.Model as GuestViewModel; Assert.AreEqual(guestId, model.Id); }