public async Task TestUpdateAllocations_NullRequest_RequiredFieldMissingResponse() { UpdateAllocationBaseRequest baseRequest = null; UpdateAllocationsRequest request = null; mockChannelManagerRepository.Setup(c => c.UpdateAllocations(request)).Returns(Task.FromResult(new BaseResult <bool>())); IActionResult actioResult = await mockChannelManagerController.UpdateAllocations(baseRequest); 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 manger Id, Room Types and Rate Plans ")); }
public async Task TestUpdateAllocations_HotelCodeNull_RequiredFieldMissingResponse() { UpdateAllocationBaseRequest baseRequest = new UpdateAllocationBaseRequest { UpdateAllocationsValidationRequest = new UpdateAllocationsValidationRequest() }; baseRequest.UpdateAllocationsValidationRequest.HotelCode = String.Empty; IActionResult actioResult = await mockChannelManagerController.UpdateAllocations(baseRequest); 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 manger Id, Room Types and Rate Plans ")); }
public async Task <IActionResult> UpdateAllocations([FromBody] UpdateAllocationBaseRequest request) { BaseResult <bool> requestValidationResponse = new BaseResult <bool>(); if (request == null) { requestValidationResponse.IsError = true; requestValidationResponse.Message = string.Format(Constants.ErrorMessage.RequiredFieldMissing, "Hotel Code, Channe manger Id, Room Types and Rate Plans "); requestValidationResponse.ErrorCode = (int)Constants.ErrorCodes.RequiredFieldMissing; return(new BadRequestObjectResult(requestValidationResponse)); } requestValidationResponse = await ValidateUpdateAllocationRequest(request.UpdateAllocationsValidationRequest); if (!requestValidationResponse.Result && requestValidationResponse.IsError && requestValidationResponse.ExceptionMessage != null) { return(new StatusCodeResult(500)); } if (!requestValidationResponse.Result) { return(new BadRequestObjectResult(requestValidationResponse)); } //foreach(UpdateAllocationsRequest allocationRequest in request.UpdateAllocationsRequest) //{ // try // { // BaseResult<bool> updateAllocationResponse = await iChannelManager.UpdateAllocations(allocationRequest).ConfigureAwait(false); // if(updateAllocationResponse.IsError) // { // //Log the error // } // } // catch(Exception ex) // { // } //} return(Ok(requestValidationResponse)); // return await iChannelManager.ValidateRoomTypeRatePlanRequest(request).ConfigureAwait(false); }
public async Task Test_ValidateUpdateAllocationRequest_Success_OkResponse() { UpdateAllocationBaseRequest baseRequest = new UpdateAllocationBaseRequest { UpdateAllocationsValidationRequest = new UpdateAllocationsValidationRequest() }; baseRequest.UpdateAllocationsValidationRequest.HotelCode = "TestCaseForOkResponse"; baseRequest.UpdateAllocationsValidationRequest.ChannelManagerId = 1; baseRequest.UpdateAllocationsValidationRequest.RoomTypeRatePlanList.Add(new RoomTypeRatePlan { RatePlanCode = "Test Rate Plan Code", RoomTypeCode = "Test Room Type Code" }); //mockChannelManagerRepository.Setup(m => m.ValidateUpdateAllocationRequest(baseRequest.UpdateAllocationsValidationRequest)).Returns(Task.FromResult(new BaseResult<bool> { Result = true })); //mockChannelManagerRepository.Setup(c => c.UpdateAllocations(baseRequest.UpdateAllocationsRequest)).Returns(Task.FromResult(new BaseResult<bool>())); // IActionResult actioResult = await mockChannelManagerController.UpdateAllocations(baseRequest); IActionResult actioResult = await fakeChannelManagerController.UpdateAllocations(baseRequest); Assert.IsTrue(actioResult != null); Assert.IsTrue(actioResult is Microsoft.AspNetCore.Mvc.ObjectResult); }
public async Task TestUpdateAllocationsRequestValidationResponse_Exception_InternalServerError() { UpdateAllocationBaseRequest baseRequest = new UpdateAllocationBaseRequest { UpdateAllocationsValidationRequest = new UpdateAllocationsValidationRequest(), }; baseRequest.UpdateAllocationsRequest.Add(new UpdateAllocationsRequest()); baseRequest.UpdateAllocationsValidationRequest.HotelCode = "TestCaseForException"; baseRequest.UpdateAllocationsValidationRequest.ChannelManagerId = 1; baseRequest.UpdateAllocationsValidationRequest.RoomTypeRatePlanList.Add(new RoomTypeRatePlan { RatePlanCode = "Test Rate Plan Code", RoomTypeCode = "Test Room Type Code" }); //mockChannelManagerRepository.Setup(m => m.ValidateUpdateAllocationRequest(baseRequest.UpdateAllocationsValidationRequest)).Returns(Task.FromResult(new BaseResult<bool> {Result = false,ExceptionMessage =Common.GetMockException(),IsError = true })); //mockChannelManagerRepository.Setup(c => c.UpdateAllocations(baseRequest.UpdateAllocationsRequest[0])).Returns(Task.FromResult(new BaseResult<bool>())); IActionResult actioResult = await fakeChannelManagerController.UpdateAllocations(baseRequest); //IActionResult actioResult = await channelManagerController.UpdateAllocations(baseRequest); Assert.IsTrue(actioResult != null); Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actioResult).StatusCode, 500); }
public async Task TestUpdateAllocations_RoomTypesRatesCombinationAreNotPresent_RoomAndRateNotFound() { UpdateAllocationBaseRequest baseRequest = new UpdateAllocationBaseRequest { UpdateAllocationsValidationRequest = new UpdateAllocationsValidationRequest() }; baseRequest.UpdateAllocationsValidationRequest.HotelCode = "IN10000008"; baseRequest.UpdateAllocationsValidationRequest.ChannelManagerId = 1; baseRequest.UpdateAllocationsValidationRequest.RoomTypeRatePlanList.Add(new RoomTypeRatePlan { RatePlanCode = "Test Rate Plan Code", RoomTypeCode = "Test Room Type Code" }); // mockChannelManagerRepository.Setup(c => c.UpdateAllocations(request)).Returns(Task.FromResult(new BaseResult<bool>())); // IActionResult actioResult = await mockChannelManagerController.UpdateAllocations(baseRequest); IActionResult actioResult = await channelManagerController.UpdateAllocations(baseRequest); 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.NoRate); Assert.IsTrue(String.Compare(response.Message, Constants.ErrorMessage.NoRates, StringComparison.InvariantCultureIgnoreCase) == 0); }