public void Can_Edit_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); mock.Setup(m => m.Movies).Returns(new List <Movie> { new Movie { MovieId = 1, Name = "P1", ShowTime = new TimeSpan(12, 0, 0) }, new Movie { MovieId = 2, Name = "P2", ShowTime = new TimeSpan(13, 0, 0) }, new Movie { MovieId = 3, Name = "P3", ShowTime = new TimeSpan(14, 0, 0) } }.AsQueryable()); var controller = new CinemaController(mock.Object); // Act var movieResult1 = controller.EditMovie(1).Model as Movie; var movieResult2 = controller.EditMovie(2).Model as Movie; var movieResult3 = controller.EditMovie(3).Model as Movie; // Assert Assert.AreEqual(1, movieResult1.MovieId); Assert.AreEqual(2, movieResult2.MovieId); Assert.AreEqual(3, movieResult3.MovieId); }
public void Can_Show_All_Movies_By_Index() { // Arrange var mock = new Mock <ICinemaRepository>(); mock.Setup(m => m.Movies).Returns(new List <Movie> { new Movie { MovieId = 1, Name = "T1" }, new Movie { MovieId = 2, Name = "T2" }, new Movie { MovieId = 3, Name = "T3" }, }.AsQueryable()); var controller = new CinemaController(mock.Object); //Act var result = (controller.Index().Model as IEnumerable <Movie>).ToArray(); // Assert Assert.AreEqual(result.Length, 3); Assert.AreEqual("T1", result[0].Name); Assert.AreEqual("T2", result[1].Name); Assert.AreEqual("T3", result[2].Name); }
public void Can_Delete_Existent_Movie() { //Arrange var mock = new Mock <ICinemaRepository>(); mock.Setup(m => m.Movies).Returns(new List <Movie> { new Movie { MovieId = 1, Name = "T1", ShowTime = new TimeSpan(12, 0, 0) }, new Movie { MovieId = 2, Name = "T2", ShowTime = new TimeSpan(13, 0, 0) }, new Movie { MovieId = 3, Name = "T3", ShowTime = new TimeSpan(14, 0, 0) }, new Movie { MovieId = 4, Name = "T4", ShowTime = new TimeSpan(15, 0, 0) }, new Movie { MovieId = 5, Name = "T5", ShowTime = new TimeSpan(16, 0, 0) } }.AsQueryable()); var controller = new CinemaController(mock.Object); //Act var result = controller.DeleteMovie(1); //Assert mock.Verify(movies => movies.DeleteMovie(It.IsAny <int>()), Times.Once()); Assert.IsInstanceOf <ActionResult>(result); }
public void Cannot_Edit_Nonexistent_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); mock.Setup(movie => movie.Movies).Returns(new List <Movie> { new Movie { MovieId = 1, Name = "P1" }, new Movie { MovieId = 2, Name = "P2" }, new Movie { MovieId = 3, Name = "P3" }, }.AsQueryable()); var controller = new CinemaController(mock.Object); // Act var movieResult = controller.EditMovie(4).Model; // Assert Assert.IsNull(movieResult); }
public CinemaControllerTest() { modelFaker = new ModelFaker(); mockCinemaService = new Mock <ICinemaService>(); mockMapper = new Mock <IMapper>(); controllerUnderTest = new CinemaController( mockCinemaService.Object, mockMapper.Object); }
public void CinemaControllerBookNow(CustomerModel customermodel) { this.repository = new GenericRepository <TblBookingSeat>(); this.repositoryCustomer = new GenericRepository <TblCustomer>(); this.repositoryErrorLog = new GenericRepository <TblErrorLog>(); CinemaController cinemaController = new CinemaController(repository, repositoryCustomer, repositoryErrorLog); JsonResult result = cinemaController.BookTicket(customermodel) as JsonResult; // Assert Assert.IsNotNull(result); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1 form1 = new Form1(); RecreationalController recreationalController = new RecreationalController(form1); StoreController storeController = new StoreController(form1); RestaurantController restaurantController = new RestaurantController(form1); CinemaController cinemaController = new CinemaController(form1); Application.Run(form1); }
public void CinemaControllerIndex() { this.repository = new GenericRepository <TblBookingSeat>(); this.repositoryCustomer = new GenericRepository <TblCustomer>(); this.repositoryErrorLog = new GenericRepository <TblErrorLog>(); CinemaController cinemaController = new CinemaController(repository, repositoryCustomer, repositoryErrorLog); ViewResult result = cinemaController.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public void GivenInvalidParameterName_WhenCallingAction_ShouldGetBadRequest(string showName, string seatNumber) { // ARRANGE var controller = new CinemaController(_bookingServiceMock.Object, _cinemaShowServiceMock.Object, _seatServiceMock.Object); // ACT var response = controller.BookCinemaShow(showName, seatNumber) as ObjectResult; // ASSERT response.Should().NotBeNull(); response.StatusCode.Should().Be(400); }
public void GivenBookingAShow_WhenNotAbleToBookAShow_ShouldGetBadRequest() { // ARRANGE _bookingServiceMock.Setup(s => s.BookSeat(It.IsAny <string>(), It.IsAny <string>())).Returns(() => false); var controller = new CinemaController(_bookingServiceMock.Object, _cinemaShowServiceMock.Object, _seatServiceMock.Object); // ACT var response = controller.BookCinemaShow(_fixture.Create <string>(), _fixture.Create <string>()) as ObjectResult; // ASSERT response.Should().NotBeNull(); response.StatusCode.Should().Be(400); }
public void CinemaControllerUnBookSeat(UnBookModel unBook) { this.repository = new GenericRepository <TblBookingSeat>(); this.repositoryCustomer = new GenericRepository <TblCustomer>(); this.repositoryErrorLog = new GenericRepository <TblErrorLog>(); int SeatNum = unBook.SeatNumber; CinemaController cinemaController = new CinemaController(repository, repositoryCustomer, repositoryErrorLog); JsonResult result = cinemaController.UnBookTicket(SeatNum) as JsonResult; // Assert Assert.IsNotNull(result.Value); }
public void GivenInvalidShowName_WhenCallingAction_ShouldGetBadRequest(string showName) { // ARRANGE var controller = new CinemaController(_bookingServiceMock.Object, _cinemaShowServiceMock.Object, _seatServiceMock.Object); // ACT var response = controller.GetAvailabelSeats(showName); var result = response.Result as ObjectResult; // ASSERT result.Should().NotBeNull(); result.StatusCode.Should().Be(400); }
public void CinemaControllerMatchSecretCode(int TicketId, string SecretCode) { this.repository = new GenericRepository <TblBookingSeat>(); this.repositoryCustomer = new GenericRepository <TblCustomer>(); this.repositoryErrorLog = new GenericRepository <TblErrorLog>(); CinemaController cinemaController = new CinemaController(repository, repositoryCustomer, repositoryErrorLog); JsonResult result = cinemaController.CheckSecretCode(SecretCode, TicketId) as JsonResult; // Assert Assert.IsNotNull(result); }
public void GivenBookingAShow_WhenCallingActionExceptionOccurs_ShouldGetConflict() { // ARRANGE _bookingServiceMock.Setup(s => s.BookSeat(It.IsAny <string>(), It.IsAny <string>())).Returns(() => throw new Exception()); var controller = new CinemaController(_bookingServiceMock.Object, _cinemaShowServiceMock.Object, _seatServiceMock.Object); // ACT var response = controller.BookCinemaShow(_fixture.Create <string>(), _fixture.Create <string>()) as ObjectResult; // ASSERT response.Should().NotBeNull(); response.StatusCode.Should().Be(409); }
public void CinemaControllerCheckSecretCode(SecretModel modelTest) { this.repository = new GenericRepository <TblBookingSeat>(); this.repositoryCustomer = new GenericRepository <TblCustomer>(); this.repositoryErrorLog = new GenericRepository <TblErrorLog>(); int SeatNum = modelTest.SeatNumber; string SecretCode = modelTest.SecretCode; CinemaController cinemaController = new CinemaController(repository, repositoryCustomer, repositoryErrorLog); JsonResult result = cinemaController.CheckSecretCode(SecretCode, SeatNum) as JsonResult; // Assert Assert.IsNotNull(result.Value); }
public void GivenNoAvailableSeats_WhenCallingAction_ShouldGetNotFound() { // ARRANGE _seatServiceMock.Setup(s => s.GetAvailableSeats(It.IsAny <string>())).Returns(() => null); var controller = new CinemaController(_bookingServiceMock.Object, _cinemaShowServiceMock.Object, _seatServiceMock.Object); // ACT var response = controller.GetAvailabelSeats(_fixture.Create <string>()); var result = response.Result as ObjectResult; // ASSERT result.Should().NotBeNull(); result.StatusCode.Should().Be(404); }
public void GivenNoCinemaShows_WhenCallGetActiveCinemaShows_ShouldGetNotFound() { // ARRANGE _cinemaShowServiceMock.Setup(cs => cs.GetAvailableCinemaShows()).Returns(() => null); var controller = new CinemaController(_bookingServiceMock.Object, _cinemaShowServiceMock.Object, _seatServiceMock.Object); // ACT var response = controller.GetAvailableCinemaShows(); var result = response.Result as ObjectResult; // ASSERT result.Should().NotBeNull(); result.StatusCode.Should().Be(404); }
public void FilmsTest() { // Arrange var moq = new Mock <DataManager>(); CinemaController controller = new CinemaController(moq.Object); // Act var result = controller.Films(); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <DataManager>(viewResult.Model); }
public void Can_Save_Valid_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); var controller = new CinemaController(mock.Object); var movie = new Movie { MovieId = 1, Name = "Приключения Шурика", ShowTime = new TimeSpan(12, 0, 0) }; // Act var result = controller.EditMovie(movie); // Assert mock.Verify(m => m.SaveMovie(movie), Times.Once()); }
public void Cannot_Save_Invalid_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); var controller = new CinemaController(mock.Object); var movie = new Movie { MovieId = 1, Name = "Приключения Шурика", ShowTime = new TimeSpan(12, 0, 0) }; controller.ModelState.AddModelError("Error", "Error in model"); // Act var result = controller.EditMovie(movie); // Assert mock.Verify(m => m.SaveMovie(movie), Times.Never()); }
public void GivenHaveCinemaShows_WhenCallGetActiveCinemaShows_ShouldGetOk() { // ARRANGE var shows = _fixture.Create <IEnumerable <CinemaShow> >(); _cinemaShowServiceMock.Setup(cs => cs.GetAvailableCinemaShows()).Returns(shows); var controller = new CinemaController(_bookingServiceMock.Object, _cinemaShowServiceMock.Object, _seatServiceMock.Object); // ACT var response = controller.GetAvailableCinemaShows(); var result = response.Result as ObjectResult; // ASSERT result.Should().NotBeNull(); result.StatusCode.Should().Be(200); }
public void TestMethod1() { // Arrange var controller = new CinemaController(repository); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); // Act var response = controller.Get(10); // Assert Product product; Assert.IsTrue(response.TryGetContentValue <Product>(out product)); Assert.AreEqual(10, product.Id); }
public void Can_Create_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); var controller = new CinemaController(mock.Object); // Act var movie = controller.CreateMovie().Model as Movie; // Assert Assert.IsNotNull(movie); Assert.AreEqual(0, movie.MovieId); Assert.AreEqual(null, movie.Name); Assert.AreEqual(new TimeSpan(), movie.ShowTime); Assert.AreEqual(0, movie.Bookings.Count); }
public void Cannot_Delete_Nonexistent_Movie() { //Arrange var mock = new Mock <ICinemaRepository>(); mock.Setup(m => m.Movies).Returns(new List <Movie> { new Movie { MovieId = 1, Name = "T1", ShowTime = new TimeSpan(12, 0, 0) }, new Movie { MovieId = 2, Name = "T2", ShowTime = new TimeSpan(13, 0, 0) }, }.AsQueryable()); var controller = new CinemaController(mock.Object); //Act var result = controller.DeleteMovie(3); //Assert Assert.IsInstanceOf <HttpNotFoundResult>(result); Assert.AreEqual((result as HttpNotFoundResult).StatusCode, 404); }
public CinemaControllerTest() { _sqlCinemaService = new SqlCinemaService(_dbContext); _sqlRoomService = new SqlRoomService(_dbContext); _cinemaController = new CinemaController(_sqlCinemaService, _sqlRoomService); }
private void Awake() { instance = this; }