예제 #1
0
        public void UpdateTwoYearAnniversaryWinCouponSuccess()
        {
            // 아이디 준비
            var entry = new TwoYearAnniversaryEntry
            {
                Id          = 1,
                CreateDate  = new DateTime(2018, 3, 29),
                IpAddress   = "127.0.0.1",
                SamsoniteId = "pentacleId123",
                PrizeType   = TwoYearAnniversarInstantPrizeType.StarBucks,
                Channel     = Domain.Entities.Abstract.ChannelType.PC
            };

            entryRepo.Setup(x => x.Add(It.IsAny <TwoYearAnniversaryEntry>())).Returns(entry);
            entryRepo.Setup(x => x.SingleOrDefault(It.IsAny <Expression <Func <TwoYearAnniversaryEntry, bool> > >())).Returns(entry);


            var coupon = new TwoYearAnniversaryWinCoupon
            {
                CouponType = 0,
                CouponCode = "1",
                //TwoYearAnniversaryEntryId = 1,
                //WinnerDate = new DateTime(2018, 3, 29),
            };

            couponRepo.Setup(x => x.Add(It.IsAny <TwoYearAnniversaryWinCoupon>())).Returns(coupon);
            couponRepo.Setup(x => x.FirstOrDefault(It.IsAny <Expression <Func <TwoYearAnniversaryWinCoupon, bool> > >())).Returns(coupon);


            var resultCoupon = new TwoYearAnniversaryWinCoupon
            {
                CouponType = 0,
                CouponCode = "1",
                TwoYearAnniversaryEntryId = 1,
                WinnerDate = new DateTime(2018, 3, 29),
            };

            couponRepo.Setup(x => x.Update(It.IsAny <TwoYearAnniversaryWinCoupon>())).Returns(resultCoupon);


            long entryId = 1;
            var  result  = service.UpdateTwoYearAnniversaryWinCoupon(entryId);

            Assert.NotNull(resultCoupon);

            //null check
            //var user = new TwoYearAnniversaryEntry { };
            //user = null;
            //entryRepo.Setup(x => x.SingleOrDefault(It.IsAny<Expression<Func<TwoYearAnniversaryEntry, bool>>>())).Returns(user);

            //long entryId = 1;

            //var failedResult = Assert.Throws<TwoYearAnniversaryServiceException>(() => {
            //    var result = service.UpdateTwoYearAnniversaryWinCoupon(entryId);
            //});

            //Assert.Matches("400", failedResult.Code);
            //Assert.Matches("당첨 데이터가 존재하지 않습니다.", failedResult.Message);
        }
예제 #2
0
        public ActionResult CreateTwoYearAnniversaryEntry(TwoYearCustNoModel custNoModel)
        {
            try
            {
                if (common.Now >= new DateTime(2018, 4, 19))
                {
                    throw new TwoYearAnniversaryServiceException("400", "이벤트가 종료되었습니다.", null);
                }

                if (string.IsNullOrEmpty(custNoModel.TwoYearCustNo))
                {
                    throw new TwoYearAnniversaryServiceException("400", "쌤소나이트에 로그인 후 시도해주세요.", null);
                }

                var encrytionId = custNoModel.TwoYearCustNo;
                var samsoniteId = decrypt(encrytionId);
                //string samsoniteId= Session["TwoAnniversarySamsoniteId"] as string;
                var entry = new TwoYearAnniversaryEntry()
                {
                    SamsoniteId           = encrytionId,
                    SamsoniteEncryptionId = samsoniteId,
                    CreateDate            = common.Now,
                    Channel   = common.IsMobileDevice ? Domain.Entities.Abstract.ChannelType.Mobile : Domain.Entities.Abstract.ChannelType.PC,
                    IpAddress = common.IpAddress
                };

                var user = service.CreateTwoYearAnniversaryEntry(entry);

                var coupon = service.UpdateTwoYearAnniversaryWinCoupon(user.Id);

                if (coupon != null)
                {
                    var couponUrl = ConfigurationManager.AppSettings["samsonite.coupon.url"] as string;

                    string         url            = string.Format(couponUrl + "?custNo={0}&coupon={1}", user.SamsoniteId, coupon.CouponCode);
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                    httpWebRequest.Method = "GET";
                    //httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                    // 실서버 반영시 주석 해제
                    using (HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { }
                }


                var model = new TwoYearAnniversaryViewModel()
                {
                    PrizeType    = user.PrizeType,
                    RouletteType = 4,
                    PrizeName    = "wlaossdefr",
                };

                /*
                 *  - 서버 룰렛 순서 = ["1만원쿠폰","스타벅스 기프티콘",  "키즈백팩", "쌤소나이트 정품가방", "20만원쿠폰", "라인프렌즈 콜라보 캐리어"]
                 *  - 뷰단 룰렛 순서 = ["라인프렌즈 콜라보 캐리어", "20만원쿠폰", "키즈백팩", "스타벅스 기프티콘", "1만원쿠폰", "쌤소나이트 정품가방"]
                 */
                switch (user.PrizeType)
                {
                case TwoYearAnniversarInstantPrizeType.Loser:
                default:
                    model.PrizeName    = "wlaossdefr";
                    model.RouletteType = 4;
                    break;

                case TwoYearAnniversarInstantPrizeType.StarBucks:
                    model.PrizeName    = "wzzxjcvvl";
                    model.RouletteType = 3;
                    break;

                case TwoYearAnniversarInstantPrizeType.AtKidsBagPack:
                    model.PrizeName    = "wgrfkdqskad";
                    model.RouletteType = 2;
                    break;

                case TwoYearAnniversarInstantPrizeType.OriginalBag:
                    model.PrizeName    = "wtrrkeqwkqd";
                    model.RouletteType = 5;
                    break;

                case TwoYearAnniversarInstantPrizeType.Coupon_20:
                    model.PrizeName    = "wlzknjvhhgs";
                    model.RouletteType = 1;
                    break;

                case TwoYearAnniversarInstantPrizeType.LineFriendsCarrier:
                    model.PrizeName    = "wmznobfvlcdxj";
                    model.RouletteType = 0;
                    break;
                }

                return(Json(new
                {
                    result = true,
                    data = model
                }));
            }
            catch (TwoYearAnniversaryServiceException e)
            {
                return(Json(new
                {
                    result = false,
                    message = e.Message
                }));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    result = false,
                    message = "서비스 점검중입니다. 잠시 후 시도해보시거나, 담당자에게 문의하시기 바랍니다."
                }));
            }
        }