public async Task TestGetRateCategoryById_positive_Predicate_sample()
        {
            //Arrange
            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));
            //Act
            Task <BaseResult <List <RateCategory> > > result = rateCategoryRepository.GetRateCategoryById(rateCategoryId);

            //Assert
            Assert.IsTrue(result.Result != null);
            Assert.IsTrue(result.Result is BaseResult <List <RateCategory> >);
        }
        public void TestGetRateCategoryById_Exception_ByRatePlans_InternalServerError()
        {
            //Arrange
            int rateCategoryId = 7;
            List <RateCategory> rateCategoryList  = new List <RateCategory>();
            RateCategory        rateCategoryModel = new RateCategory()
            {
                Id       = 1,
                Name     = "RC1",
                IsActive = true
            };

            rateCategoryList.Add(rateCategoryModel);
            mockRatesCategoryRepository.Setup(a => a.GetRateCategoryById(rateCategoryId)).Returns(Task.FromResult(new BaseResult <List <RateCategory> > {
                Result = rateCategoryList
            }));
            mockRatesCategoryRepository.Setup(a => a.GetRatePlansById(rateCategoryId)).Returns(Task.FromResult(new BaseResult <List <RatePlans> > {
                IsError = true, ExceptionMessage = Helper.Common.GetMockException()
            }));

            //Act
            Task <IActionResult> actionResult = mockRatesCategoryController.GetRateCategoryById(rateCategoryId);

            //Assert
            Assert.IsTrue(actionResult != null);
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actionResult.Result).StatusCode, 500);
        }
        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>);
        }
        public async Task TestGetRateCategoryById_Success_OkResponse()
        {
            //Arrange
            int          rateCategoryId    = 7;
            RateCategory rateCategoryModel = new RateCategory()
            {
                HotelId = 1061,
                Id      = 1,
                Name    = "RC1",
                CancellationPolicyId = 5,
                MarketId             = 2,
                HotelMealId          = 2,
                IsDeleted            = false,
                IsActive             = true
            };
            RatePlans ratePlansModel = new RatePlans()
            {
                Id             = 1,
                RoomId         = 322,
                RateCategoryId = 7,
                IsDeleted      = false,
                IsActive       = true
            };

            mockRatesCategoryRepository.Setup(a => a.GetRateCategoryById(rateCategoryId)).Returns(Task.FromResult(new BaseResult <List <RateCategory> >()
            {
                Result = new List <RateCategory> {
                    rateCategoryModel
                }
            }));
            mockRatesCategoryRepository.Setup(a => a.GetRatePlansById(rateCategoryId)).Returns(Task.FromResult(new BaseResult <List <RatePlans> > {
                Result = new List <RatePlans> {
                    ratePlansModel
                }
            }));
            //Act
            Task <IActionResult> actionResult = mockRatesCategoryController.GetRateCategoryById(rateCategoryId);
            var rateCategory = (actionResult.Result as Microsoft.AspNetCore.Mvc.OkObjectResult).Value as BaseResult <RateCategoryViewModel>;

            //Assert
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)actionResult.Result).StatusCode, 200);
            Assert.IsNotNull(rateCategory);
            Assert.IsTrue(!rateCategory.IsError);
            Assert.IsTrue(rateCategory.Result != null);
        }
        public async Task TestUpdateRateCategory_Failed_ByUpdateEntityByDapper_Error()
        {
            //Arrange
            var rateCategoryViewModel = new RateCategoryViewModel()
            {
                Id                   = 1,
                Name                 = "RC1",
                MarketId             = 2,
                CancellationPolicyId = 2,
                HotelMealId          = 2,
                IsActive             = true
            };

            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>()
            {
                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);
        }
        public async Task TestCreateRateCategory_Success_OkResponse()
        {
            //Arrange
            RateCategoryViewModel rateCategoryViewModel = new RateCategoryViewModel();

            RateCategory rateCategory = new RateCategory();

            mockRatesCategoryRepository.Setup(a => a.SaveAndUpdateRateCategory(rateCategoryViewModel, It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <RateCategory> {
                Result = rateCategory
            }));
            //Act
            Task <IActionResult> actionResult = mockRatesCategoryController.CreateRateCategory(rateCategoryViewModel);
            var createRateCategoryResult      = (actionResult.Result as Microsoft.AspNetCore.Mvc.OkObjectResult).Value as BaseResult <RateCategory>;

            //Assert
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)actionResult.Result).StatusCode, 200);
            Assert.IsNotNull(createRateCategoryResult);
            Assert.IsTrue(!createRateCategoryResult.IsError);
            Assert.IsTrue(createRateCategoryResult.Result != null);
        }
        public async Task TestAddRateCategory_Failed_Error()
        {
            //Arrange
            var rateCategoryViewModel = new RateCategoryViewModel()
            {
                Id                   = 1,
                Name                 = "RC1",
                MarketId             = 2,
                CancellationPolicyId = 2,
                HotelMealId          = 2,
                IsActive             = true
            };

            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>()
            {
                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);
        }
        public async Task <IActionResult> GetRateCategoryById([FromBody] int rateCategoryId)
        {
            BaseResult <RateCategoryViewModel> rateCategoryViewModelResult = new BaseResult <RateCategoryViewModel>();
            BaseResult <List <RateCategory> >  rateCategoryResult          = new BaseResult <List <RateCategory> >();
            BaseResult <List <RatePlans> >     ratePlansResult             = new BaseResult <List <RatePlans> >();
            RateCategory rateCategoryRequest = new RateCategory();

            if (rateCategoryId <= default(int))
            {
                rateCategoryResult.IsError = true;
                rateCategoryResult.Message = string.Format(coreHelper.Constants.ErrorMessage.InvalidId, rateCategoryId);
                return(BadRequest(rateCategoryResult));
            }

            rateCategoryResult = await iRatesCategory.GetRateCategoryById(rateCategoryId).ConfigureAwait(false);

            if (rateCategoryResult.IsError && rateCategoryResult.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }
            else if (rateCategoryResult.Result == null)
            {
                return(new NoContentResult()); //204
            }

            ratePlansResult = await iRatesCategory.GetRatePlansById(rateCategoryId).ConfigureAwait(false);

            if (ratePlansResult.IsError && ratePlansResult.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }

            rateCategoryRequest = rateCategoryResult.Result.First();

            var result = RatesCategoryResponseMapper.MapToRateCategoryViewModel(rateCategoryRequest, ratePlansResult.Result);

            rateCategoryViewModelResult.Result = result;
            return(Ok(rateCategoryViewModelResult));
        }
        /// <summary>
        /// Map RateCategoryViewModel
        /// </summary>
        /// <param name="rateCategoryResponse"></param>
        /// <param name="roomTypeList"></param>
        /// <returns></returns>
        public static RateCategoryViewModel MapToRateCategoryViewModel(RateCategory rateCategoryResponse, List <RatePlans> roomTypeList)
        {
            var rateCategoryViewModel = AutoMapper.Mapper.Map <RateCategory, RateCategoryViewModel>(rateCategoryResponse);

            if (roomTypeList != null)
            {
                foreach (var item in roomTypeList)
                {
                    var ratePlansViewModel = AutoMapper.Mapper.Map <RatePlans, RatePlansViewModel>(item);
                    if (item.IsDeleted)
                    {
                        ratePlansViewModel.IsSelected = false;
                    }
                    else
                    {
                        ratePlansViewModel.IsSelected = true;
                    }
                    rateCategoryViewModel.RoomTypeList.Add(ratePlansViewModel);
                }
            }
            return(rateCategoryViewModel);
        }
Example #11
0
        public async Task <IActionResult> DeleteRateCategory([FromBody] int rateCategoryId)
        {
            BaseResult <RateCategory> rateCategoryResult = new BaseResult <RateCategory>();
            RateCategory rateCategoryRequest             = new RateCategory();

            if (rateCategoryId <= default(int))
            {
                rateCategoryResult.IsError = true;
                rateCategoryResult.Message = string.Format(coreHelper.Constants.ErrorMessage.InvalidId, rateCategoryId);
                return(BadRequest(rateCategoryResult));
            }
            rateCategoryResult = await iRatesCategory.DeleteRateCategory(rateCategoryId).ConfigureAwait(false);

            if (rateCategoryResult.IsError && rateCategoryResult.ExceptionMessage != null)
            {
                return(StatusCode(500, rateCategoryResult));
            }
            else if (rateCategoryResult.Result == null)
            {
                return(new NoContentResult());
            }
            return(Ok(rateCategoryResult));
        }
        /// <summary>
        /// Map Rate Category while updating record
        /// </summary>
        /// <param name="rateCategoryToMap"></param>
        /// <param name="rateCategoryDatabase"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static RateCategory AutoMapperRateCategory(RateCategoryViewModel rateCategoryToMap, RateCategory rateCategoryDatabase, string userName)
        {
            var rateCategoryMapped = AutoMapper.Mapper.Map <RateCategory>(rateCategoryToMap);

            rateCategoryMapped.Code        = rateCategoryDatabase.Code;
            rateCategoryMapped.CreatedBy   = rateCategoryDatabase.CreatedBy;
            rateCategoryMapped.CreatedDate = rateCategoryDatabase.CreatedDate;
            rateCategoryMapped.UpdatedBy   = userName;
            rateCategoryMapped.UpdatedDate = DateTime.Now.JakartaOffset();
            rateCategoryMapped.IsDeleted   = rateCategoryDatabase.IsDeleted;
            return(rateCategoryMapped);
        }
        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);
        }
Example #14
0
 public void Save(RateCategory category)
 {
     if(category.IsValid())
     {
         RateCategoryRepo.Save(category);
     }
 }
Example #15
0
 public void Delete(RateCategory category)
 {
     RateCategoryRepo.Remove(category);
 }
Example #16
0
 public EditRateCategoryModel(RateCategory rateCategory, IEnumerable<RoomType> roomTypes)
 {
     Id = rateCategory.Id;
     Name = rateCategory.Name;
     Description = rateCategory.Description;
     Color = rateCategory.Color;
     Items = rateCategory.Items.Select(x => new EditRateCategoryItemModel(x, roomTypes)).ToList();
 }