public async Task TestCreateChildrenAndExtraBedPolicy_Success_OkResponse() { //Arrange List <Room> roomList = new List <Room>(); MaxChildAndExtraBedPerRoomViewModel maxChildAndExtraBedPerRoomModel = new MaxChildAndExtraBedPerRoomViewModel() { HotelId = 5, RoomId = 332, RoomName = "Large", BedCount = 2, ExtraBedCount = 1, MaxChildren = 2, NoOfGuest = 4 }; ChildrenAndExtraBedPoliciesViewModel childrenAndExtraBedPoliciesViewModel = new ChildrenAndExtraBedPoliciesViewModel() { HotelId = 5, IsChildrenAllowed = true, MinChildAge = 0, MaxChildAge = 4, IsExtraCotAllowed = true, MinInfantAge = 2, MaxInfantAge = 5, IsExtraBedAllowed = true, CotPrice = 1000, CotPriceTypeId = 2, }; ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesModel = new ChildrenAndExtraBedPolicies(); childrenAndExtraBedPoliciesViewModel.ObjectState = ObjectState.Added; childrenAndExtraBedPoliciesViewModel.MaxChildAndExtraBedPerRoomList.Add(maxChildAndExtraBedPerRoomModel); ObjectState objectState = ObjectState.Added; mockPoliciesRepository.Setup(x => x.GetRoomsById(It.IsAny <List <MaxChildAndExtraBedPerRoomViewModel> >())).Returns(Task.FromResult(new BaseResult <List <Room> >() { Result = roomList })).Verifiable(); mockPoliciesRepository.Setup(a => a.SaveAndUpdateChildAndExtraBedPolicy(It.IsAny <ChildrenAndExtraBedPolicies>(), objectState)).Returns(Task.FromResult(new BaseResult <ChildrenAndExtraBedPolicies> { Result = new ChildrenAndExtraBedPolicies() })); mockPoliciesRepository.Setup(a => a.SaveAndUpdateChildAndExtraBedPolicy(It.IsAny <ChildrenAndExtraBedPolicies>(), objectState)).Returns(Task.FromResult(new BaseResult <ChildrenAndExtraBedPolicies> { Result = childrenAndExtraBedPoliciesModel })).Verifiable(); mockPoliciesRepository.Setup(a => a.UpdateRoomList(It.IsAny <List <Room> >())).Returns(Task.FromResult(new BaseResult <bool> { Result = true })).Verifiable(); //Act Task <IActionResult> actionResult = mockPoliciesController.CreateChildrenAndExtraBedPolicy(childrenAndExtraBedPoliciesViewModel); //Assert BaseResult <ChildrenAndExtraBedPolicies> saveOrUpdatechildrenAndExtraBedPolicies = (actionResult.Result as Microsoft.AspNetCore.Mvc.OkObjectResult).Value as BaseResult <ChildrenAndExtraBedPolicies>; Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)actionResult.Result).StatusCode, 200); Assert.IsNotNull(saveOrUpdatechildrenAndExtraBedPolicies); Assert.IsTrue(saveOrUpdatechildrenAndExtraBedPolicies.Result != null); }
public async Task TestCreateChildrenAndExtraBedPolicy_Exception_BySaveAndUpdateChildAndExtraBedPolicy_InternalServerError() { //Arrange List <Room> roomList = new List <Room>(); MaxChildAndExtraBedPerRoomViewModel maxChildAndExtraBedPerRoomModel = new MaxChildAndExtraBedPerRoomViewModel() { HotelId = 5, RoomId = 332, RoomName = "Large", BedCount = 2, ExtraBedCount = 1, MaxChildren = 2, NoOfGuest = 4 }; ChildrenAndExtraBedPoliciesViewModel childrenAndExtraBedPoliciesViewModel = new ChildrenAndExtraBedPoliciesViewModel() { HotelId = 5, IsChildrenAllowed = true, MinChildAge = 0, MaxChildAge = 4, IsExtraCotAllowed = true, MinInfantAge = 2, MaxInfantAge = 5, IsExtraBedAllowed = true, CotPrice = 1000, CotPriceTypeId = 2, }; childrenAndExtraBedPoliciesViewModel.ObjectState = ObjectState.Added; childrenAndExtraBedPoliciesViewModel.MaxChildAndExtraBedPerRoomList.Add(maxChildAndExtraBedPerRoomModel); ObjectState objectState = ObjectState.Added; mockPoliciesRepository.Setup(x => x.GetRoomsById(It.IsAny <List <MaxChildAndExtraBedPerRoomViewModel> >())).Returns(Task.FromResult(new BaseResult <List <Room> >() { Result = roomList })).Verifiable(); mockPoliciesRepository.Setup(x => x.SaveAndUpdateChildAndExtraBedPolicy(It.IsAny <ChildrenAndExtraBedPolicies>(), objectState)).Returns(Task.FromResult(new BaseResult <ChildrenAndExtraBedPolicies>() { IsError = true, ExceptionMessage = Helper.Common.GetMockException() })).Verifiable(); //Act Task <IActionResult> actionResult = mockPoliciesController.CreateChildrenAndExtraBedPolicy(childrenAndExtraBedPoliciesViewModel); //Assert mockPoliciesRepository.Verify(); Assert.IsTrue(actionResult != null); Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actionResult.Result).StatusCode, 500); }
/// <summary> /// Return the mapped ChildrenAndExtraBedPoliciesList /// </summary> /// <param name="MaxChildAndExtraBedPerRoom"></param> /// <returns>MaxChildAndExtraBedPerRoomViewModel</returns> public static BaseResult <List <MaxChildAndExtraBedPerRoomViewModel> > MapMaxChildAndExtraBedPerRoom(BaseResult <List <MaxChildAndExtraBedPerRoom> > maxChildAndExtraBedPerRoomViewModelListDetail) { BaseResult <List <MaxChildAndExtraBedPerRoomViewModel> > maxChildAndExtraBedPerRoomViewModelList = new BaseResult <List <MaxChildAndExtraBedPerRoomViewModel> >(); List <MaxChildAndExtraBedPerRoomViewModel> modelList = new List <MaxChildAndExtraBedPerRoomViewModel>(); foreach (var item in maxChildAndExtraBedPerRoomViewModelListDetail.Result) { MaxChildAndExtraBedPerRoomViewModel model = new MaxChildAndExtraBedPerRoomViewModel(); model.HotelId = item.HotelId; model.RoomId = item.RoomId; model.RoomName = item.RoomName; model.NoOfGuest = item.NoOfGuest; model.BedCount = item.BedCount; model.MaxChildren = item.MaxChildren; if (item.NoOfGuest == null) { model.NoOfGuest = 0; } else { model.NoOfGuest = item.NoOfGuest; } if (item.BedCount == null) { model.BedCount = 0; } else { model.BedCount = item.BedCount; } model.ExtraBedCount = item.ExtraBedCount; model.ExtraBedAllowed = item.ExtraBedAllowed; model.IsExtraBedAllowed = item.IsExtraBedAllowed; modelList.Add(model); } maxChildAndExtraBedPerRoomViewModelList.Result = modelList; return(maxChildAndExtraBedPerRoomViewModelList); }