Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 6965a66

Browse files
committed
#59 - Use Task.GetAwaiter().GetResult() instead of Task.Result.
1 parent e315a54 commit 6965a66

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public CookieAuthenticationHandler([NotNull] ILogger logger)
3636

3737
protected override AuthenticationTicket AuthenticateCore()
3838
{
39-
return AuthenticateCoreAsync().Result;
39+
return AuthenticateCoreAsync().GetAwaiter().GetResult();
4040
}
4141

4242
protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
@@ -124,7 +124,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
124124

125125
protected override void ApplyResponseGrant()
126126
{
127-
ApplyResponseGrantAsync().Wait();
127+
ApplyResponseGrantAsync().GetAwaiter().GetResult();
128128
}
129129

130130
protected override async Task ApplyResponseGrantAsync()

src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public async Task<bool> InvokeReturnPathAsync()
8484

8585
protected override AuthenticationTicket AuthenticateCore()
8686
{
87-
return AuthenticateCoreAsync().Result;
87+
return AuthenticateCoreAsync().GetAwaiter().GetResult();
8888
}
8989

9090
protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()

src/Microsoft.AspNet.Security.OAuth/OAuthBearerAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public OAuthBearerAuthenticationHandler(ILogger logger, string challenge)
2121

2222
protected override AuthenticationTicket AuthenticateCore()
2323
{
24-
return AuthenticateCoreAsync().Result;
24+
return AuthenticateCoreAsync().GetAwaiter().GetResult();
2525
}
2626

2727
protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()

src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public override async Task<bool> InvokeAsync()
4646

4747
protected override AuthenticationTicket AuthenticateCore()
4848
{
49-
return AuthenticateCoreAsync().Result;
49+
return AuthenticateCoreAsync().GetAwaiter().GetResult();
5050
}
5151

5252
protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
@@ -124,7 +124,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
124124
}
125125
protected override void ApplyResponseChallenge()
126126
{
127-
ApplyResponseChallengeAsync().Wait();
127+
ApplyResponseChallengeAsync().GetAwaiter().GetResult();
128128
}
129129

130130
protected override async Task ApplyResponseChallengeAsync()

src/Microsoft.AspNet.Security/DefaultAuthorizationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public async Task<bool> AuthorizeAsync(IEnumerable<Claim> claims, ClaimsPrincipa
8484

8585
public bool Authorize(IEnumerable<Claim> claims, ClaimsPrincipal user, object resource)
8686
{
87-
return AuthorizeAsync(claims, user, resource).Result;
87+
return AuthorizeAsync(claims, user, resource).GetAwaiter().GetResult();
8888
}
8989

9090
private bool ClaimsMatch([NotNull] IEnumerable<Claim> x, [NotNull] IEnumerable<Claim> y)

src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public AuthenticationTicket Authenticate()
183183
() =>
184184
{
185185
return Task.FromResult(AuthenticateCore());
186-
}).Result;
186+
}).GetAwaiter().GetResult();
187187
}
188188

189189
protected abstract AuthenticationTicket AuthenticateCore();
@@ -225,7 +225,7 @@ private void ApplyResponse()
225225
{
226226
ApplyResponseCore();
227227
return Task.FromResult(0);
228-
}).Wait(); // Block if the async version is in progress.
228+
}).GetAwaiter().GetResult(); // Block if the async version is in progress.
229229
}
230230

231231
protected virtual void ApplyResponseCore()

test/Microsoft.AspNet.Security.Test/DefaultAuthorizationServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void Check_ShouldThrowWhenPoliciesDontStop()
242242

243243
// Act
244244
// Assert
245-
Exception ex = Assert.Throws<AggregateException>(() => authorizationService.Authorize(Enumerable.Empty<Claim>(), null));
245+
Exception ex = Assert.Throws<InvalidOperationException>(() => authorizationService.Authorize(Enumerable.Empty<Claim>(), null));
246246
}
247247

248248
[Fact]

0 commit comments

Comments
 (0)