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

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

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

            Guid validId = Guid.NewGuid();

            League validLeague = new League
            {
                Id   = validId,
                Name = "testLeague",
                URL  = "testURL"
            };

            League result = null;

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

                await actContext.Leagues.AddAsync(validLeague);

                await actContext.SaveChangesAsync();

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

                result = await SUT.FindAsync(validId.ToString());
            }

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