Example #1
0
        public async Task FilterTournamentsAsync_ShouldReturnTournaments_WhenPassedValidParameters()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <DataContext>()
                                 .UseInMemoryDatabase(databaseName: "FilterTournamentsAsync_ShouldReturnTournaments_WhenPassedValidParameters")
                                 .Options;

            string validSortOrder  = "name_asc";
            string validFilter     = "testTournament";
            int    validPageSize   = 10;
            int    validPageNumber = 1;

            string validSlug         = "Test";
            string validName         = "testTournament";
            int    validPandaScoreId = 123;

            Tournament validTournament = new Tournament
            {
                Id           = Guid.NewGuid(),
                Name         = validName,
                PandaScoreId = validPandaScoreId,
                Slug         = validSlug
            };

            IEnumerable <Tournament> result = new List <Tournament>();

            // Act
            using (DataContext actContext = new DataContext(contextOptions))
            {
                Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();

                await actContext.Tournaments.AddAsync(validTournament);

                await actContext.SaveChangesAsync();

                TournamentService SUT = new TournamentService(
                    pandaScoreClientMock.Object,
                    actContext);

                result = await SUT.FilterTournamentsAsync(validSortOrder, validFilter, validPageNumber, validPageSize);
            }

            // Assert
            using (DataContext assertContext = new DataContext(contextOptions))
            {
                var tournament = result.ToArray()[0];

                Assert.IsTrue(assertContext.Tournaments.Count().Equals(result.Count()));
                Assert.IsTrue(assertContext.Tournaments.Any(t => t.Name.Equals(tournament.Name)));
                Assert.IsTrue(assertContext.Tournaments.Any(t => t.Slug.Equals(tournament.Slug)));
            }
        }
        public async Task ThrowArgumentOutOfRangeException_WhenPassedInvalidPageSize(int invalidPageSize)
        {
            // Arrange
            Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();
            Mock <DataContext>       dataContextMock      = new Mock <DataContext>();

            string validSortOrder  = string.Empty;
            string validFilter     = string.Empty;
            int    validPageNumber = 1;

            TournamentService SUT = new TournamentService(
                pandaScoreClientMock.Object,
                dataContextMock.Object);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(
                () => SUT.FilterTournamentsAsync(validSortOrder, validFilter, validPageNumber, invalidPageSize));
        }