Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 0c82d26

Browse files
committed
Fix await warnings
Received() doesn't work well with awaited calls.
1 parent eb33c02 commit 0c82d26

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/UnitTests/GitHub.App/Models/ModelServiceTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,16 @@ public async Task VaccumsTheCache()
381381
var apiClient = Substitute.For<IApiClient>();
382382
var cache = Substitute.For<IBlobCache>();
383383
cache.InvalidateAll().Returns(Observable.Return(Unit.Default));
384+
var received = false;
385+
cache.Vacuum().Returns(x =>
386+
{
387+
received = true;
388+
return Observable.Return(Unit.Default);
389+
});
384390
var modelService = new ModelService(apiClient, cache, Substitute.For<IAvatarProvider>());
385391

386392
await modelService.InvalidateAll();
387-
await cache.Received().Vacuum();
393+
Assert.True(received);
388394
}
389395
}
390396

src/UnitTests/GitHub.App/Models/RepositoryHostTests.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,23 @@ public async Task DoesNotFallBackToOldScopesWhenGitHubAndTwoFactorAuthFailsAndEr
105105
{
106106
var apiClient = Substitute.For<IApiClient>();
107107
apiClient.HostAddress.Returns(HostAddress.GitHubDotComHostAddress);
108+
bool received1 = false, received2 = false;
108109
apiClient.GetOrCreateApplicationAuthenticationCode(Args.TwoFactorChallengCallback, null, false, true)
109-
.Returns(Observable.Throw<ApplicationAuthorization>(new TwoFactorChallengeFailedException()));
110+
.Returns(_ =>
111+
{
112+
received1 = true;
113+
return Observable.Throw<ApplicationAuthorization>(new TwoFactorChallengeFailedException());
114+
});
115+
116+
apiClient.GetOrCreateApplicationAuthenticationCode(Args.TwoFactorChallengCallback,
117+
Args.String,
118+
true,
119+
Args.Boolean)
120+
.Returns(_ =>
121+
{
122+
received2 = true;
123+
return Observable.Throw<ApplicationAuthorization>(new TwoFactorChallengeFailedException());
124+
});
110125
apiClient.GetUser().Returns(Observable.Return(CreateOctokitUser("jiminy")));
111126
var hostCache = new InMemoryBlobCache();
112127
var modelService = new ModelService(apiClient, hostCache, Substitute.For<IAvatarProvider>());
@@ -115,13 +130,8 @@ public async Task DoesNotFallBackToOldScopesWhenGitHubAndTwoFactorAuthFailsAndEr
115130

116131
await host.LogIn("aUsername", "aPassowrd");
117132

118-
apiClient.Received()
119-
.GetOrCreateApplicationAuthenticationCode(Args.TwoFactorChallengCallback, null, false, true);
120-
apiClient.DidNotReceive().GetOrCreateApplicationAuthenticationCode(
121-
Args.TwoFactorChallengCallback,
122-
Args.String,
123-
true,
124-
Args.Boolean);
133+
Assert.True(received1);
134+
Assert.False(received2);
125135
Assert.False(host.IsLoggedIn);
126136
var loginInfo = await loginCache.GetLoginAsync(HostAddress.GitHubDotComHostAddress);
127137
Assert.Equal("", loginInfo.UserName);

0 commit comments

Comments
 (0)