/// <summary> /// Method to update RatePlan /// </summary> /// <param name="ratePlansViewModel"></param> /// <param name="userName"></param> /// <returns>RateCategory</returns> public async Task <BaseResult <RateCategory> > UpdateRatePlans(RatePlansViewModel ratePlansViewModel, string userName) { BaseResult <RateCategory> result = new BaseResult <RateCategory>(); result.Result = new RateCategory(); //Fetch Rate plan by Id var ratePlansResult = await iRatePlansLibrary.GetListByPredicate(id => id.Id == ratePlansViewModel.Id && id.IsActive).ConfigureAwait(false); if (ratePlansResult.Result != null && ratePlansResult.Result.Any()) { //Map Rate Plans var updateRatePlans = RatesCategoryRequestMapper.AutoMapperRatePlans(ratePlansViewModel, ratePlansResult.Result.First(), userName); // Update Rate plan var updateRatePlansResult = await iRatePlansLibrary.UpdateEntityByDapper(updateRatePlans).ConfigureAwait(false); if (updateRatePlansResult.IsError || updateRatePlansResult.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = updateRatePlansResult.ExceptionMessage; return(result); } //set result result.Result.Id = updateRatePlans.RateCategoryId; } else { result.IsError = true; result.ErrorCode = (int)coreHelper.Constants.ErrorCodes.NoRatePlanOfID; result.Message = string.Format(coreHelper.Constants.ErrorMessage.NoRatePlanOfID, ratePlansViewModel.Id); return(result); } return(result); }
public async Task TestUpdateRatePlans_Failed_ByGetListByPredicate_Error() { //Arrange var rateCategoryViewModel = new RateCategoryViewModel() { Id = 1, Name = "RC1", MarketId = 2, CancellationPolicyId = 2, HotelMealId = 2, IsActive = true }; var ratePlanViewModel = new RatePlansViewModel() { Id = 1, RateCategoryId = 2, RoomId = 322, ObjectState = ObjectState.Modified }; var ratePlansList = new List <RatePlansViewModel>(); ratePlansList.Add(ratePlanViewModel); rateCategoryViewModel.RoomTypeList.AddRange(ratePlansList); rateCategoryViewModel.ObjectState = ObjectState.Modified; int rateCategoryId = 1; var rateCategory = new RateCategory() { Id = 1, Name = "RateCategory1", IsActive = true, IsDeleted = false }; var baseResult = new BaseResult <List <RateCategory> >() { Result = new List <RateCategory>() { rateCategory } }; var pred = new Func <RateCategory, bool>(x => x.Id == rateCategoryId && !x.IsDeleted); iRateCategoryLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <RateCategory, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult)); iRateCategoryLibrary.Setup(x => x.UpdateEntityByDapper(It.IsAny <RateCategory>())).Returns(Task.FromResult(new BaseResult <bool>() { Result = true })).Verifiable(); var ratePlanbaseResult = new BaseResult <List <RatePlans> >(); ratePlanbaseResult.Result = null; var ratePlanPred = new Func <RatePlans, bool>(x => x.RateCategoryId == rateCategoryId && x.IsActive); iRatePlansLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <RatePlans, bool> >(y => y.GetType() == ratePlanPred.GetType()))).Returns(Task.FromResult(ratePlanbaseResult)); //Act Task <BaseResult <RateCategory> > actionResult = rateCategoryRepository.SaveAndUpdateRateCategory(rateCategoryViewModel, It.IsAny <string>()); //Assert Assert.IsTrue(actionResult.Result.IsError); Assert.IsTrue(actionResult.Result.Message != null); }
public async Task TestAddRateCategory_Pass_Success() { //Arrange var rateCategoryViewModel = new RateCategoryViewModel() { Id = 1, Name = "RC1", MarketId = 2, CancellationPolicyId = 2, HotelMealId = 2, IsActive = true }; var ratePlan = new RatePlansViewModel() { Id = 1, RateCategoryId = 2, RoomId = 322 }; var ratePlansList = new List <RatePlansViewModel>(); ratePlansList.Add(ratePlan); rateCategoryViewModel.RoomTypeList.AddRange(ratePlansList); rateCategoryViewModel.ObjectState = ObjectState.Added; var rateCategory = new RateCategory() { Id = 1, Name = "RateCategory1", IsActive = true, IsDeleted = false }; var baseResult = new BaseResult <List <RateCategory> >() { Result = new List <RateCategory>() { rateCategory } }; iRateCategoryLibrary.Setup(x => x.InsertEntity(It.IsAny <RateCategory>())).Returns(Task.FromResult(new BaseResult <long>() { Result = 2 })).Verifiable(); iRatePlansLibrary.Setup(x => x.InsertEntityList(It.IsAny <List <RatePlans> >())).Returns(Task.FromResult(new BaseResult <long>() { Result = 2 })).Verifiable(); //Act Task <BaseResult <RateCategory> > actionResult = rateCategoryRepository.SaveAndUpdateRateCategory(rateCategoryViewModel, It.IsAny <string>()); //Assert Assert.IsTrue(actionResult.Result != null); Assert.IsTrue(actionResult.Result is BaseResult <RateCategory>); }
/// <summary> /// Map Rate Plans while updating record /// </summary> /// <param name="ratePlansToMap"></param> /// <param name="ratePlansDatabase"></param> /// <param name="userName"></param> /// <returns></returns> public static RatePlans AutoMapperRatePlans(RatePlansViewModel ratePlansToMap, RatePlans ratePlansDatabase, string userName) { var ratePlansMapped = AutoMapper.Mapper.Map <RatePlans>(ratePlansToMap); ratePlansMapped.IsActive = true; if (ratePlansToMap.IsSelected) { ratePlansMapped.IsDeleted = false; } else { ratePlansMapped.IsDeleted = true; } ratePlansMapped.Id = ratePlansDatabase.Id; ratePlansMapped.RateCategoryId = ratePlansDatabase.RateCategoryId; ratePlansMapped.CreatedBy = ratePlansDatabase.CreatedBy; ratePlansMapped.CreatedDate = ratePlansDatabase.CreatedDate; ratePlansMapped.UpdatedBy = userName; ratePlansMapped.UpdatedDate = DateTime.Now.JakartaOffset(); return(ratePlansMapped); }
public async Task TestAddRatePlans_Failed_Error() { //Arrange var rateCategoryViewModel = new RateCategoryViewModel() { Id = 1, Name = "RC1", MarketId = 2, CancellationPolicyId = 2, HotelMealId = 2, IsActive = true }; var ratePlanViewModel = new RatePlansViewModel() { Id = 1, RateCategoryId = 2, RoomId = 322 }; var ratePlansViewModelList = new List <RatePlansViewModel>(); ratePlansViewModelList.Add(ratePlanViewModel); rateCategoryViewModel.RoomTypeList.AddRange(ratePlansViewModelList); rateCategoryViewModel.ObjectState = ObjectState.Added; var rateCategory = new RateCategory() { Id = 1, Name = "RateCategory1", IsActive = true, IsDeleted = false }; var baseResult = new BaseResult <List <RateCategory> >() { Result = new List <RateCategory>() { rateCategory } }; iRateCategoryLibrary.Setup(x => x.InsertEntity(It.IsAny <RateCategory>())).Returns(Task.FromResult(new BaseResult <long>() { Result = 2 })).Verifiable(); var ratePlan = new RatePlans() { Id = 1, RateCategoryId = 2, RoomId = 322 }; int rateCategoryId = 2; var ratePlanbaseResult = new BaseResult <List <RatePlans> >() { Result = new List <RatePlans>() { ratePlan } }; var pred = new Func <RatePlans, bool>(x => x.RateCategoryId == rateCategoryId && x.IsActive); iRatePlansLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <RatePlans, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(ratePlanbaseResult)); iRatePlansLibrary.Setup(x => x.InsertEntityList(It.IsAny <List <RatePlans> >())).Returns(Task.FromResult(new BaseResult <long>() { IsError = true, ExceptionMessage = Helper.Common.GetMockException() })).Verifiable(); //Act Task <BaseResult <RateCategory> > actionResult = rateCategoryRepository.SaveAndUpdateRateCategory(rateCategoryViewModel, It.IsAny <string>()); //Assert Assert.IsTrue(actionResult.Result.IsError); Assert.IsTrue(actionResult.Result.ExceptionMessage != null); }