Example #1
0
        public async Task ThrowArgumentException_WhenPassedInvalidId(string invalidId)
        {
            // Arrange
            Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();
            Mock <DataContext>       dataContextMock      = new Mock <DataContext>();

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

            // Assert
            await Assert.ThrowsExceptionAsync <ArgumentException>(async() =>
                                                                  await SUT.FindAsync(invalidId));
        }
Example #2
0
        public async Task FindAsync_ShouldReturnTournament_WhenPassedValidParameters()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <DataContext>()
                                 .UseInMemoryDatabase(databaseName: "FindAsync_ShouldReturnTournament_WhenPassedValidParameters")
                                 .Options;

            Guid validId = Guid.NewGuid();

            Tournament validTournament = new Tournament
            {
                Id   = validId,
                Name = "testTournament"
            };

            Tournament result = null;

            // 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.FindAsync(validId.ToString());
            }

            // Assert
            using (DataContext assertContext = new DataContext(contextOptions))
            {
                Assert.IsTrue(assertContext.Tournaments.Any(c => c.Id.Equals(result.Id)));
                Assert.IsTrue(assertContext.Tournaments.Any(c => c.Name.Equals(result.Name)));
            }
        }