/// <summary> /// Maps list of facilities to HotelfacilityTypeViewModel /// </summary> /// <param name="facilityList"></param> /// <param name="facilityTypeList"></param> /// <returns>List<HotelFacilityTypeViewModel></returns> public static BaseResult <List <HotelFacilityTypeViewModel> > MapHotelFacilityType(BaseResult <List <FacilityViewModel> > facilityList, BaseResult <List <HotelFacilityType> > facilityTypeList) { BaseResult <List <HotelFacilityTypeViewModel> > responseModelList = new BaseResult <List <HotelFacilityTypeViewModel> >(); List <HotelFacilityTypeViewModel> modelList = new List <HotelFacilityTypeViewModel>(); foreach (var item in facilityTypeList.Result) { List <HotelFacility> facility = new List <HotelFacility>(); List <HotelFacility> facilityWithoutType = new List <HotelFacility>(); HotelFacilityTypeViewModel hotelFacilityTypeModel = new HotelFacilityTypeViewModel { FacilityTypeId = item.Id, FacilityTypeName = item.Name, FacilityGroupId = item.FacilityGroupId, // FacilityList = facility }; foreach (var facilities in facilityList.Result) { if (facilities.FacilityTypeId == item.Id && facilities.IsActive) { // facility.Add(facilities); hotelFacilityTypeModel.FacilityList.Add(facilities); } } modelList.Add(hotelFacilityTypeModel); } responseModelList.Result = modelList; return(responseModelList); }
public async Task TestCreateHotelFacilityRelation_SuccessOkResponse() { //Arrange var userName = "******"; var id = 1; var facilities = new FacilityViewModel() { Id = 1, FacilityGroupId = 1, FacilityTypeId = 1, IsSelected = true, IsActive = true, Name = "ABC" }; var facilityType = new HotelFacilityTypeViewModel() { FacilityTypeId = 1, FacilityGroupId = 1, FacilityTypeName = "TypeName", }; facilityType.FacilityList.Add(facilities); var facilityGroup = new HotelFacilityGroupViewModel() { FacilityGroupId = 1, FacilityGroupName = "Group1", IconPath = "", }; facilityGroup.HotelFacilityTypes.Add(facilityType); var facilityModel = new HotelFacilityViewModel() { HotelId = 73, }; facilityModel.FacilityGroupList.Add(facilityGroup); mockFacilitiesRepository.Setup(x => x.InsertAndUpdateHotelFacilityRelation(It.IsAny <HotelFacilityViewModel>(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <long>() { Result = 1 })); //Act IActionResult result = await mockFacilitiesController.CreateHotelFacilityRelation(facilityModel); BaseResult <long> finalResult = (result as Microsoft.AspNetCore.Mvc.OkObjectResult).Value as BaseResult <long>; //Assert Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)result).StatusCode, 200); Assert.IsNotNull(finalResult); Assert.IsTrue(!finalResult.IsError); Assert.IsTrue(finalResult.Result != default(long)); Assert.IsTrue(finalResult.Result == id); }
public void TestCreateHotelFacilityRelation_Failed_Error() { //Arrange var facilities = new FacilityViewModel() { Id = 1, FacilityGroupId = 1, FacilityTypeId = 1, IsSelected = true, IsActive = true, Name = "ABC" }; var facilityType = new HotelFacilityTypeViewModel() { FacilityTypeId = 1, FacilityGroupId = 1, FacilityTypeName = "TypeName", }; facilityType.FacilityList.Add(facilities); var facilityGroup = new HotelFacilityGroupViewModel() { FacilityGroupId = 1, FacilityGroupName = "Group1", IconPath = "", }; facilityGroup.HotelFacilityTypes.Add(facilityType); var facilityModel = new HotelFacilityViewModel() { HotelId = 73, }; facilityModel.FacilityGroupList.Add(facilityGroup); mockFacilitiesRepository.Setup(x => x.InsertAndUpdateHotelFacilityRelation(It.IsAny <HotelFacilityViewModel>(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <long>() { IsError = true, ExceptionMessage = Helper.Common.GetMockException() })).Verifiable(); //Act var result = mockFacilitiesController.CreateHotelFacilityRelation(facilityModel); //Assert mockFacilitiesRepository.Verify(); Assert.IsTrue(result.Result is StatusCodeResult); Assert.AreEqual(((StatusCodeResult)result.Result).StatusCode, 500); }
/// <summary> /// Maps HotelFacilityTypeViewModel to HotelFacilityGroupViewModel /// </summary> /// <param name="hotelFacilityGroupList"></param> /// <param name="hotelFacilityViewModel"></param> /// <returns>List<HotelFacilityGroupViewModel></returns> public static BaseResult <List <HotelFacilityGroupViewModel> > MapHotelFacilityGroup(BaseResult <List <FacilityViewModel> > hotelFacilityList, BaseResult <List <HotelFacilityGroup> > hotelFacilityGroupList, BaseResult <List <HotelFacilityTypeViewModel> > hotelFacilityViewModel) { BaseResult <List <HotelFacilityGroupViewModel> > responseModelList = new BaseResult <List <HotelFacilityGroupViewModel> >(); List <HotelFacilityGroupViewModel> modelList = new List <HotelFacilityGroupViewModel>(); List <HotelFacilityTypeViewModel> facilityTypeModelList = new List <HotelFacilityTypeViewModel>(); foreach (var item in hotelFacilityGroupList.Result) { List <HotelFacility> facilities = new List <HotelFacility>(); List <HotelFacilityTypeViewModel> facilityTypeList = new List <HotelFacilityTypeViewModel>(); HotelFacilityTypeViewModel hotelFacilityTypeModel = new HotelFacilityTypeViewModel { FacilityGroupId = item.Id, }; foreach (var facility in hotelFacilityList.Result) { if (facility.FacilityTypeId == null && facility.FacilityGroupId == item.Id && facility.IsActive) { hotelFacilityTypeModel.FacilityList.Add(facility); } } if (hotelFacilityTypeModel.FacilityList.Count > 0) { hotelFacilityViewModel.Result.Add(hotelFacilityTypeModel); } HotelFacilityGroupViewModel hotelfacilityGroupModel = new HotelFacilityGroupViewModel { FacilityGroupId = item.Id, FacilityGroupName = item.Name, IconPath = item.IconPath }; foreach (var facilityTypes in hotelFacilityViewModel.Result) { if (facilityTypes.FacilityGroupId == item.Id) { hotelfacilityGroupModel.HotelFacilityTypes.Add(facilityTypes); } } modelList.Add(hotelfacilityGroupModel); } responseModelList.Result = modelList; return(responseModelList); }
public void TestCreateHotelFacilityRelation_Id() { //Arrange var hotelId = 73; var id = 1; HotelFacilityRelation hotelFacilityRelation = new HotelFacilityRelation { HotelId = hotelId, FacilityId = id, FacilityTypeId = id, FacilityGroupId = id, IsDeleted = false, IsProvisioned = true, CreatedBy = "MGIT", UpdatedBy = "MGIT", StartDate = DateTime.Now, EndDate = DateTime.Now }; var userName = "******"; var facilities = new FacilityViewModel() { Id = 1, FacilityGroupId = 1, FacilityTypeId = 1, IsSelected = true, IsActive = true, Name = "ABC" }; var facilityType = new HotelFacilityTypeViewModel() { FacilityTypeId = 1, FacilityGroupId = 1, FacilityTypeName = "TypeName", }; facilityType.FacilityList.Add(facilities); var facilityGroup = new HotelFacilityGroupViewModel() { FacilityGroupId = 1, FacilityGroupName = "Group1", IconPath = "", }; facilityGroup.HotelFacilityTypes.Add(facilityType); var facilityModel = new HotelFacilityViewModel() { HotelId = 73, }; facilityModel.FacilityGroupList.Add(facilityGroup); iHotelFacilityRelationLibrary.Setup(a => a.InsertEntity(It.IsAny <HotelFacilityRelation>())).Returns(Task.FromResult(new BaseResult <long>() { Result = id })); //Act var result = facilitiesRepository.InsertAndUpdateHotelFacilityRelation(facilityModel, userName); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Result.Result == id); }