Exemplo n.º 1
0
        public void TicketManager_CancelTicket_ClosedSession()
        {
            //Arrange
            var seatManager  = Mock.Of <ISeatManager>();
            var priceManager = Mock.Of <IPriceManager>();
            var dataContext  = Mock.Of <IDataContext>();

            var session = new Session()
            {
                TimeAndDate = new DateTime(2014, 10, 26)
            };

            session.Close();
            var seat = new Seat()
            {
                Row = Session.NUMBER_OF_ROWS, SeatNumber = Session.NUMBER_OF_SEATS, Session = session, Reserved = true
            };
            var ticket = new Ticket()
            {
                Price = 7, Seat = seat, TimeAndDate = DateTime.Now
            };

            var target = new TicketManager(seatManager, priceManager, dataContext);

            //Act
            Action action = () => { target.CancelTicket(ticket); };

            //Assert
            action.ShouldThrow <CinematicException>().WithMessage(Messages.SessionIsClosedCannotReturnTickets);
        }
Exemplo n.º 2
0
        public void TicketManager_CancelTicket_TicketParamNullException()
        {
            //Arrange
            var seatManager  = Mock.Of <ISeatManager>();
            var priceManager = Mock.Of <IPriceManager>();
            var dataContext  = Mock.Of <IDataContext>();

            var target = new TicketManager(seatManager, priceManager, dataContext);

            //Act
            Action action = () => { target.CancelTicket(null); };

            //Assert
            action.ShouldThrow <ArgumentNullException>().WithMessage(new ArgumentNullException("ticket").Message);
        }
Exemplo n.º 3
0
        public void TicketManager_CancelTicket_Right()
        {
            //Arrange
            var seatManagerMock  = new Mock <ISeatManager>();
            var priceManagerMock = new Mock <IPriceManager>();
            var dataContextMock  = new Mock <IDataContext>();

            seatManagerMock.Setup(m => m.DeallocateSeat(It.IsAny <Seat>())).Returns <Seat>((s) =>
            {
                s.Reserved = false;
                return(s);
            });

            dataContextMock.Setup(m => m.Remove(It.IsAny <Ticket>())).Callback <Ticket>((t) =>
            {
                t.Id = 1;
            });

            var session = new Session()
            {
                TimeAndDate = new DateTime(2014, 10, 26)
            };
            var seat = new Seat()
            {
                Row = Session.NUMBER_OF_ROWS, SeatNumber = Session.NUMBER_OF_SEATS, Session = session, Reserved = true
            };
            var ticket = new Ticket()
            {
                Price = 7, Seat = seat, TimeAndDate = DateTime.Now
            };

            var target = new TicketManager(seatManagerMock.Object, priceManagerMock.Object, dataContextMock.Object);

            //Act
            target.CancelTicket(ticket);

            //Assert
            ticket.Seat.Reserved.Should().BeFalse();
            dataContextMock.Verify(m => m.Remove(It.IsAny <Ticket>()), Times.Once);
        }