Skip to content

Commit

Permalink
Clean up some compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdecock committed Aug 28, 2024
1 parent 2849247 commit fa5d101
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task when_UserService_gives_anonymous_user_GetAuthState_returns_ano
Substitute.For<ILogger<BffClientAuthenticationStateProvider>>());

var authState = await sut.GetAuthenticationStateAsync();
authState.User.Identity.IsAuthenticated.ShouldBeFalse();
authState.User.Identity?.IsAuthenticated.ShouldBeFalse();
}

[Fact]
Expand All @@ -42,9 +42,9 @@ public async Task when_UserService_returns_persisted_user_GetAuthState_returns_t
Substitute.For<ILogger<BffClientAuthenticationStateProvider>>());

var authState = await sut.GetAuthenticationStateAsync();
authState.User.Identity.IsAuthenticated.ShouldBeTrue();
authState.User.Identity.Name.ShouldBe(expectedName);
userService.Received(1).GetUserAsync();
authState.User.Identity?.IsAuthenticated.ShouldBeTrue();
authState.User.Identity?.Name.ShouldBe(expectedName);
await userService.Received(1).GetUserAsync();
}

[Fact]
Expand All @@ -70,27 +70,27 @@ public async Task after_configured_delay_UserService_is_called_again_and_state_n
var authState = await sut.GetAuthenticationStateAsync();

// Initially, we have called the user service once to initialize
userService.Received(1).GetUserAsync();
await userService.Received(1).GetUserAsync();

// Advance time within the polling delay, and note that we still haven't made additional calls
time.Advance(TimeSpan.FromSeconds(1)); // t = 1
userService.Received(1).GetUserAsync();
await userService.Received(1).GetUserAsync();

// Advance time past the polling delay, and note that we make an additional call
time.Advance(TimeSpan.FromSeconds(2)); // t = 3
userService.Received(1).GetUserAsync(true);
userService.Received(1).GetUserAsync(false);
await userService.Received(1).GetUserAsync(true);
await userService.Received(1).GetUserAsync(false);

// Advance time within the polling interval, but more than the polling delay
// We don't expect additional calls yet
time.Advance(TimeSpan.FromSeconds(3)); // t = 6
userService.Received(1).GetUserAsync(true);
userService.Received(1).GetUserAsync(false);
await userService.Received(1).GetUserAsync(true);
await userService.Received(1).GetUserAsync(false);

// Advance time past the polling interval, and note that we make an additional call
time.Advance(TimeSpan.FromSeconds(10)); // t = 16
userService.Received(1).GetUserAsync(true);
userService.Received(2).GetUserAsync(false);
await userService.Received(1).GetUserAsync(true);
await userService.Received(2).GetUserAsync(false);
}

[Fact]
Expand All @@ -101,7 +101,7 @@ public async Task timer_stops_when_user_logs_out()
var time = new FakeTimeProvider();

var anonymousUser = new ClaimsPrincipal(new ClaimsIdentity());
anonymousUser.Identity.IsAuthenticated.ShouldBeFalse();
anonymousUser.Identity?.IsAuthenticated.ShouldBeFalse();

var cachedUser = new ClaimsPrincipal(new ClaimsIdentity(
[
Expand Down Expand Up @@ -130,17 +130,17 @@ public async Task timer_stops_when_user_logs_out()

var authState = await sut.GetAuthenticationStateAsync();
time.Advance(TimeSpan.FromSeconds(5));
userService.Received(1).GetUserAsync(true);
userService.Received(1).GetUserAsync(false);
await userService.Received(1).GetUserAsync(true);
await userService.Received(1).GetUserAsync(false);

time.Advance(TimeSpan.FromSeconds(10));
userService.Received(1).GetUserAsync(true);
userService.Received(2).GetUserAsync(false);
await userService.Received(1).GetUserAsync(true);
await userService.Received(2).GetUserAsync(false);


time.Advance(TimeSpan.FromSeconds(50));
userService.Received(1).GetUserAsync(true);
userService.Received(2).GetUserAsync(false);
await userService.Received(1).GetUserAsync(true);
await userService.Received(2).GetUserAsync(false);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void When_base_address_option_is_default_AddRemoteApiHttpClient_for_typed

var sp = sut.BuildServiceProvider();
var wrapper = sp.GetService<ResolvesTypedClients>();
var httpClient = wrapper.Client;
var httpClient = wrapper?.Client;
httpClient.ShouldNotBeNull();
httpClient.BaseAddress.ShouldNotBeNull();
httpClient.BaseAddress.AbsoluteUri.ShouldBe(expectedBaseAddress);
Expand All @@ -165,7 +165,7 @@ public void When_base_address_option_is_default_AddRemoteApiHttpClient_for_typed

var sp = sut.BuildServiceProvider();
var wrapper = sp.GetService<ResolvesTypedClients>();
var httpClient = wrapper.Client;
var httpClient = wrapper?.Client;
httpClient.ShouldNotBeNull();
httpClient.BaseAddress.ShouldNotBeNull();
httpClient.BaseAddress.AbsoluteUri.ShouldBe(expectedBaseAddress);
Expand All @@ -185,7 +185,7 @@ public void AddBffBlazorClient_can_set_options_with_callback()
sut.AddBffBlazorClient(opt => opt.RemoteApiPath = expectedConfiguredValue);
var sp = sut.BuildServiceProvider();
var opts = sp.GetService<IOptions<BffBlazorOptions>>();
opts.Value.ShouldNotBeNull();
opts.ShouldNotBeNull();
opts.Value.RemoteApiPath.ShouldBe(expectedConfiguredValue);
}
}

0 comments on commit fa5d101

Please sign in to comment.