public async Task CreateConfigIfOneDoesNotExist()
        {
            // Arrange
            var guildId        = (ulong)1000L;
            var expectedResult = new GuildConfig {
                GuildID = guildId
            };

            // Act
            var result = await guildService.GetOrCreateConfigAsync(guildId);

            // Assert
            PropertyMatcher.Match(expectedResult, result);
            _mockGuildConfig.Verify(d => d.Add(Match.Create <GuildConfig>(g => g.GuildID == guildId)), Times.Once);
            _monkeyDbContext.Verify(c => c.SaveChangesAsync(default), Times.Once);
Beispiel #2
0
        public async Task ShouldGetLatestComic()
        {
            // Arrange
            var number = 69;
            var latestResponseHandler = PrepareMockResponseHandlerForLatest(number);
            var httpClient            = PrepareHttpClient(latestResponseHandler);

            _mockHttpClientFactory.Setup(f => f.CreateClient(It.IsAny <string>())).Returns(httpClient);

            var xkcdResponse = PrepareXkcdResponse(number);

            // Act
            var latestComic = await xkcdService.GetLatestComicAsync();

            // Assert
            PropertyMatcher.Match(xkcdResponse, latestComic);
        }
Beispiel #3
0
        public async Task GetComicByNumber()
        {
            // Arrange
            var maxNumber             = 690;
            var comicNumber           = 420;
            var latestResponseHandler = PrepareMockResponseHandlerForLatest(maxNumber);

            PrepareMockResponseHandler(latestResponseHandler, comicNumber);
            var httpClient = PrepareHttpClient(latestResponseHandler);

            _mockHttpClientFactory.Setup(f => f.CreateClient(It.IsAny <string>())).Returns(httpClient);

            var expectedComic = PrepareXkcdResponse(comicNumber);

            // Act
            var comic = await xkcdService.GetComicAsync(comicNumber);

            // Assert
            PropertyMatcher.Match(expectedComic, comic);
        }