Exemplo n.º 1
0
        public void PostAsync_With_InValid_ModelState_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = "Invalid Model State";
            int    expectedStatusCode = 400;

            CreateAuditoriumModel createAuditoriumModel = new CreateAuditoriumModel
            {
                auditName     = "auditorium123",
                cinemaId      = 44,
                numberOfSeats = 5,
                seatRows      = 55
            };


            _auditoriumService = new Mock <IAuditoriumService>();
            AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object);

            auditoriumsController.ModelState.AddModelError("key", "Invalid Model State");


            //Act
            var result         = auditoriumsController.PostAsync(createAuditoriumModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse = (BadRequestObjectResult)result;
            var createdResult  = ((BadRequestObjectResult)result).Value;
            var errorResponse  = ((SerializableError)createdResult).GetValueOrDefault("key");
            var message        = (string[])errorResponse;


            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, message[0]);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
Exemplo n.º 2
0
        public void PostAsync_Create_Throw_DbException_Auditorium()
        {
            //Arrange
            string expectedMessage    = "Inner exception error message.";
            int    expectedStatusCode = 400;

            CreateAuditoriumModel createAuditoriumModel = new CreateAuditoriumModel
            {
                auditName     = "Auditorium55",
                cinemaId      = 24,
                numberOfSeats = 5,
                seatRows      = 6
            };

            CreateAuditoriumResultModel createAuditoriumResultModel = new CreateAuditoriumResultModel
            {
                Auditorium = new AuditoriumDomainModel
                {
                    Id        = 25,
                    Name      = createAuditoriumModel.auditName,
                    CinemaId  = createAuditoriumModel.cinemaId,
                    SeatsList = new List <SeatDomainModel>()
                },
                IsSuccessful = true
            };

            Task <CreateAuditoriumResultModel> responseTask = Task.FromResult(createAuditoriumResultModel);
            Exception         exception         = new Exception("Inner exception error message.");
            DbUpdateException dbUpdateException = new DbUpdateException("Error.", exception);

            _auditoriumService = new Mock <IAuditoriumService>();
            _auditoriumService.Setup(x => x.CreateAuditorium(It.IsAny <AuditoriumDomainModel>(),
                                                             It.IsAny <int>(),
                                                             It.IsAny <int>())).Throws(dbUpdateException);

            AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object);

            //Act
            var result          = auditoriumsController.PostAsync(createAuditoriumModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse  = (BadRequestObjectResult)result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
Exemplo n.º 3
0
        public void PostAsync_Create_createAuditoriumResultModel_IsSuccessful_False_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = "Error occured while creating new auditorium, please try again.";
            int    expectedStatusCode = 400;

            CreateAuditoriumModel createAuditoriumModel = new CreateAuditoriumModel
            {
                auditName     = "Auditorium55",
                cinemaId      = 24,
                numberOfSeats = 5,
                seatRows      = 6
            };

            CreateAuditoriumResultModel createAuditoriumResultModel = new CreateAuditoriumResultModel
            {
                Auditorium = new AuditoriumDomainModel
                {
                    Id        = 123,
                    CinemaId  = createAuditoriumModel.cinemaId,
                    Name      = createAuditoriumModel.auditName,
                    SeatsList = new List <SeatDomainModel>()
                },
                IsSuccessful = false,
                ErrorMessage = Messages.AUDITORIUM_CREATION_ERROR
            };
            Task <CreateAuditoriumResultModel> responseTask = Task.FromResult(createAuditoriumResultModel);

            _auditoriumService = new Mock <IAuditoriumService>();
            _auditoriumService.Setup(x => x.CreateAuditorium(It.IsAny <AuditoriumDomainModel>(),
                                                             It.IsAny <int>(),
                                                             It.IsAny <int>())).Returns(responseTask);
            AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object);


            //Act
            var result          = auditoriumsController.PostAsync(createAuditoriumModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse  = (BadRequestObjectResult)result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
Exemplo n.º 4
0
        public void PostAsync_Create_createAuditoriumResultModel_IsSuccessful_True_Auditorium()
        {
            //Arrange
            int expectedStatusCode = 201;

            CreateAuditoriumModel createAuditoriumModel = new CreateAuditoriumModel
            {
                auditName     = "Auditorium1",
                cinemaId      = 23,
                numberOfSeats = 5,
                seatRows      = 4
            };

            CreateAuditoriumResultModel createAuditoriumResultModel = new CreateAuditoriumResultModel
            {
                Auditorium = new AuditoriumDomainModel
                {
                    Id        = 15,
                    CinemaId  = createAuditoriumModel.cinemaId,
                    Name      = createAuditoriumModel.auditName,
                    SeatsList = new List <SeatDomainModel>()
                },
                IsSuccessful = true
            };
            Task <CreateAuditoriumResultModel> responseTask = Task.FromResult(createAuditoriumResultModel);

            _auditoriumService = new Mock <IAuditoriumService>();
            _auditoriumService.Setup(x => x
                                     .CreateAuditorium(It.IsAny <AuditoriumDomainModel>(), It.IsAny <int>(), It.IsAny <int>())).Returns(responseTask);

            AuditoriumsController auditoriumsController = new AuditoriumsController(_auditoriumService.Object);

            //Act
            var result                = auditoriumsController.PostAsync(createAuditoriumModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var createdResult         = ((CreatedResult)result).Value;
            var auditoriumDomainModel = (AuditoriumDomainModel)createdResult;

            //Assert
            Assert.IsNotNull(auditoriumDomainModel);
            Assert.AreEqual(createAuditoriumModel.cinemaId, auditoriumDomainModel.CinemaId);
            Assert.AreEqual(createAuditoriumModel.auditName, auditoriumDomainModel.Name);
            Assert.IsInstanceOfType(result, typeof(CreatedResult));
            Assert.AreEqual(expectedStatusCode, ((CreatedResult)result).StatusCode);
        }