示例#1
0
        public async void BookMovie_ValidDetails_ShowBookedMovie()
        {
            try
            {
                //Arrange
                UserBookingDto userBookingDto =
                    new UserBookingDto()
                {
                    UserId = 1,
                    ShowId = 1,
                    Seat   = new List <SeatDto>()
                    {
                        new SeatDto()
                        {
                            SeatId = 1
                        }, new SeatDto()
                        {
                            SeatId = 2
                        }
                    },
                    MultiplexId = 1,
                    BookingDate = DateTime.Now
                };

                //auto mapper configuration
                var mockMapper = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile(new AutoMapperProfiles());
                });
                var mapper = mockMapper.CreateMapper();

                BookingsController controller = new BookingsController(repo: mockRepo.Object, mapper: mapper);

                //Act
                var result = await controller.BookMovie(userBookingDto);

                //Assert
                var okResult = result as OkObjectResult;
                if (okResult != null)
                {
                    Assert.NotNull(okResult);
                }

                var model = okResult.Value as IEnumerable <UserBookingReturnDto>;
                if (model.Count() > 0)
                {
                    Assert.NotNull(model);
                    Assert.NotNull(model?.FirstOrDefault().Id);
                    var expected = userBookingDto?.UserId;
                    var actual   = model?.FirstOrDefault().UserId;

                    Assert.Equal(expected: expected, actual: actual);
                }
            }
            catch (Exception ex)
            {
                //Assert
                Assert.False(false, ex.Message);
            }
        }
示例#2
0
        public async void BookMovie_InvalidSeatList_NotFound()
        {
            try
            {
                //Arrange
                UserBookingDto userBookingDto =
                    new UserBookingDto()
                {
                    UserId = 1,
                    ShowId = 1,
                    Seat   = new List <SeatDto>()
                    {
                        new SeatDto()
                        {
                            SeatId = 1
                        },
                        new SeatDto()
                        {
                            SeatId = 50
                        }
                    },
                    MultiplexId = 1,
                    BookingDate = DateTime.Now
                };

                //auto mapper configuration
                var mockMapper = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile(new AutoMapperProfiles());
                });
                var mapper = mockMapper.CreateMapper();

                BookingsController controller = new BookingsController(repo: mockRepo.Object, mapper: mapper);

                //Act
                var result = await controller.BookMovie(userBookingDto);

                //Assert
                var notFoundResult = result as NotFoundResult;
                if (notFoundResult != null)
                {
                    Assert.NotNull(notFoundResult);
                }
            }
            catch (Exception ex)
            {
                //Assert
                Assert.False(false, ex.Message);
            }
        }
示例#3
0
        public async void AddShow_ModelValidationFail_BadRequest()
        {
            try
            {
                //Arrange
                UserBookingDto userBookingDto =
                    new UserBookingDto()
                {
                    UserId = 1,
                    ShowId = 1,
                    Seat   = new List <SeatDto>()
                    {
                        new SeatDto()
                        {
                            SeatId = 1
                        },
                        new SeatDto()
                        {
                            SeatId = 2
                        }
                    },
                    BookingDate = DateTime.Now
                };

                //auto mapper configuration
                var mockMapper = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile(new AutoMapperProfiles());
                });
                var mapper = mockMapper.CreateMapper();

                BookingsController controller = new BookingsController(repo: mockRepo.Object, mapper: mapper);

                //Act
                var result = await controller.BookMovie(userBookingDto);

                //Assert
                var badRequestResult = result as BadRequestObjectResult;
                if (badRequestResult != null)
                {
                    Assert.NotNull(badRequestResult);
                }
            }
            catch (Exception ex)
            {
                //Assert
                Assert.False(false, ex.Message);
            }
        }