Skip to content

Commit

Permalink
Closes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
joergjo committed Dec 18, 2024
1 parent c2e9002 commit 14e4498
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 42 deletions.
14 changes: 9 additions & 5 deletions test/ContosoAds.ImageProcessor.IntegrationTests/ApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task Probe_Returns_OK(string uri)
using var client = _factory.CreateClient();

// Assert
using var response = await client.GetAsync(uri);
using var response = await client.GetAsync(uri, TestContext.Current.CancellationToken);

// Act
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -45,7 +45,8 @@ public async Task Options_Returns_OK()

// Assert
using var response = await client.SendAsync(
new HttpRequestMessage(HttpMethod.Options, "/thumbnail-request"));
new HttpRequestMessage(HttpMethod.Options, "/thumbnail-request"),
TestContext.Current.CancellationToken);

// Act
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand Down Expand Up @@ -81,7 +82,8 @@ public async Task Post_Returns_Ok()
{
Uri = new Uri("https://example.com/foo.jpg"),
AdId = 1
});
},
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -104,7 +106,8 @@ public async Task Post_WithMissingImage_Returns_Ok()
{
Uri = new Uri("https://example.com/foo.jpg"),
AdId = 1
});
},
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -125,7 +128,8 @@ public async Task Post_WithInvalidMessageContent_Returns_BadRequest(string? url,
// Act
using var response = await client.PostAsJsonAsync(
"/thumbnail-request",
new {Uri = url, AdId = adId});
new {Uri = url, AdId = adId},
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,15 +15,15 @@
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace ContosoAds.ImageProcessor.IntegrationTests;
internal static class TestSupport
{
private const string Jpeg = """
/9j/4AAQSkZJRgABAQAASABIAAD/4QBARXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAoKADAAQAAAABAAAAoAAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/8AAEQgAoACgAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/bAEMAAQEBAQEBAgEBAgICAgICAwICAgIDBAMDAwMDBAUEBAQEBAQFBQUFBQUFBQYGBgYGBgcHBwcHCAgICAgICAgICP/bAEMBAQEBAgICAwICAwgFBAUICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICP/dAAQACv/aAAwDAQACEQMRAD8A/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9D+d+iiiv8AtwP8vwooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//0f536KKK/wC3A/y/CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//S/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9P+d+iiiv8AtwP8vwooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//1P536KKK/wC3A/y/CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//V/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9b+d+iiiv8AtwP8vwooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//1/536KKK/wC3A/y/CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//Q/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9k=
""";
/9j/4AAQSkZJRgABAQAASABIAAD/4QBARXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAoKADAAQAAAABAAAAoAAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/8AAEQgAoACgAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/bAEMAAQEBAQEBAgEBAgICAgICAwICAgIDBAMDAwMDBAUEBAQEBAQFBQUFBQUFBQYGBgYGBgcHBwcHCAgICAgICAgICP/bAEMBAQEBAgICAwICAwgFBAUICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICP/dAAQACv/aAAwDAQACEQMRAD8A/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9D+d+iiiv8AtwP8vwooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//0f536KKK/wC3A/y/CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//S/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9P+d+iiiv8AtwP8vwooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//1P536KKK/wC3A/y/CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//V/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9b+d+iiiv8AtwP8vwooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//1/536KKK/wC3A/y/CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//Q/nfooor/ALcD/L8KKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9k=
""";

internal static byte[] JpegBytes => Convert.FromBase64String(Jpeg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,15 +14,15 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task It_Renders_ThumbnailSize(string imageBase64, int expectedWidth

// Assert
result.Position = 0;
using var image = await Image.LoadAsync(result);
using var image = await Image.LoadAsync(result, TestContext.Current.CancellationToken);
Assert.Equal(expectedWidth, image.Width);
Assert.Equal(expectedHeight, image.Height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,15 +20,15 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="System.Net.Http.Json" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Probe_Returns_OK(string uri)
using var client = _factory.CreateClient();

// Assert
using var response = await client.GetAsync(uri);
using var response = await client.GetAsync(uri, TestContext.Current.CancellationToken);

// Act
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public async Task Options_Returns_Ok()

// Act
using var response = await client.SendAsync(
new HttpRequestMessage(HttpMethod.Options, "/thumbnail-result"));
new HttpRequestMessage(HttpMethod.Options, "/thumbnail-result"),
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand Down Expand Up @@ -59,7 +60,8 @@ await _factory.SeedDatabaseAsync(
{
Uri = new Uri(thumbnailUri),
AdId = adId
});
},
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -79,7 +81,8 @@ public async Task Post_WithMissingAd_Returns_Ok()
{
Uri = new Uri("https://contosoads.blob.core.windows.net/images/thumbnail.jpg"),
AdId = 1
});
},
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Expand All @@ -100,7 +103,8 @@ public async Task Post_WithInvalidContent_Returns_BadRequest(string? uri, string
// Act
using var response = await client.PostAsJsonAsync(
"/thumbnail-result",
new {uri, adId});
new {uri, adId},
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task Get_Returns_OkAndPage(string action, string pageTitle)
using var client = _factory.CreateClient();

// Act
using var response = await client.GetAsync($"/ads/{action}/{id}");
using var response = await client.GetAsync($"/ads/{action}/{id}", TestContext.Current.CancellationToken);

// Assert
using var document = await response.ToDocumentAsync();
Expand All @@ -64,7 +64,7 @@ public async Task Get_WithInvalidId_Returns_NotFound(string id, string action)
using var client = _factory.CreateClient();

// Act
using var response = await client.GetAsync($"/ads/{action}/{id}");
using var response = await client.GetAsync($"/ads/{action}/{id}", TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
Expand Down
10 changes: 6 additions & 4 deletions test/ContosoAds.Web.IntegrationTests/Pages/Ads/CreateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task Get_Returns_OkAndPage(string uri)
using var client = _factory.CreateClient();

// Act
using var response = await client.GetAsync(uri);
using var response = await client.GetAsync(uri, TestContext.Current.CancellationToken);

// Assert
using var document = await response.ToDocumentAsync();
Expand All @@ -46,7 +46,9 @@ public async Task Get_WithAdditionalSegments_Returns_NotFound(string uri)
using var client = _factory.CreateClient();

// Act
using var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri));
using var response = await client.SendAsync(
new HttpRequestMessage(HttpMethod.Get, uri),
TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
Expand All @@ -60,7 +62,7 @@ public async Task Post_RedirectsTo_Ads()
const string uri = "/ads/create";
await _factory.SeedDatabaseAsync();
var client = _factory.CreateClient();
using var getResponse = await client.GetAsync(uri);
using var getResponse = await client.GetAsync(uri, TestContext.Current.CancellationToken);
using var document = await getResponse.ToDocumentAsync();
var csrfToken = document.QuerySelector("input[name=__RequestVerificationToken]")?.GetAttribute("value");

Expand All @@ -77,7 +79,7 @@ public async Task Post_RedirectsTo_Ads()
new KeyValuePair<string, string>("__RequestVerificationToken", csrfToken!)
])
};
using var postResponse = await client.SendAsync(request);
using var postResponse = await client.SendAsync(request, TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode);
Expand Down
8 changes: 4 additions & 4 deletions test/ContosoAds.Web.IntegrationTests/Pages/Ads/DeleteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ await _factory.SeedDatabaseAsync(
Title = "A car"
});
using var client = _factory.CreateClient();
using var getResponse = await client.GetAsync($"/ads/delete/1");
using var getResponse = await client.GetAsync($"/ads/delete/1", TestContext.Current.CancellationToken);
using var document = await getResponse.ToDocumentAsync();
var csrfToken = document.QuerySelector("input[name=__RequestVerificationToken]")?.GetAttribute("value");

Expand All @@ -47,7 +47,7 @@ await _factory.SeedDatabaseAsync(
new KeyValuePair<string, string>("__RequestVerificationToken", csrfToken!)
])
};
using var postResponse = await client.SendAsync(request);
using var postResponse = await client.SendAsync(request, TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode);
Expand All @@ -72,7 +72,7 @@ await _factory.SeedDatabaseAsync(
Title = "A car"
});
using var client = _factory.CreateClient();
using var getResponse = await client.GetAsync($"/ads/delete/1");
using var getResponse = await client.GetAsync($"/ads/delete/1", TestContext.Current.CancellationToken);
using var document = await getResponse.ToDocumentAsync();
var csrfToken = document.QuerySelector("input[name=__RequestVerificationToken]")?.GetAttribute("value");

Expand All @@ -84,7 +84,7 @@ await _factory.SeedDatabaseAsync(
Content = new FormUrlEncodedContent(
[new KeyValuePair<string, string>("__RequestVerificationToken", csrfToken!)])
};
using var postResponse = await client.SendAsync(request);
using var postResponse = await client.SendAsync(request, TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.NotFound, postResponse.StatusCode);
Expand Down
8 changes: 4 additions & 4 deletions test/ContosoAds.Web.IntegrationTests/Pages/Ads/EditTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ await _factory.SeedDatabaseAsync(
Title = "A car"
});
using var client = _factory.CreateClient();
using var getResponse = await client.GetAsync($"/ads/edit/1");
using var getResponse = await client.GetAsync($"/ads/edit/1", TestContext.Current.CancellationToken);
using var document = await getResponse.ToDocumentAsync();
var csrfToken = document.QuerySelector("input[name=__RequestVerificationToken]")?.GetAttribute("value");

Expand All @@ -53,7 +53,7 @@ await _factory.SeedDatabaseAsync(
new KeyValuePair<string, string>("__RequestVerificationToken", csrfToken!)
])
};
using var postResponse = await client.SendAsync(request);
using var postResponse = await client.SendAsync(request, TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode);
Expand All @@ -78,7 +78,7 @@ await _factory.SeedDatabaseAsync(
Title = "A car"
});
using var client = _factory.CreateClient();
using var getResponse = await client.GetAsync($"/ads/edit/1");
using var getResponse = await client.GetAsync($"/ads/edit/1", TestContext.Current.CancellationToken);
using var document = await getResponse.ToDocumentAsync();
var csrfToken = document.QuerySelector("input[name=__RequestVerificationToken]")?.GetAttribute("value");
await _factory.SeedDatabaseAsync();
Expand All @@ -97,7 +97,7 @@ await _factory.SeedDatabaseAsync(
new KeyValuePair<string, string>("__RequestVerificationToken", csrfToken!)
])
};
using var postResponse = await client.SendAsync(request);
using var postResponse = await client.SendAsync(request, TestContext.Current.CancellationToken);

// Assert
Assert.Equal(HttpStatusCode.NotFound, postResponse.StatusCode);
Expand Down
4 changes: 2 additions & 2 deletions test/ContosoAds.Web.IntegrationTests/Pages/Ads/IndexTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task Get_Returns_OkAndPage(string uri)
using var client = _factory.CreateClient();

// Act
using var response = await client.GetAsync(uri);
using var response = await client.GetAsync(uri, TestContext.Current.CancellationToken);

// Assert
using var document = await response.ToDocumentAsync();
Expand All @@ -51,7 +51,7 @@ public async Task Get_WithCategory_Returns_OkAndPage(Category category, string d
using var client = _factory.CreateClient();

// Act
using var response = await client.GetAsync($"/ads?Category={category}");
using var response = await client.GetAsync($"/ads?Category={category}", TestContext.Current.CancellationToken);

// Assert
using var document = await response.ToDocumentAsync();
Expand Down
Loading

0 comments on commit 14e4498

Please sign in to comment.