Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
update FluentAssertions
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Sep 23, 2022
1 parent 99831ff commit 748d907
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 5 additions & 5 deletions test/Duende.Bff.EntityFramework.Tests/UserSessionStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,10 @@ await _subject.CreateUserSessionAsync(new UserSession
}
}
[Fact]
public void GetUserSessionsAsync_for_missing_sub_and_sid_should_throw()
public async Task GetUserSessionsAsync_for_missing_sub_and_sid_should_throw()
{
Func<Task> f = () => _subject.GetUserSessionsAsync(new UserSessionsFilter());
f.Should().Throw<Exception>();
await f.Should().ThrowAsync<Exception>();
}


Expand Down Expand Up @@ -801,10 +801,10 @@ await _subject.CreateUserSessionAsync(new UserSession
}
}
[Fact]
public void DeleteUserSessionsAsync_for_missing_sub_and_sid_should_throw()
public async Task DeleteUserSessionsAsync_for_missing_sub_and_sid_should_throw()
{
Func<Task> f = () => _subject.DeleteUserSessionsAsync(new UserSessionsFilter());
f.Should().Throw<Exception>();
await f.Should().ThrowAsync<Exception>();
}

[Fact]
Expand Down Expand Up @@ -841,7 +841,7 @@ public async Task concurrent_deletes_with_exception_handler_and_detatching_shoul
await ctx1.SaveChangesAsync();

Func<Task> f1 = async () => await ctx2.SaveChangesAsync();
f1.Should().Throw<DbUpdateConcurrencyException>();
await f1.Should().ThrowAsync<DbUpdateConcurrencyException>();

try
{
Expand Down
2 changes: 1 addition & 1 deletion test/Duende.Bff.Tests/Duende.Bff.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ public async Task login_endpoint_should_accept_returnUrl()
}

[Fact]
public void login_endpoint_should_not_accept_non_local_returnUrl()
public async Task login_endpoint_should_not_accept_non_local_returnUrl()
{
Func<Task> f = () => BffHost.BrowserClient.GetAsync(BffHost.Url("/bff/login") + "?returnUrl=https://foo");
f.Should().Throw<Exception>().And.Message.Should().Contain("returnUrl");
(await f.Should().ThrowAsync<Exception>()).And.Message.Should().Contain("returnUrl");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task logout_endpoint_for_authenticated_should_require_sid()
await BffHost.BffLoginAsync("alice", "sid123");

Func<Task> f = () => BffHost.BffLogoutAsync();
f.Should().Throw<Exception>();
await f.Should().ThrowAsync<Exception>();

(await BffHost.GetIsUserLoggedInAsync()).Should().BeTrue();
}
Expand All @@ -61,7 +61,7 @@ public async Task logout_endpoint_for_authenticated_when_require_otpion_is_false
BffHost.BffOptions.RequireLogoutSessionId = false;

var response = await BffHost.BrowserClient.GetAsync(BffHost.Url("/bff/logout"));
response.StatusCode.Should().Be(302); // endsession
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // endsession
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(IdentityServerHost.Url("/connect/endsession"));
}

Expand All @@ -79,15 +79,15 @@ public async Task logout_endpoint_for_authenticated_user_without_sid_should_succ
await BffHost.IssueSessionCookieAsync("alice");

var response = await BffHost.BrowserClient.GetAsync(BffHost.Url("/bff/logout"));
response.StatusCode.Should().Be(302); // endsession
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // endsession
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(IdentityServerHost.Url("/connect/endsession"));
}

[Fact]
public async Task logout_endpoint_for_anonymous_user_without_sid_should_succeed()
{
var response = await BffHost.BrowserClient.GetAsync(BffHost.Url("/bff/logout"));
response.StatusCode.Should().Be(302); // endsession
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // endsession
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(IdentityServerHost.Url("/connect/endsession"));
}

Expand All @@ -108,19 +108,19 @@ public async Task logout_endpoint_should_accept_returnUrl()
await BffHost.BffLoginAsync("alice", "sid123");

var response = await BffHost.BrowserClient.GetAsync(BffHost.Url("/bff/logout") + "?sid=sid123&returnUrl=/foo");
response.StatusCode.Should().Be(302); // endsession
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // endsession
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(IdentityServerHost.Url("/connect/endsession"));

response = await IdentityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // logout
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // logout
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(IdentityServerHost.Url("/account/logout"));

response = await IdentityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // post logout redirect uri
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // post logout redirect uri
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(BffHost.Url("/signout-callback-oidc"));

response = await BffHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // root
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // root
response.Headers.Location.ToString().ToLowerInvariant().Should().Be("/foo");
}

Expand All @@ -130,7 +130,7 @@ public async Task logout_endpoint_should_reject_non_local_returnUrl()
await BffHost.BffLoginAsync("alice", "sid123");

Func<Task> f = () => BffHost.BrowserClient.GetAsync(BffHost.Url("/bff/logout") + "?sid=sid123&returnUrl=https://foo");
f.Should().Throw<Exception>().And.Message.Should().Contain("returnUrl");
(await f.Should().ThrowAsync<Exception>()).And.Message.Should().Contain("returnUrl");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Xunit;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Net;

namespace Duende.Bff.Tests.Endpoints.Management
{
Expand All @@ -33,7 +34,7 @@ public async Task custom_ManagementBasePath_should_affect_basepath(string path)

var response = await BffHost.BrowserClient.SendAsync(req);

response.StatusCode.Should().NotBe(404);
response.StatusCode.Should().NotBe(HttpStatusCode.NotFound);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Security.Claims;
using System.Threading.Tasks;
using Xunit;
using System.Net;

namespace Duende.Bff.Tests.Endpoints.Management
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public async Task user_endpoint_for_authenticated_user_without_csrf_header_shoul
var req = new HttpRequestMessage(HttpMethod.Get, BffHost.Url("/bff/user"));
var response = await BffHost.BrowserClient.SendAsync(req);

response.StatusCode.Should().Be(401);
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
}

[Fact]
Expand All @@ -68,7 +69,7 @@ public async Task user_endpoint_for_unauthenticated_user_should_fail()
req.Headers.Add("x-csrf", "1");
var response = await BffHost.BrowserClient.SendAsync(req);

response.StatusCode.Should().Be(401);
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions test/Duende.Bff.Tests/Endpoints/RemoteEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,21 @@ public async Task endpoints_that_disable_csrf_should_not_require_csrf_header()
}

[Fact]
public void calls_to_endpoint_without_bff_metadata_should_fail()
public async Task calls_to_endpoint_without_bff_metadata_should_fail()
{
var req = new HttpRequestMessage(HttpMethod.Get, BffHost.Url("/not_bff_endpoint"));

Func<Task> f = () => BffHost.BrowserClient.SendAsync(req);
f.Should().Throw<Exception>();
await f.Should().ThrowAsync<Exception>();
}

[Fact]
public void calls_to_bff_not_in_endpoint_routing_should_fail()
public async Task calls_to_bff_not_in_endpoint_routing_should_fail()
{
var req = new HttpRequestMessage(HttpMethod.Get, BffHost.Url("/invalid_endpoint/test"));

Func<Task> f = () => BffHost.BrowserClient.SendAsync(req);
f.Should().Throw<Exception>();
await f.Should().ThrowAsync<Exception>();
}
}
}
3 changes: 2 additions & 1 deletion test/Duende.Bff.Tests/GenericHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Duende.Bff.Tests.TestFramework;
using FluentAssertions;
using Microsoft.AspNetCore.Builder;
using System.Net;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -23,7 +24,7 @@ public async Task Test1()

var response = await host.HttpClient.GetAsync("/test");

response.StatusCode.Should().Be(204);
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
}
}
}
5 changes: 3 additions & 2 deletions test/Duende.Bff.Tests/TestFramework/GenericHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Security.Claims;
Expand Down Expand Up @@ -131,7 +132,7 @@ void ConfigureSignout(IApplicationBuilder app)
public async Task RevokeSessionCookieAsync()
{
var response = await BrowserClient.GetAsync(Url("__signout"));
response.StatusCode.Should().Be(204);
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
}


Expand Down Expand Up @@ -165,7 +166,7 @@ public async Task IssueSessionCookieAsync(params Claim[] claims)
{
_userToSignIn = new ClaimsPrincipal(new ClaimsIdentity(claims, "test", "name", "role"));
var response = await BrowserClient.GetAsync(Url("__signin"));
response.StatusCode.Should().Be(204);
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
}
public Task IssueSessionCookieAsync(AuthenticationProperties props, params Claim[] claims)
{
Expand Down
2 changes: 1 addition & 1 deletion test/Duende.Bff.Tests/TestFramework/TestBrowserClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void RemoveCookie(string uri, string name)

public async Task FollowRedirectAsync()
{
LastResponse.StatusCode.Should().Be(302);
LastResponse.StatusCode.Should().Be(HttpStatusCode.Redirect);
var location = LastResponse.Headers.Location.ToString();
await GetAsync(location);
}
Expand Down
16 changes: 8 additions & 8 deletions test/Duende.Bff.Tests/TestHosts/BffHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public async Task<List<JsonRecord>> CallUserEndpointAsync()

var response = await BrowserClient.SendAsync(req);

response.StatusCode.Should().Be(200);
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Content.Headers.ContentType.MediaType.Should().Be("application/json");

var json = await response.Content.ReadAsStringAsync();
Expand All @@ -351,16 +351,16 @@ public async Task<HttpResponseMessage> BffLoginAsync(string sub, string sid = nu
public async Task<HttpResponseMessage> BffOidcLoginAsync()
{
var response = await BrowserClient.GetAsync(Url("/bff/login"));
response.StatusCode.Should().Be(302); // authorize
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // authorize
response.Headers.Location.ToString().ToLowerInvariant().Should()
.StartWith(_identityServerHost.Url("/connect/authorize"));

response = await _identityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // client callback
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // client callback
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(Url("/signin-oidc"));

response = await BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // root
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // root
response.Headers.Location.ToString().ToLowerInvariant().Should().Be("/");

(await GetIsUserLoggedInAsync()).Should().BeTrue();
Expand All @@ -372,21 +372,21 @@ public async Task<HttpResponseMessage> BffOidcLoginAsync()
public async Task<HttpResponseMessage> BffLogoutAsync(string sid = null)
{
var response = await BrowserClient.GetAsync(Url("/bff/logout") + "?sid=" + sid);
response.StatusCode.Should().Be(302); // endsession
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // endsession
response.Headers.Location.ToString().ToLowerInvariant().Should()
.StartWith(_identityServerHost.Url("/connect/endsession"));

response = await _identityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // logout
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // logout
response.Headers.Location.ToString().ToLowerInvariant().Should()
.StartWith(_identityServerHost.Url("/account/logout"));

response = await _identityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // post logout redirect uri
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // post logout redirect uri
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(Url("/signout-callback-oidc"));

response = await BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // root
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // root
response.Headers.Location.ToString().ToLowerInvariant().Should().Be("/");

(await GetIsUserLoggedInAsync()).Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public async Task<List<JsonRecord>> CallUserEndpointAsync()

var response = await BrowserClient.SendAsync(req);

response.StatusCode.Should().Be(200);
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Content.Headers.ContentType.MediaType.Should().Be("application/json");

var json = await response.Content.ReadAsStringAsync();
Expand All @@ -192,16 +192,16 @@ public async Task<HttpResponseMessage> BffLoginAsync(string sub, string sid = nu
public async Task<HttpResponseMessage> BffOidcLoginAsync()
{
var response = await BrowserClient.GetAsync(Url("/bff/login"));
response.StatusCode.Should().Be(302); // authorize
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // authorize
response.Headers.Location.ToString().ToLowerInvariant().Should()
.StartWith(_identityServerHost.Url("/connect/authorize"));

response = await _identityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // client callback
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // client callback
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(Url("/signin-oidc"));

response = await BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // root
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // root
response.Headers.Location.ToString().ToLowerInvariant().Should().Be("/");

(await GetIsUserLoggedInAsync()).Should().BeTrue();
Expand All @@ -213,21 +213,21 @@ public async Task<HttpResponseMessage> BffOidcLoginAsync()
public async Task<HttpResponseMessage> BffLogoutAsync(string sid = null)
{
var response = await BrowserClient.GetAsync(Url("/bff/logout") + "?sid=" + sid);
response.StatusCode.Should().Be(302); // endsession
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // endsession
response.Headers.Location.ToString().ToLowerInvariant().Should()
.StartWith(_identityServerHost.Url("/connect/endsession"));

response = await _identityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // logout
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // logout
response.Headers.Location.ToString().ToLowerInvariant().Should()
.StartWith(_identityServerHost.Url("/account/logout"));

response = await _identityServerHost.BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // post logout redirect uri
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // post logout redirect uri
response.Headers.Location.ToString().ToLowerInvariant().Should().StartWith(Url("/signout-callback-oidc"));

response = await BrowserClient.GetAsync(response.Headers.Location.ToString());
response.StatusCode.Should().Be(302); // root
response.StatusCode.Should().Be(HttpStatusCode.Redirect); // root
response.Headers.Location.ToString().ToLowerInvariant().Should().Be("/");

(await GetIsUserLoggedInAsync()).Should().BeFalse();
Expand Down

0 comments on commit 748d907

Please sign in to comment.