Exemple #1
0
        public async Task <BaseResult <bool> > ValidateRoomTypeRatePlanRequest(RoomTypeByHotelAndChannelManger request)
        {
            DynamicParameters paramCollection = ChannelManagerRequestMapper.CreateChannelMangerValidationRequest(request);
            BaseResult <List <ChannelManagerRequestValidationResponse> > validationResponse = new BaseResult <List <ChannelManagerRequestValidationResponse> >();

            switch (request.HotelCode)
            {
            case "TestCaseForException":
                try
                {
                    throw new Exception("Exception Thrown From Fake for Unit Test");
                }
                catch (Exception ex)
                {
                    validationResponse.IsError          = true;
                    validationResponse.ExceptionMessage = ex;
                }
                break;

            case "TestCaseForOkResponse":
                validationResponse.Result = new List <ChannelManagerRequestValidationResponse> {
                    new ChannelManagerRequestValidationResponse()
                };
                break;
            }
            // await iConnection.ExecuteStoredProcedure(Constants.StoredProcedure.ValidateChannelMangerRequest, paramCollection).ConfigureAwait(false);
            return(ChannelManagerResponseMapper.MapChannelManagerRequestValidationResponse(validationResponse));
        }
Exemple #2
0
        public async Task TestGetRoomTypesAndRatePlans_RatesArePresent_OkResponse()
        {
            RoomTypeByHotelAndChannelManger request = new RoomTypeByHotelAndChannelManger
            {
                HotelCode        = "IN10000002",
                ChannelManagerId = 1
            };

            mockChannelManagerRepository.Setup(a => a.ValidateRoomTypeRatePlanRequest(request)).Returns(Task.FromResult(new BaseResult <bool> {
                Result = true
            }));

            mockChannelManagerRepository.Setup(c => c.GetRoomTypesAndRatePlans(request)).Returns(Task.FromResult(new BaseResult <List <RoomTypeRatePlanResponse> > {
                Result = new List <RoomTypeRatePlanResponse>
                {
                    new RoomTypeRatePlanResponse {
                        RatePlanCode = "1", RatePlanDescription = "Tets Rate PLAN DESC", RatePlanName = "test Rate Plan", RoomTypeCode = "Test Room Type Code", RoomTypeDescription = "Test Room Tyep Desc", RoomTypeName = "Tets Room Tyep Neame"
                    }
                }
            }));

            IActionResult actioResult = await mockChannelManagerController.GetRoomTypesAndRatePlans(request);

            Assert.IsTrue(actioResult != null);
            Assert.IsTrue(actioResult is Microsoft.AspNetCore.Mvc.ObjectResult);
        }
Exemple #3
0
        public static DynamicParameters CreateChannelMangerValidationRequest(RoomTypeByHotelAndChannelManger request)
        {
            DynamicParameters paramCollection = new DynamicParameters();

            paramCollection.Add(Constants.StoredProcedureParameters.HotelCode, request.HotelCode);
            paramCollection.Add(Constants.StoredProcedureParameters.ChannelManagerId, request.ChannelManagerId);
            return(paramCollection);
        }
Exemple #4
0
        //public async Task<BaseResult<bool>> IsHotelValid(string hotelId)
        //{
        //    BaseResult<bool> response = new BaseResult<bool>();

        //    BaseResult<List<Hotel>> hotelList = await this.ihotelConnection.GetListByPredicate(a => a.Code == hotelId);
        //    if (hotelList == null || hotelList.Result == null || !hotelList.Result.Any())
        //    {
        //        response.Result = false;
        //        return response;
        //    }
        //    return response;
        //}

        //public async Task<BaseResult<bool>> IsHotelActive(string hotelId)
        //{
        //    BaseResult<bool> response = new BaseResult<bool>();
        //    BaseResult<List<Hotel>> hotelList = await ihotelConnection.GetListByPredicate(h => h.Code == hotelId && h.IsActive == true);
        //    if (hotelList == null && hotelList.Result == null || !hotelList.Result.Any())
        //    {
        //        response.Result = false;
        //        return response;
        //    }
        //    return response;
        //}

        public async Task <BaseResult <bool> > ValidateRoomTypeRatePlanRequest(RoomTypeByHotelAndChannelManger request)
        {
            DynamicParameters paramCollection = ChannelManagerRequestMapper.CreateChannelMangerValidationRequest(request);
            BaseResult <List <ChannelManagerRequestValidationResponse> > validationResponse =
                await iConnection.ExecuteStoredProcedure(Constants.StoredProcedure.ValidateChannelMangerRequest, paramCollection).ConfigureAwait(false);

            return(ChannelManagerResponseMapper.MapChannelManagerRequestValidationResponse(validationResponse));
        }
        public async Task <BaseResult <bool> > ValidateRoomTypeRatePlanRequest(RoomTypeByHotelAndChannelManger request)
        {
            BaseResult <bool> validationResponse = new BaseResult <bool>();

            if (request == null || string.IsNullOrEmpty(request.HotelCode) || request.ChannelManagerId == 0)
            {
                validationResponse.IsError   = true;
                validationResponse.ErrorCode = (int)Constants.ErrorCodes.RequiredFieldMissing;
                validationResponse.Message   = string.Format(Constants.ErrorMessage.RequiredFieldMissing, "Hotel Code, Channe Manager Id ");
                return(validationResponse);
            }
            return(await iChannelManager.ValidateRoomTypeRatePlanRequest(request).ConfigureAwait(false));
        }
Exemple #6
0
        public async Task TestGetRoomTypesAndRatePlans_NullRequest_RequiredFieldMissingResponse()
        {
            RoomTypeByHotelAndChannelManger request = null;

            mockChannelManagerRepository.Setup(c => c.GetRoomTypesAndRatePlans(request)).Returns(Task.FromResult(new BaseResult <List <RoomTypeRatePlanResponse> >()));
            IActionResult actioResult = await mockChannelManagerController.GetRoomTypesAndRatePlans(request);

            Assert.IsTrue(actioResult is BadRequestObjectResult);
            var result = actioResult as BadRequestObjectResult;
            BaseResult <bool> response = result.Value as BaseResult <bool>;

            Assert.AreEqual(response.ErrorCode, (int)Constants.ErrorCodes.RequiredFieldMissing);
            Assert.AreEqual(response.Message, string.Format(Constants.ErrorMessage.RequiredFieldMissing, "Hotel Code, Channe Manager Id "));
        }
Exemple #7
0
        public async Task TestGetRoomTypesAndRatePlans_ValidationRequest_Exception_InternalServerError()
        {
            RoomTypeByHotelAndChannelManger request = new RoomTypeByHotelAndChannelManger
            {
                HotelCode        = "IN10000002",
                ChannelManagerId = 1
            };

            mockChannelManagerRepository.Setup(a => a.ValidateRoomTypeRatePlanRequest(request)).Returns(Task.FromResult(new BaseResult <bool> {
                IsError = true, ExceptionMessage = Common.GetMockException()
            }));
            // mockChannelManagerRepository.Setup(c => c.GetRoomTypesAndRatePlans(request)).Returns(Task.FromResult(new BaseResult<List<RoomTypesRatePlan>> { IsError = true, ExceptionMessage = Common.GetMockException() }));
            // mockChannelManagerRepository.VerifyAll();
            IActionResult actioResult = await mockChannelManagerController.GetRoomTypesAndRatePlans(request);

            Assert.IsTrue(actioResult != null);
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actioResult).StatusCode, 500);
        }
Exemple #8
0
        public async Task TestGetRoomTypesAndRatePlans_RoomsAreNotPresent_NoRoomResponse()
        {
            RoomTypeByHotelAndChannelManger request = new RoomTypeByHotelAndChannelManger
            {
                HotelCode        = "IN10000002",
                ChannelManagerId = 1
            };
            //  mockChannelManagerRepository.Setup(c => c.GetRoomTypesAndRatePlans(request)).Returns(Task.FromResult(new BaseResult<List<RoomTypesRatePlan>>()));
            //mockChannelManagerRepository.Setup(a => a.ValidateRoomTypeRatePlanRequest(request)).Returns(Task.FromResult(new BaseResult<bool> { ErrorCode=101}));
            IActionResult actioResult = await channelManagerController.GetRoomTypesAndRatePlans(request);

            Assert.IsTrue(actioResult is BadRequestObjectResult);
            var result = actioResult as BadRequestObjectResult;
            BaseResult <bool> response = result.Value as BaseResult <bool>;

            Assert.AreEqual(response.ErrorCode, (int)Constants.ErrorCodes.NoRoom);
            Assert.IsTrue(String.Compare(response.Message, string.Format(Constants.ErrorMessage.NoRooms, request.HotelCode), StringComparison.InvariantCultureIgnoreCase) == 0);
        }
Exemple #9
0
        public async Task TestGetRoomTypesAndRatePlans_RatesAreNotPresent_NoRateResponse()
        {
            RoomTypeByHotelAndChannelManger request = new RoomTypeByHotelAndChannelManger
            {
                HotelCode        = "IN10000002",
                ChannelManagerId = 1
            };

            mockChannelManagerRepository.Setup(a => a.ValidateRoomTypeRatePlanRequest(request)).Returns(Task.FromResult(new BaseResult <bool> {
                Result = true
            }));
            mockChannelManagerRepository.Setup(c => c.GetRoomTypesAndRatePlans(request)).Returns(Task.FromResult(new BaseResult <List <RoomTypeRatePlanResponse> > ()));
            mockChannelManagerRepository.Setup(c => c.GetRoomTypesAndRatePlans(request)).Returns(Task.FromResult(new BaseResult <List <RoomTypeRatePlanResponse> > {
                Result = null
            }));
            // mockChannelManagerRepository.VerifyAll();
            IActionResult actioResult = await mockChannelManagerController.GetRoomTypesAndRatePlans(request);

            Assert.IsTrue(actioResult != null);
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actioResult).StatusCode, 204);
        }
        public async Task <IActionResult> GetRoomTypesAndRatePlans([FromBody] RoomTypeByHotelAndChannelManger request)
        {
            BaseResult <List <RoomTypeRatePlanResponse> > roomRateResponse = new BaseResult <List <RoomTypeRatePlanResponse> >();
            BaseResult <bool> requestValidationResponse = new BaseResult <bool>();

            requestValidationResponse = await ValidateRoomTypeRatePlanRequest(request);

            if (requestValidationResponse == null || !requestValidationResponse.Result && requestValidationResponse.IsError && requestValidationResponse.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }

            if (!requestValidationResponse.Result)
            {
                return(new BadRequestObjectResult(requestValidationResponse));
            }
            if (requestValidationResponse.Result)
            {
                roomRateResponse = await iChannelManager.GetRoomTypesAndRatePlans(request);
            }
            if (roomRateResponse.IsError && roomRateResponse.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }
            if (roomRateResponse.Result == null || !roomRateResponse.Result.Any())
            {
                return(new NoContentResult());
            }

            //if (!IsValidRequest(request, response))
            //{
            //    return new BadRequestObjectResult(response);
            //}

            //if (!IsValidHotel(request.HotelId, response).Result)
            //{
            //    return new BadRequestObjectResult(response);
            //}
            return(Ok(roomRateResponse));
        }
Exemple #11
0
        public async Task <BaseResult <List <RoomTypeRatePlanResponse> > > GetRoomTypesAndRatePlans(RoomTypeByHotelAndChannelManger request)
        {
            //DynamicParameters paramCollection = RequestMapper.CreateChannelMangerValidationRequest(request);
            // return await iRoomConnection.ExecuteStoredProcedure(Constants.StoredProcedure.GetRoomTypesAndRatePlans, paramCollection).ConfigureAwait(false);

            BaseResult <List <RoomTypeRatePlanResponse> > roomRatePlanList = new BaseResult <List <RoomTypeRatePlanResponse> >
            {
                Result = new List <RoomTypeRatePlanResponse>()
            };

            //roomRatePlanList.Result.Add(new RoomTypeRatePlanResponse { RoomTypeCode = "Test Room Type", RatePlanCode = "Test Rate Plan Code" });
            roomRatePlanList.Result.Add(new RoomTypeRatePlanResponse {
                RatePlanCode        = "1", RatePlanDescription = "Tets Rate PLAN DESC", RatePlanName = "test Rate Plan", RoomTypeCode = "Test Room Type Code",
                RoomTypeDescription = "Test Room Tyep Desc", RoomTypeName = "Tets Room Tyep Neame"
            });


            return(roomRatePlanList);
        }
Exemple #12
0
        public async Task <BaseResult <List <RoomTypeRatePlanResponse> > > GetRoomTypesAndRatePlans(RoomTypeByHotelAndChannelManger request)
        {
            DynamicParameters paramCollection = ChannelManagerRequestMapper.CreateChannelMangerValidationRequest(request);
            BaseResult <List <RoomTypesRatePlan> > roomRateResponse = await iRoomConnection.ExecuteStoredProcedure(Constants.StoredProcedure.GetRoomTypesAndRatePlans, paramCollection).ConfigureAwait(false);

            return(ChannelManagerResponseMapper.MapRoomTypeRatePlanResponse(roomRateResponse));// await iRoomConnection.ExecuteStoredProcedure(Constants.StoredProcedure.GetRoomTypesAndRatePlans, paramCollection).ConfigureAwait(false);
        }