Beispiel #1
0
        public void Test_that_lottery_is_added()
        {
            // arrange
            var lottery = new Mock <ILottery>();

            lottery.SetupAllProperties();
            lottery.SetupGet(x => x.Name).Returns("owdwo");
            lottery.SetupGet(x => x.Description).Returns("owdwo");
            lottery.SetupGet(x => x.DateOfDraw).Returns(new System.DateTime(2017, 1, 1));
            LotteryRepository repo = new LotteryRepository();

            // act
            repo.Save(lottery.Object);

            // assert
            Assert.That(repo.GetAllLottery().Count() == 1);
        }
Beispiel #2
0
        public void Test_that_lottery_is_updated()
        {
            // arrange
            var lotteryName = "follo";

            Data.Lottery lottery = new Data.Lottery();
            var          repo    = new LotteryRepository();

            repo.Save(lotteries[0]);
            var winningPrimary = new List <PrimaryNumbers>()
            {
                new PrimaryNumbers()
                {
                    Value = 1
                },
                new PrimaryNumbers()
                {
                    Value = 49
                },
            };

            var winningSecondary = new List <SecondaryNumbers>()
            {
                new SecondaryNumbers()
                {
                    Value = 2
                },
                new SecondaryNumbers()
                {
                    Value = 10
                },
            };

            // act
            var messages = repo.SaveWinningNumbers(lotteryName, winningPrimary, winningSecondary);

            // assert
            Assert.That(messages.Count == 0);
        }
Beispiel #3
0
        public void Test_that_shows_message_when_numbers_not_in_range()
        {
            // arrange
            var lotteryName = "urbod";

            Data.Lottery lottery = new Data.Lottery();
            var          repo    = new LotteryRepository();

            repo.Save(lotteries[1]);
            var winningPrimary = new List <PrimaryNumbers>()
            {
                new PrimaryNumbers()
                {
                    Value = 1
                },
                new PrimaryNumbers()
                {
                    Value = 49
                },
            };

            var winningSecondary = new List <SecondaryNumbers>()
            {
                new SecondaryNumbers()
                {
                    Value = 2
                },
                new SecondaryNumbers()
                {
                    Value = 10
                },
            };

            // act
            var messages = repo.SaveWinningNumbers(lotteryName, winningPrimary, winningSecondary);

            // assert
            Assert.That(messages.Count > 0);
        }
Beispiel #4
0
        // POST: api/Lottery
        public IHttpActionResult Post([FromBody] Data.Lottery value)
        {
            try
            {
                LotteryRepository repo = new LotteryRepository();
                var messages           = repo.Save(value);

                if (messages.Count == 0)
                {
                    return(Ok(messages));
                }
                else
                {
                    return(BadRequest(string.Join(" ", messages)));
                }
            }
            catch (Exception exception)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = exception.Message
                });
            }
        }