Beispiel #1
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 #2
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 #3
0
        // PUT: api/Lottery/5
        public IHttpActionResult Put(string id, [FromBody] Data.Lottery value)
        {
            try
            {
                var repo     = new LotteryRepository();
                var messages = repo.SaveWinningNumbers(id, value.WinningPrimaryNumbers.ToList(), value.WinningSecondaryNumbers.ToList());

                if (messages.Count == 0)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest(string.Join(" ", messages)));
                }
            }
            catch (Exception exception)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = exception.Message
                });
            }
        }
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
                });
            }
        }