Пример #1
0
        public void WhenผใชUserIdสงซอคปองจำนวนคปอง(string userId, int amount)
        {
            var mockTicketDac = ScenarioContext.Current.Get<Moq.Mock<ITicketDataAccess>>();
            mockTicketDac.Setup(dac => dac.BuyTicket(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()));

            var mockAccountDac = ScenarioContext.Current.Get<Moq.Mock<IAccountDataAccess>>();
            mockAccountDac.Setup(dac => dac.ChargeFromBuyTicket(It.IsAny<string>(), It.IsAny<int>()));

            var currentDate = ScenarioContext.Current.Get<DateTime>();
            var request = new BuyTicketRequest
            {
                UserId = userId,
                Amount = amount
            };
            var result = FacadeRepository.Instance.TicketFacade.BuyTicket(request, currentDate);
            ScenarioContext.Current.Set(result);
        }
Пример #2
0
        public BuyTicketRespond BuyTicket(BuyTicketRequest request, DateTime currentDate)
        {
            var invalidDataModel = new BuyTicketRespond { IsSuccessed = false };

            var areArgumentValid = request != null && !string.IsNullOrEmpty(request.UserId);
            if (!areArgumentValid) return invalidDataModel;

            var selectedAccount = FacadeRepository.Instance.AccountDataAccess.GetAccountBySecrectCode(request.UserId);
            if (selectedAccount == null) return invalidDataModel;
            invalidDataModel.AccountInfo = selectedAccount;

            var MinimumBuyTicketRequest = 1;
            var isRequestAmountValid = request.Amount >= MinimumBuyTicketRequest;
            if (!isRequestAmountValid) return invalidDataModel;

            var rewardDac = FacadeRepository.Instance.RewardDataAccess;
            var currentRewardGroup = rewardDac.GetRewardGroup()
                .OrderByDescending(it => it.ExpiredDate)
                .FirstOrDefault();
            if (currentRewardGroup == null) return invalidDataModel;
            invalidDataModel.RewardResultDate = currentRewardGroup.ExpiredDate;

            var isCurrentRewardAvailableForBuy = currentRewardGroup.RewardInfo.Any() && currentRewardGroup.ExpiredDate.Date > currentDate.Date;
            if (!isCurrentRewardAvailableForBuy) return invalidDataModel;

            var requiredPoints = currentRewardGroup.RequestPoints * request.Amount;
            var isNeedReachMinimumRequirement = selectedAccount.Points >= requiredPoints;
            if (!isNeedReachMinimumRequirement) return invalidDataModel;

            FacadeRepository.Instance.TicketDataAccess.BuyTicket(request.UserId, request.Amount, currentRewardGroup.Id);
            FacadeRepository.Instance.AccountDataAccess.ChargeFromBuyTicket(request.UserId, requiredPoints);

            selectedAccount.Points -= requiredPoints;
            selectedAccount.CurrentOrderedCoupon += request.Amount;
            return new BuyTicketRespond
            {
                AccountInfo = selectedAccount,
                IsSuccessed = true,
                RewardResultDate = currentRewardGroup.ExpiredDate
            };
        }
 public BuyTicketRespond BuyTicket(string userId, int amount)
 {
     var request = new BuyTicketRequest { UserId = userId, Amount = amount };
     var result = FacadeRepository.Instance.TicketFacade.BuyTicket(request, DateTime.Now);
     return result;
 }