public void Find_ShouldReturnAllDrawsOfAGameWhenThereAreNoDateLimits()
        {
            //Arrange
            var someGame      = new LotteryGameBuilder().WithRandomDraws(5, 10).Build();
            var someOtherGame = new LotteryGameBuilder().WithRandomDraws(5, 10).Build();

            using (var context = CreateDbContext())
            {
                context.Add(someGame);
                context.Add(someOtherGame);
                context.SaveChanges();
            }

            using (var context = CreateDbContext())
            {
                var repo = new DrawRepository(context);

                //Act
                var draws = repo.Find(someGame.Id, null, null);

                //Assert
                Assert.That(draws, Is.Not.Null, () => "No draws are returned.");
                Assert.That(draws.Count, Is.Not.GreaterThan(someGame.Draws.Count), () => "Too much draws are returned.");
                Assert.That(draws.Count, Is.EqualTo(someGame.Draws.Count), () => "All the draws of a game should be returned.");
                Assert.That(draws, Has.All.Matches((Draw draw) => draw.LotteryGameId == someGame.Id),
                            () =>
                            "Only draws of the lottery game with an 'Id' that matches the 'lotterGameId' parameter, should be returned.");
            }
        }
        public void Find_ShouldIncludeTheDrawNumbersOfTheReturnedDraws()
        {
            //Arrange
            var someGame = new LotteryGameBuilder().WithRandomDraws(1, 1).Build();

            using (var context = CreateDbContext())
            {
                context.Add(someGame);
                context.SaveChanges();
            }

            using (var context = CreateDbContext())
            {
                var repo = new DrawRepository(context);

                //Act
                var draws = repo.Find(someGame.Id, null, null);

                //Assert
                Assert.That(draws, Is.Not.Null, () => "No draws are returned.");
                var firstDraw = draws.FirstOrDefault();
                Assert.That(firstDraw, Is.Not.Null, () => "No draws are returned.");

                Assert.That(firstDraw.DrawNumbers, Is.Not.Empty, () => "The draw numbers of the draws are not returned from the database.");
            }
        }
Beispiel #3
0
        private void TestFindForDateRange(int gameId, DateTime?fromDate, DateTime?untilDate, IList <Draw> expectedDraws)
        {
            using (var context = CreateDbContext())
            {
                var repo = new DrawRepository(context);

                //Act
                var draws = repo.Find(gameId, fromDate, untilDate);

                //Assert
                Assert.That(draws, Is.Not.Empty, () => "No draws are returned.");

                Assert.That(draws, Has.Count.LessThanOrEqualTo(expectedDraws.Count),
                            () => "One or more draws that are out of range are returned.");

                Assert.That(draws, Has.Count.EqualTo(expectedDraws.Count),
                            () => "Not all draws that match the date range are returned. " +
                            "Make sure you also include the draws exactly on the from date or until date.");
            }
        }
        public void Find_ShouldCreateAndCloseConnection()
        {
            var game = GetAllGames().First(g => g.Name == "Normal");

            AssertConnectionIsCreatedAndClosed(() => _repository.Find(game.Id, null, null));
        }