public async Task GetPostsAsync_WithSlug_RequestsToCorrectEndpoint() { var mockHttp = CreateMockHttp($"{PostsEndpoint}slug/welcome?fields=title%2cslug%2chtml%2cpublished_at&key=content_api_key", "{}"); var ghostClient = new GhostClient(mockHttp.ToHttpClient(), ApiUrl, ContentApiKey); var queryBuilder = new GhostQueryBuilder <PostContent>() .Slug("welcome"); await ghostClient.GetPostsAsync(queryBuilder); mockHttp.VerifyNoOutstandingExpectation(); }
public async Task GetPostsAsync_ThrowsException_WhenApiReturnsInvalidData() { var invalidResponse = "123"; var mockHttp = CreateMockHttp($"{PostsEndpoint}?fields=title%2cslug%2chtml%2cpublished_at&key=content_api_key", invalidResponse); var ghostClient = new GhostClient(mockHttp.ToHttpClient(), ApiUrl, ContentApiKey); var queryBuilder = new GhostQueryBuilder <PostContent>(); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await ghostClient.GetPostsAsync(queryBuilder); }); mockHttp.VerifyNoOutstandingExpectation(); }
public async Task GetPostsAsync_ReturnsCorrectly() { var actualGhostResponse = TestData.GhostResponseJson; var mockHttp = CreateMockHttp( $"{PostsEndpoint}?fields=title%2cslug%2chtml%2cpublished_at&key=content_api_key", actualGhostResponse); var ghostClient = new GhostClient(mockHttp.ToHttpClient(), ApiUrl, ContentApiKey); var queryBuilder = new GhostQueryBuilder <PostContent>(); // Act var actual = await ghostClient.GetPostsAsync(queryBuilder); var expected = TestData.PostsResponse; Assert.Equal(expected.Posts, actual?.Posts); Assert.Equal(expected.Meta, actual?.Meta); }