public async Task TestGetRatePlansById_positive_Predicate_sample()
        {
            //Arrange
            int ratePlanId = 1, rateCategoryId = 1;
            var ratePlan = new RatePlans()
            {
                Id = 1, RateCategoryId = 1, IsActive = true, IsDeleted = false
            };
            var baseResult = new BaseResult <List <RatePlans> >()
            {
                Result = new List <RatePlans>()
                {
                    ratePlan
                }
            };
            var pred = new Func <RatePlans, bool>(x => x.RateCategoryId == rateCategoryId);

            iRatePlansLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <RatePlans, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult));
            //Act
            Task <BaseResult <List <RatePlans> > > result = rateCategoryRepository.GetRatePlansById(ratePlanId);

            //Assert
            Assert.IsTrue(result.Result != null);
            Assert.IsTrue(result.Result is BaseResult <List <RatePlans> >);
        }
        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 TestUpdateRatePlans_Failed_ByUpdateEntityByDapper_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 ratePlan = new RatePlans()
            {
                Id             = 1,
                RateCategoryId = 2,
                RoomId         = 322
            };

            var ratePlanbaseResult = new BaseResult <List <RatePlans> >()
            {
                Result = new List <RatePlans>()
                {
                    ratePlan
                }
            };
            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));
            iRatePlansLibrary.Setup(x => x.UpdateEntityByDapper(It.IsAny <RatePlans>())).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);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        public static List <Room> GetRoomsForDB(int hotelID)
        {
            string sql = @"select roomName,BedArea,Area,Floor,NetType,r.BedType,r.RoomTypeId,r.IsChildRoom,Remark,p.RoomID,e.RatePlanID,
                           p.RatePlanName,p.ishourRoom,p.BedType as RatePlanBedType,
                           p.NetInfo,p.zaocan,p.Discount,e.price,e.dates,e.Available,p.PayType
                           from HotelRoom r with(nolock)
                           inner join HotelRatePlan p with(nolock)
                           on r.id=p.RoomID 
                           inner join HotelRate e with(nolock)
                           on e.RatePlanID=p.id
                           where r.hotelID=@hotelID and r.Enabled=1 and p.Enabled=1 
                           order by r.id,p.id,dates";
            var    dt  = HotelCloud.SqlServer.SQLHelper.Get_DataTable(sql, HotelCloud.SqlServer.SQLHelper.GetCon(), new Dictionary <string, HotelCloud.SqlServer.DBParam> {
                { "hotelID", new HotelCloud.SqlServer.DBParam {
                      ParamValue = hotelID.ToString()
                  } }
            });
            List <Room>     rooms       = new List <Room>();
            Room            room        = new Room();
            List <RatePlan> RatePlans   = new List <RatePlan>();
            RatePlan        rateplan    = new RatePlan();
            List <Rate>     Rates       = new List <Rate>();
            string          croomID     = "";
            string          cRatePlanID = "";

            foreach (System.Data.DataRow dr in dt.Rows)
            {
                if (!cRatePlanID.Equals(dr["RatePlanID"].ToString()))
                {
                    if (!cRatePlanID.Equals(""))
                    {
                        rateplan.Rates = Rates;
                        RatePlans.Add(rateplan);
                    }
                    cRatePlanID           = dr["RatePlanID"].ToString();
                    rateplan              = new RatePlan();
                    rateplan.BedType      = dr["rateplanbedtype"].ToString();
                    rateplan.NetInfo      = dr["netinfo"].ToString();
                    rateplan.ID           = WeiXinPublic.ConvertHelper.ToInt(dr["rateplanid"]);
                    rateplan.RatePlanName = dr["rateplanname"].ToString();
                    rateplan.ZaoCan       = dr["zaocan"].ToString();
                    rateplan.IsHourRoom   = WeiXinPublic.ConvertHelper.ToInt(dr["isHourRoom"]);
                    rateplan.Discount     = WeiXinPublic.ConvertHelper.ToDouble(dr["Discount"]);
                    rateplan.PayType      = Convert.ToString(dr["paytype"]);
                    Rates = new List <Rate>();
                }
                if ((!croomID.Equals(dr["RoomID"].ToString())))
                {
                    if (!croomID.Equals(""))
                    {
                        room.RatePlans = RatePlans;
                        rooms.Add(room);
                    }
                    croomID          = dr["RoomID"].ToString();
                    room             = new Room();
                    room.Area        = dr["area"].ToString();
                    room.BedArea     = dr["bedarea"].ToString();
                    room.BedType     = dr["bedtype"].ToString();
                    room.Floor       = dr["floor"].ToString();
                    room.ID          = Convert.ToInt32(dr["roomID"].ToString());
                    room.NetType     = dr["nettype"].ToString();
                    room.Remark      = dr["Remark"].ToString();
                    room.RoomName    = dr["RoomName"].ToString();
                    room.IsChildRoom = WeiXinPublic.ConvertHelper.ToInt(dr["IsChildRoom"]);
                    room.RoomTypeId  = WeiXinPublic.ConvertHelper.ToInt(dr["RoomTypeId"]);
                    RatePlans        = new List <RatePlan>();
                }

                Rate r = new Rate();
                r.Available = Convert.ToInt32(dr["Available"].ToString());
                r.Dates     = Convert.ToDateTime(dr["dates"].ToString());
                r.Price     = Convert.ToInt32(dr["Price"].ToString());
                Rates.Add(r);
            }
            if (dt.Rows.Count > 0)
            {
                rateplan.Rates = Rates;
                RatePlans.Add(rateplan);
                room.RatePlans = RatePlans;
                rooms.Add(room);
            }
            return(rooms);
        }