Beispiel #1
0
        public void TryUpdateInstantLotteryWinnerFailed()
        {
            var entry = new DisneyStarWars2018InstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2018, 5, 2),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty,
                Name       = "홍길동",
                Mobile     = "01012345678",
                UpdateDate = new DateTime(2018, 5, 2)
            };

            repo.Setup(x => x.Any(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >())).Returns(true);
            repo.Setup(x => x.Update(It.IsAny <DisneyStarWars2018InstantLottery>())).Returns(entry);

            //action
            var failedResult = Assert.Throws <DisneyStarWars2018ServiceException>(() => {
                var tryTest = service.UpdateInstantLotteryWinner(entry);
            });

            //assert
            Assert.Matches("400", failedResult.Code);
            Assert.Matches("이미 당첨된 내역이 존재합니다.당첨된 분에게는 추가 경품이 지급되지 않습니다.", failedResult.Message);
        }
Beispiel #2
0
        public void TryUpdateInstantLotteryWinnerSuccess()
        {
            var entry = new DisneyStarWars2018InstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2018, 5, 2),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty,
                Name       = "홍길동",
                Mobile     = "01012345678",
                UpdateDate = new DateTime(2018, 1, 4)
            };

            repo.Setup(x => x.Any(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >())).Returns(false);
            repo.Setup(x => x.Update(It.IsAny <DisneyStarWars2018InstantLottery>())).Returns(entry);

            //action
            var result = service.UpdateInstantLotteryWinner(entry);

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty);

            repo.Verify(x => x.Any(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >()), Times.Once);
            repo.Verify(x => x.Update(It.IsAny <DisneyStarWars2018InstantLottery>()), Times.Once);
            repo.Verify(x => x.Save(), Times.Once);
        }
Beispiel #3
0
        /// <summary>
        /// 경품 당첨 후 개인정보 저장
        /// </summary>
        /// <param name="entry"></param>
        public DisneyStarWars2018InstantLottery UpdateInstantLotteryWinner(DisneyStarWars2018InstantLottery entry)
        {
            var isWin = repo.Any(x => x.PrizeType != DisneyStarWars2018InstantLotteryPrizeType.Loser && x.Mobile == entry.Mobile);

            if (isWin)
            {
                throw new DisneyStarWars2018ServiceException("400", "이미 당첨된 내역이 존재합니다.당첨된 분에게는 추가 경품이 지급되지 않습니다.", entry.Mobile);
            }

            var result = repo.Update(entry);

            repo.Save();

            return(result);
        }
Beispiel #4
0
        public void TryCreateInstantLotterySuccess()
        {
            //arrange
            var prizes = new List <DisneyStarWars2018InstantLotteryPrizeSetting>()
            {
                new DisneyStarWars2018InstantLotteryPrizeSetting {
                    Date = new DateTime(2018, 5, 2), PrizeType = DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty, Rate = 1.0f, TotalCount = 1, WinnerCount = 0, StartTime = 19
                },
                new DisneyStarWars2018InstantLotteryPrizeSetting {
                    Date = new DateTime(2018, 5, 2), PrizeType = DisneyStarWars2018InstantLotteryPrizeType.DisneyQuenMirror, Rate = 1.0f, TotalCount = 1, WinnerCount = 0, StartTime = 19
                },
                new DisneyStarWars2018InstantLotteryPrizeSetting {
                    Date = new DateTime(2018, 5, 2), PrizeType = DisneyStarWars2018InstantLotteryPrizeType.StarWarsCupSet, Rate = 1.0f, TotalCount = 1, WinnerCount = 0, StartTime = 19
                }
            };
            var entry = new DisneyStarWars2018InstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2018, 5, 2),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty
            };

            repo.Setup(x => x.Any(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >())).Returns(false);
            settingRepo.Setup(x => x.Filter(It.IsAny <Expression <Func <DisneyStarWars2018InstantLotteryPrizeSetting, bool> > >())).Returns(prizes.AsQueryable);
            settingRepo.Setup(x => x.SingleOrDefault(It.IsAny <Expression <Func <DisneyStarWars2018InstantLotteryPrizeSetting, bool> > >())).Returns(prizes[3]);
            var list = new List <DisneyStarWars2018InstantLottery>();

            repo.Setup(x => x.Filter(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >())).Returns(list.AsQueryable());
            repo.Setup(x => x.Add(It.IsAny <DisneyStarWars2018InstantLottery>())).Returns(entry);

            //action
            var result = service.CreateInstantLottery(entry, true);

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty);

            repo.Verify(x => x.Any(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >()), Times.Once);
            settingRepo.Verify(x => x.Filter(It.IsAny <Expression <Func <DisneyStarWars2018InstantLotteryPrizeSetting, bool> > >()), Times.Once);
            settingRepo.Verify(x => x.SingleOrDefault(It.IsAny <Expression <Func <DisneyStarWars2018InstantLotteryPrizeSetting, bool> > >()), Times.Once);
            repo.Verify(x => x.Filter(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >()), Times.Once);
            settingRepo.Verify(x => x.Update(It.IsAny <DisneyStarWars2018InstantLotteryPrizeSetting>()), Times.Once);
            repo.Verify(x => x.Add(It.IsAny <DisneyStarWars2018InstantLottery>()), Times.Once);
            repo.Verify(x => x.Save(), Times.Once);
        }
Beispiel #5
0
        /// <summary>
        /// 즉석당첨 응모
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="isChecked"></param>
        /// <returns></returns>
        public DisneyStarWars2018InstantLottery CreateInstantLottery(DisneyStarWars2018InstantLottery entry, bool isChecked)
        {
            using (var tx = new TransactionScope()) {
                var now = time.Now;

                var isWin = repo.Any(x => x.PrizeType != DisneyStarWars2018InstantLotteryPrizeType.Loser && x.IpAddress == entry.IpAddress);
                //네이버 세션 과정 생략 변수
                //isChecked = true;
                //한번이라도 당첨된사람 제거 변수
                //isWin = false;

                entry.PrizeType = DisneyStarWars2018InstantLotteryPrizeType.Loser;
                if (isChecked && !isWin)
                {
                    var prizes = settingRepo.Filter(x => x.Date == now.Date && x.StartTime <= now.Hour && x.TotalCount > x.WinnerCount && x.Rate > 0.0f).ToList();
                    entry.PrizeType = prizeSelector.SelectPrize(prizes, DisneyStarWars2018InstantLotteryPrizeType.Loser, now);

                    if (entry.PrizeType != DisneyStarWars2018InstantLotteryPrizeType.Loser)
                    {
                        var prize = settingRepo.SingleOrDefault(x => x.Date == now.Date && x.PrizeType == entry.PrizeType);
                        if (prize == null)
                        {
                            entry.PrizeType = DisneyStarWars2018InstantLotteryPrizeType.Loser;
                        }
                        else
                        {
                            prize.WinnerCount = repo.Filter(x => x.CreateDate >= now.Date && x.PrizeType == entry.PrizeType).Count() + 1;
                            settingRepo.Update(prize);
                        }
                    }
                }

                entry.CreateDate = now;
                var user = repo.Add(entry);
                repo.Save();

                tx.Complete();

                return(user);
            }
        }
Beispiel #6
0
        public void TryGetInstantLotteryWinnerSuccess()
        {
            var entry = new DisneyStarWars2018InstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2018, 5, 2),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.PC,
                PrizeType  = DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty
            };

            repo.Setup(x => x.SingleOrDefault(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >())).Returns(entry);

            //action
            var result = service.GetInstantLotteryWinner(1);

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty);

            repo.Verify(x => x.SingleOrDefault(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >()), Times.Once);
        }
Beispiel #7
0
        public void TryCreateInstantLotteryFailedByIsWinIpAddress()
        {
            var entry = new DisneyStarWars2018InstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2018, 11, 4),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = DisneyStarWars2018InstantLotteryPrizeType.Loser
            };

            repo.Setup(x => x.Any(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >())).Returns(true);
            repo.Setup(x => x.Add(It.IsAny <DisneyStarWars2018InstantLottery>())).Returns(entry);

            //action
            var result = service.CreateInstantLottery(entry, true);

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, DisneyStarWars2018InstantLotteryPrizeType.Loser);

            repo.Verify(x => x.Any(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >()), Times.Once);
            repo.Verify(x => x.Add(It.IsAny <DisneyStarWars2018InstantLottery>()), Times.Once);
            repo.Verify(x => x.Save(), Times.Once);
        }