public void TestGetSelectedFacilities_ListOfHotelFacilities() { //Arrange int id = 1; var hotelFacility = new HotelFacilityRelation() { Id = id, HotelId = id, FacilityId = id, FacilityGroupId = id, IsDeleted = false }; var baseResult = new BaseResult <List <HotelFacilityRelation> >() { Result = new List <HotelFacilityRelation>() { hotelFacility } }; var pred = new Func <HotelFacilityRelation, bool>(x => !x.IsDeleted && x.HotelId == id); iHotelFacilityRelationLibrary.Setup(a => a.GetListByPredicate(It.Is <Func <HotelFacilityRelation, bool> >(x => x.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult)); //Act var facilityList = facilitiesRepository.GetSelectedFacilities(id); //Assert Assert.IsTrue(facilityList != null); Assert.IsTrue(facilityList.Result is BaseResult <List <HotelFacilityRelation> >); Assert.IsTrue(facilityList.Result.Result.Exists(x => x.Id == id)); }
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); }
/// <summary> /// Saves The Facilities of that specific hotel /// </summary> /// <param name="hotelFacilityViewModel">hotel Facility View Model</param> /// <returns>long</returns> public async Task <BaseResult <long> > InsertAndUpdateHotelFacilityRelation(HotelFacilityViewModel hotelFacilityViewModel, string userName) { BaseResult <long> result = new BaseResult <long>(); if (hotelFacilityViewModel != null) { foreach (var item in hotelFacilityViewModel.FacilityGroupList) { foreach (var facilityType in item.HotelFacilityTypes) { foreach (var facility in facilityType.FacilityList) { if (facility.ObjectState == ObjectState.Added) { if (facility.IsSelected == true) { HotelFacilityRelation hotelFacilityRelation = new HotelFacilityRelation { HotelId = hotelFacilityViewModel.HotelId, FacilityId = facility.Id, FacilityTypeId = facility.FacilityTypeId, FacilityGroupId = facility.FacilityGroupId, IsDeleted = false, IsProvisioned = facility.IsSelected, CreatedBy = userName, UpdatedBy = userName, StartDate = DateTime.Now, EndDate = DateTime.Now }; result = await this.iHotelFacilityRelationLibrary.InsertEntity(hotelFacilityRelation); if (result.IsError) { return(result); } } } if (facility.ObjectState == ObjectState.Deleted) { BaseResult <bool> updateResult = new BaseResult <bool>(); var facilities = this.iHotelFacilityRelationLibrary.GetListByPredicate(x => x.HotelId == hotelFacilityViewModel.HotelId && x.Id == facility.FacilityRelationId && x.FacilityId == facility.Id && x.IsDeleted == false).Result.Result.FirstOrDefault(); if (facilities != null) { facilities.IsDeleted = true; facilities.UpdatedBy = userName; facilities.UpdatedDate = DateTime.Now.JakartaOffset(); updateResult = await this.iHotelFacilityRelationLibrary.UpdateEntityByDapper(facilities); if (updateResult.IsError && updateResult.ExceptionMessage != null) { result.IsError = updateResult.IsError; result.ExceptionMessage = updateResult.ExceptionMessage; return(result); } result.Result = facilities.Id; } if (result.IsError) { return(result); } } } } } } return(result); }