public void ShouldWorkWithCorrectId() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(DetailsController).Assembly); var hotelServiceMock = new Mock<IHotelsService>(); Hotel hotelForTest = new Hotel() { Id = 1, Name = "Some name", Description = "Some description", Location = new Location() { Country = "Bulgaria", City = "Sofia", Address = "5th Street" }, Email = "*****@*****.**", Stars = 4 }; hotelServiceMock.Setup(x => x.GetById(It.IsAny<int>())) .Returns(hotelForTest); var hotelRoomsServiceMock = new Mock<IHotelRoomsService>(); hotelRoomsServiceMock.Setup(x => x.GetUniqueRoomTypesInHotel(It.IsAny<int>())) .Returns(new List<HotelRoom>().AsQueryable()); var controller = new DetailsController(hotelServiceMock.Object, hotelRoomsServiceMock.Object); var id = 1; controller.WithCallTo(x => x.HotelDetails(id)) .ShouldRenderView("HotelDetails") .WithModel<DetailsViewModel>( viewModel => { Assert.AreEqual(hotelForTest, viewModel.Hotel); }).AndModelError(""); }
public void IndexShouldReturnCorrectView() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(HomeController).Assembly); var homeServiceMock = new Mock<IHomeService>(); HomeController home = new HomeController(homeServiceMock.Object); ViewResult result = home.Index() as ViewResult; Assert.IsNotNull(result); }
public void BookingAreaAllControllerShouldReturnIndexView() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(AllController).Assembly); var hotelServiceMock = new Mock<IHotelsService>(); hotelServiceMock.Setup(x => x.GetAll()) .Returns(new List<Hotel>().AsQueryable); var controller = new AllController(hotelServiceMock.Object); controller.WithCallTo(x => x.Index()) .ShouldRenderView("Index") .WithModel<List<HotelViewModel>>() .AndNoModelErrors(); }