Пример #1
0
        public void TryUpdateInstantLotteryWinnerFailed()
        {
            var entry = new KittyJusticeLeagueInstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2017, 11, 13),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = KittyJusticeLeagueInstantLotteryPrizeType.JoyGifticon,
                Name       = "홍길동",
                Mobile     = "01012345678",
                UpdateDate = new DateTime(2017, 11, 13)
            };

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

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

            //assert
            Assert.Matches("400", failedResult.Code);
            Assert.Matches("이미 당첨된 내역이 존재합니다.당첨된 분에게는 추가 경품이 지급되지 않습니다.", failedResult.Message);
        }
Пример #2
0
        public void TryUpdateInstantLotteryWinnerSuccess()
        {
            var entry = new KittyJusticeLeagueInstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2017, 11, 13),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = KittyJusticeLeagueInstantLotteryPrizeType.JoyGifticon,
                Name       = "홍길동",
                Mobile     = "01012345678",
                UpdateDate = new DateTime(2017, 11, 13)
            };

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

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

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, KittyJusticeLeagueInstantLotteryPrizeType.JoyGifticon);

            repo.Verify(x => x.Any(It.IsAny <Expression <Func <KittyJusticeLeagueInstantLottery, bool> > >()), Times.Once);
            repo.Verify(x => x.Update(It.IsAny <KittyJusticeLeagueInstantLottery>()), Times.Once);
            repo.Verify(x => x.Save(), Times.Once);
        }
Пример #3
0
        public void TryCreateInstantLotterySuccess()
        {
            //arrange
            var prizes = new List <KittyJusticeLeagueInstantLotteryPrizeSetting>()
            {
                new KittyJusticeLeagueInstantLotteryPrizeSetting {
                    Date = new DateTime(2017, 11, 13), PrizeType = KittyJusticeLeagueInstantLotteryPrizeType.JoyGifticon, Rate = 1.0f, TotalCount = 1, WinnerCount = 0, StartTime = 19
                },
                new KittyJusticeLeagueInstantLotteryPrizeSetting {
                    Date = new DateTime(2017, 11, 13), PrizeType = KittyJusticeLeagueInstantLotteryPrizeType.JusticeLeagueNanoBlock, Rate = 1.0f, TotalCount = 1, WinnerCount = 0, StartTime = 19
                },
                new KittyJusticeLeagueInstantLotteryPrizeSetting {
                    Date = new DateTime(2017, 11, 13), PrizeType = KittyJusticeLeagueInstantLotteryPrizeType.ChirstmasTree, Rate = 1.0f, TotalCount = 1, WinnerCount = 0, StartTime = 19
                },
                new KittyJusticeLeagueInstantLotteryPrizeSetting {
                    Date = new DateTime(2017, 11, 13), PrizeType = KittyJusticeLeagueInstantLotteryPrizeType.KittyNanoBlock, Rate = 1.0f, TotalCount = 1, WinnerCount = 0, StartTime = 12
                }
            };
            var entry = new KittyJusticeLeagueInstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2017, 11, 13),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = KittyJusticeLeagueInstantLotteryPrizeType.KittyNanoBlock
            };

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

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

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

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, KittyJusticeLeagueInstantLotteryPrizeType.KittyNanoBlock);

            repo.Verify(x => x.Any(It.IsAny <Expression <Func <KittyJusticeLeagueInstantLottery, bool> > >()), Times.Once);
            settingRepo.Verify(x => x.Filter(It.IsAny <Expression <Func <KittyJusticeLeagueInstantLotteryPrizeSetting, bool> > >()), Times.Once);
            settingRepo.Verify(x => x.SingleOrDefault(It.IsAny <Expression <Func <KittyJusticeLeagueInstantLotteryPrizeSetting, bool> > >()), Times.Once);
            repo.Verify(x => x.Filter(It.IsAny <Expression <Func <KittyJusticeLeagueInstantLottery, bool> > >()), Times.Once);
            settingRepo.Verify(x => x.Update(It.IsAny <KittyJusticeLeagueInstantLotteryPrizeSetting>()), Times.Once);
            repo.Verify(x => x.Add(It.IsAny <KittyJusticeLeagueInstantLottery>()), Times.Once);
            repo.Verify(x => x.Save(), Times.Once);
        }
Пример #4
0
        public KittyJusticeLeagueInstantLottery UpdateInstantLotteryWinner(KittyJusticeLeagueInstantLottery entry)
        {
            var isWin = repo.Any(x => x.PrizeType != KittyJusticeLeagueInstantLotteryPrizeType.Loser && x.Mobile == entry.Mobile);

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

            var result = repo.Update(entry);

            repo.Save();

            return(result);
        }
Пример #5
0
        public void TryGetInstantLotteryWinnerSuccess()
        {
            var entry = new KittyJusticeLeagueInstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2017, 11, 13),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.PC,
                PrizeType  = KittyJusticeLeagueInstantLotteryPrizeType.JoyGifticon
            };

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

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

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, KittyJusticeLeagueInstantLotteryPrizeType.JoyGifticon);

            repo.Verify(x => x.SingleOrDefault(It.IsAny <Expression <Func <KittyJusticeLeagueInstantLottery, bool> > >()), Times.Once);
        }
Пример #6
0
        public KittyJusticeLeagueInstantLottery CreateInstantLottery(KittyJusticeLeagueInstantLottery entry, bool isChecked = false)
        {
            using (var tx = new TransactionScope()) {
                var now = time.Now;

                var isWin = repo.Any(x => x.PrizeType != KittyJusticeLeagueInstantLotteryPrizeType.Loser && x.IpAddress == entry.IpAddress);

                entry.PrizeType = KittyJusticeLeagueInstantLotteryPrizeType.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, KittyJusticeLeagueInstantLotteryPrizeType.Loser, now);

                    if (entry.PrizeType != KittyJusticeLeagueInstantLotteryPrizeType.Loser)
                    {
                        var prize = settingRepo.SingleOrDefault(x => x.Date == now.Date && x.PrizeType == entry.PrizeType);
                        if (prize == null)
                        {
                            entry.PrizeType = KittyJusticeLeagueInstantLotteryPrizeType.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);
            }
        }
Пример #7
0
        public void TryCreateInstantLotteryFailedByIsWinIpAddress()
        {
            var entry = new KittyJusticeLeagueInstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2017, 11, 13),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.Mobile,
                PrizeType  = KittyJusticeLeagueInstantLotteryPrizeType.Loser
            };

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

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

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

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