diff --git a/.autover/changes/e128958a-1f95-4d56-9b25-9de91316fb26.json b/.autover/changes/e128958a-1f95-4d56-9b25-9de91316fb26.json new file mode 100644 index 0000000..585af4e --- /dev/null +++ b/.autover/changes/e128958a-1f95-4d56-9b25-9de91316fb26.json @@ -0,0 +1,13 @@ +{ + "Projects": [ + { + "Name": "Amazon.AspNetCore.Identity.Cognito", + "Type": "Major", + "ChangelogMessages": [ + "Updated the .NET SDK dependencies to the latest version 4.0.0-preview.4", + "Marked project as trimmable", + "Added SourceLink support" + ] + } + ] +} \ No newline at end of file diff --git a/src/Amazon.AspNetCore.Identity.Cognito/Amazon.AspNetCore.Identity.Cognito.csproj b/src/Amazon.AspNetCore.Identity.Cognito/Amazon.AspNetCore.Identity.Cognito.csproj index 7855ff2..865d496 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/Amazon.AspNetCore.Identity.Cognito.csproj +++ b/src/Amazon.AspNetCore.Identity.Cognito/Amazon.AspNetCore.Identity.Cognito.csproj @@ -1,48 +1,60 @@  - netstandard2.0;netcoreapp3.1 + netstandard2.0;netcoreapp3.1;net8.0 ../ruleset.xml - 3.0.2 true Amazon.AspNetCore.Identity.Cognito ASP.NET Core Identity Provider for Amazon Cognito Amazon.AspNetCore.Identity.Cognito Simplifies using Amazon Cognito as a membership storage solution for building ASP.NET Core web applications using ASP.NET Core Identity. Amazon Web Services - AWS;Amazon;aws-sdk-v3;Cognito;Identity + AWS;Amazon;aws-sdk-v4;Cognito;Identity https://github.com/aws/aws-aspnet-cognito-identity-provider/ LICENSE icon.png + README.md https://github.com/aws/aws-aspnet-cognito-identity-provider/ Amazon Web Services true - 3.0.2 - 3.0.2 + + true + true + true + snupkg + + 4.0.0-preview.1 + + + + true - + + - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoKeyNormalizer.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoKeyNormalizer.cs index 656d5d4..6d40b38 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoKeyNormalizer.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoKeyNormalizer.cs @@ -37,7 +37,7 @@ public string Normalize(string key) } #endif -#if NETCOREAPP3_1 +#if !NETSTANDARD2_0 /// /// Returns a normalized representation of the specified . /// diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoPasswordValidator.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoPasswordValidator.cs index c28212d..bf61f27 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoPasswordValidator.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoPasswordValidator.cs @@ -34,7 +34,7 @@ public class CognitoPasswordValidator : IPasswordValidator /// The user whose password should be validated. /// The password supplied for validation /// The task object representing the asynchronous operation, containing the - /// of the operation. + /// of the operation. public async Task ValidateAsync(UserManager manager, CognitoUser user, string password) { // Retrieve the password policy set by the user's user pool @@ -43,28 +43,31 @@ public async Task ValidateAsync(UserManager manager var errorDescriber = new IdentityErrorDescriber(); var errors = new List(); + if (password is null) + password = string.Empty; + if (password.Length < passwordPolicy.MinimumLength) { - errors.Add(errorDescriber.PasswordTooShort(passwordPolicy.MinimumLength)); + errors.Add(errorDescriber.PasswordTooShort(passwordPolicy.MinimumLength ?? 0)); } - if (!password.Any(char.IsLower) && passwordPolicy.RequireLowercase) + if (!password.Any(char.IsLower) && (passwordPolicy.RequireLowercase ?? false)) { errors.Add(errorDescriber.PasswordRequiresLower()); } - if (!password.Any(char.IsUpper) && passwordPolicy.RequireUppercase) + if (!password.Any(char.IsUpper) && (passwordPolicy.RequireUppercase ?? false)) { errors.Add(errorDescriber.PasswordRequiresUpper()); } - if (!password.Any(char.IsNumber) && passwordPolicy.RequireNumbers) + if (!password.Any(char.IsNumber) && (passwordPolicy.RequireNumbers ?? false)) { errors.Add(errorDescriber.PasswordRequiresDigit()); } var passwordContainsASymbol = password.IndexOfAny(CognitoSymbols) >= 0; - if (!passwordContainsASymbol && passwordPolicy.RequireSymbols) + if (!passwordContainsASymbol && (passwordPolicy.RequireSymbols ?? false)) { errors.Add(errorDescriber.PasswordRequiresNonAlphanumeric()); } diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoRoleStore.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoRoleStore.cs index 4ade177..1a1de4a 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoRoleStore.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoRoleStore.cs @@ -99,7 +99,7 @@ public virtual async Task FindByNameAsync(string roleName, CancellationTo }, cancellationToken).ConfigureAwait(false); return new CognitoRole(response.Group.GroupName, response.Group.Description, - response.Group.Precedence, response.Group.RoleArn) as TRole; + response.Group.Precedence ?? 0, response.Group.RoleArn) as TRole; } /// diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoSigninManager.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoSigninManager.cs index fb9eeb0..4b1a857 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoSigninManager.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoSigninManager.cs @@ -38,7 +38,7 @@ public class CognitoSignInManager : SignInManager where TUser : Co private const string Cognito2FAChallengeNameType = "Cognito2FAChallengeNameType"; private const string Cognito2FAProviderKey = "Amazon Cognito 2FA"; -#if NETCOREAPP3_1 +#if !NETSTANDARD2_0 public CognitoSignInManager(UserManager userManager, IHttpContextAccessor contextAccessor, IUserClaimsPrincipalFactory claimsFactory, diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserManager.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserManager.cs index 93dbc72..706a799 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserManager.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserManager.cs @@ -74,11 +74,10 @@ public override async Task FindByEmailAsync(string email) { throw new ArgumentNullException(nameof(email)); } -#if NETCOREAPP3_1 - email = NormalizeEmail(email); -#endif #if NETSTANDARD2_0 email = NormalizeKey(email); +#else + email = NormalizeEmail(email); #endif var user = await _userStore.FindByEmailAsync(email, CancellationToken).ConfigureAwait(false); if (user != null) @@ -124,11 +123,10 @@ public override async Task FindByNameAsync(string userName) { throw new ArgumentNullException(nameof(userName)); } -#if NETCOREAPP3_1 - userName = NormalizeName(userName); -#endif #if NETSTANDARD2_0 userName = NormalizeKey(userName); +#else + userName = NormalizeName(userName); #endif var user = await _userStore.FindByNameAsync(userName, CancellationToken).ConfigureAwait(false); if (user != null) @@ -180,7 +178,7 @@ private async Task PopulateTokens(TUser user, string claimType, string claimValu /// The that represents the asynchronous operation, containing the AuthFlowResponse object /// if the specified matches the one store for the , /// otherwise null. - public virtual Task CheckPasswordAsync(TUser user, string password) + public new virtual Task CheckPasswordAsync(TUser user, string password) { ThrowIfDisposed(); if (user == null) diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserClaimStore.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserClaimStore.cs index 00b63b7..1524f38 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserClaimStore.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserClaimStore.cs @@ -53,7 +53,7 @@ public virtual async Task> GetClaimsAsync(TUser user, CancellationT UserPoolId = _pool.PoolID }, cancellationToken).ConfigureAwait(false); - return details.UserAttributes.Select(att => new Claim(att.Name, att.Value)).ToList(); + return details.UserAttributes?.Select(att => new Claim(att.Name, att.Value)).ToList() ?? new List(); } catch (AmazonCognitoIdentityProviderException e) { @@ -134,10 +134,10 @@ public virtual async Task RemoveClaimsAsync(TUser user, IEnumerable claim var userClaims = await GetClaimsAsync(user, cancellationToken).ConfigureAwait(false); // Only removes the claims that the user actually have. - var matchedClaims = userClaims.Select(claim => new { claim.Type, claim.Value }) + var matchedClaims = userClaims?.Select(claim => new { claim.Type, claim.Value }) .Intersect(claims.Select(claim => new { claim.Type, claim.Value })); - if (matchedClaims.Any()) + if (matchedClaims != null && matchedClaims.Any()) { try { @@ -182,8 +182,17 @@ public async Task> GetUsersForClaimAsync(Claim claim, CancellationT UserPoolId = _pool.PoolID }, cancellationToken).ConfigureAwait(false); - return response.Users.Select(user => _pool.GetUser(user.Username, user.UserStatus, - user.Attributes.ToDictionary(att => att.Name, att => att.Value))).ToList() as IList; + return response.Users? + .Select(user => + _pool.GetUser( + user.Username, + user.UserStatus, + user.Attributes? + .ToDictionary(att => att.Name, att => att.Value) + ?? new Dictionary() + ) + ) + .ToList() as IList ?? new List(); } catch (AmazonCognitoIdentityProviderException e) { diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserEmailStore.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserEmailStore.cs index 667eb16..a66874a 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserEmailStore.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserEmailStore.cs @@ -19,6 +19,7 @@ using Amazon.Extensions.CognitoAuthentication; using Microsoft.AspNetCore.Identity; using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -46,11 +47,13 @@ public virtual async Task FindByEmailAsync(string normalizedEmail, Cancel UserPoolId = _pool.PoolID }, cancellationToken).ConfigureAwait(false); - if (result.Users.Count > 0) + if (result.Users != null && result.Users.Count > 0) { return _pool.GetUser(result.Users[0].Username, result.Users[0].UserStatus, - result.Users[0].Attributes.ToDictionary(att => att.Name, att => att.Value)) as TUser; + result.Users[0].Attributes? + .ToDictionary(att => att.Name, att => att.Value) ?? + new Dictionary()) as TUser; } } catch (AmazonCognitoIdentityProviderException e) diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserRoleStore.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserRoleStore.cs index cc09ee1..57f31d1 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserRoleStore.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserRoleStore.cs @@ -112,7 +112,10 @@ public virtual async Task CreateAsync(TUser user, IDictionary(), + validationData ?? new Dictionary()).ConfigureAwait(false); return IdentityResult.Success; } catch (AmazonCognitoIdentityProviderException e) @@ -191,9 +194,9 @@ public virtual async Task UpdateAsync(TUser user, CancellationTo { // Only update user writable attributes. var clientConfig = await _pool.GetUserPoolClientConfiguration().ConfigureAwait(false); - var newValues = clientConfig.WriteAttributes + var newValues = clientConfig.WriteAttributes? .Where(key => user.Attributes.ContainsKey(key)) - .ToDictionary(key => key, key => user.Attributes[key]); + .ToDictionary(key => key, key => user.Attributes[key]) ?? new Dictionary(); await _cognitoClient.AdminUpdateUserAttributesAsync(new AdminUpdateUserAttributesRequest { @@ -218,7 +221,7 @@ await _cognitoClient.AdminUpdateUserAttributesAsync(new AdminUpdateUserAttribute internal List CreateAttributeList(IDictionary attributeDict) { List attributeList = new List(); - foreach (KeyValuePair data in attributeDict) + foreach (KeyValuePair data in attributeDict ?? new Dictionary()) { AttributeType attribute = new AttributeType() { @@ -315,7 +318,7 @@ public virtual async Task> GetRolesAsync(TUser user, CancellationT UserPoolId = _pool.PoolID }, cancellationToken).ConfigureAwait(false); - return response.Groups.Select(group => group.GroupName).ToList(); + return response.Groups?.Select(group => group.GroupName).ToList() ?? new List(); } catch (AmazonCognitoIdentityProviderException e) { @@ -341,7 +344,7 @@ public virtual async Task IsInRoleAsync(TUser user, string roleName, Cance } var userRoles = await GetRolesAsync(user, cancellationToken).ConfigureAwait(false); - return userRoles.Contains(roleName); + return userRoles?.Contains(roleName) ?? false; } /// @@ -364,8 +367,16 @@ public virtual async Task> GetUsersInRoleAsync(string roleName, Can UserPoolId = _pool.PoolID }, cancellationToken).ConfigureAwait(false); - return response.Users.Select(user => _pool.GetUser(user.Username, user.UserStatus, - user.Attributes.ToDictionary(att => att.Name, att => att.Value))).ToList() as IList; + return response.Users? + .Select(user => + _pool.GetUser( + user.Username, + user.UserStatus, + user.Attributes? + .ToDictionary(att => att.Name, att => att.Value) + ?? new Dictionary() + ) + ).ToList() as IList ?? new List(); } catch (AmazonCognitoIdentityProviderException e) { diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserTwoFactorStore.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserTwoFactorStore.cs index b47b9de..7c365a8 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserTwoFactorStore.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.IUserTwoFactorStore.cs @@ -54,7 +54,7 @@ public virtual async Task GetTwoFactorEnabledAsync(TUser user, Cancellatio { var userSettings = await _cognitoClient.AdminGetUserAsync(request, cancellationToken).ConfigureAwait(false); - return userSettings.MFAOptions.Count > 0; + return userSettings.MFAOptions?.Count > 0; } catch (AmazonCognitoIdentityProviderException e) { diff --git a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.cs b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.cs index 0d71dcc..10be1a6 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserStore/CognitoUserStore.cs @@ -298,11 +298,11 @@ public virtual async Task> GetUsersAsync(CognitoAttribu throw new CognitoServiceException("Failed to retrieve the list of users from Cognito.", e); } - foreach (var user in response.Users) + foreach (var user in response.Users ?? new List()) { result.Add(new CognitoUser(user.Username, _pool.ClientID, _pool, _cognitoClient, null, user.UserStatus.Value, user.Username, - user.Attributes.ToDictionary(attribute => attribute.Name, attribute => attribute.Value))); + user.Attributes?.ToDictionary(attribute => attribute.Name, attribute => attribute.Value) ?? new Dictionary())); } } while (!string.IsNullOrEmpty(response.PaginationToken)); @@ -327,7 +327,7 @@ public virtual async Task CreateAsync(TUser user, string passwor try { - await _pool.SignUpAsync(user.UserID, password, user.Attributes, validationData).ConfigureAwait(false); + await _pool.SignUpAsync(user.UserID, password, user.Attributes ?? new Dictionary(), validationData).ConfigureAwait(false); return IdentityResult.Success; } catch (AmazonCognitoIdentityProviderException e) @@ -509,7 +509,7 @@ private async Task GetAttributeValueAsync(TUser user, string attributeNa } var clientConfig = await _pool.GetUserPoolClientConfiguration().ConfigureAwait(false); - if (!clientConfig.ReadAttributes.Contains(attributeName)) + if (!clientConfig.ReadAttributes?.Contains(attributeName) ?? true) { throw new NotAuthorizedException(string.Format("Reading attribute {0} is not allowed by the user pool client configuration.", attributeName)); } @@ -543,7 +543,7 @@ private async Task SetAttributeValueAsync(TUser user, string attributeName, stri var clientConfig = await _pool.GetUserPoolClientConfiguration().ConfigureAwait(false); - if (!clientConfig.WriteAttributes.Contains(attributeName)) + if (!clientConfig.WriteAttributes?.Contains(attributeName) ?? true) { throw new NotAuthorizedException(string.Format("Writing to attribute {0} is not allowed by the user pool client configuration.", attributeName)); } diff --git a/src/Amazon.AspNetCore.Identity.Cognito/Extensions/CognitoServiceCollectionExtensions.cs b/src/Amazon.AspNetCore.Identity.Cognito/Extensions/CognitoServiceCollectionExtensions.cs index d645440..cbfe71e 100644 --- a/src/Amazon.AspNetCore.Identity.Cognito/Extensions/CognitoServiceCollectionExtensions.cs +++ b/src/Amazon.AspNetCore.Identity.Cognito/Extensions/CognitoServiceCollectionExtensions.cs @@ -23,11 +23,17 @@ using System; using System.Linq; using System.Reflection; +#if NET8_0 +using System.Diagnostics.CodeAnalysis; +#endif namespace Microsoft.Extensions.DependencyInjection { public static class CognitoServiceCollectionExtensions { +#if NET8_0 + [RequiresUnreferencedCode("Identity middleware does not currently support trimming or native AOT.", Url = "https://aka.ms/aspnet/trimming")] +#endif public static IServiceCollection AddCognitoIdentity(this IServiceCollection services, Action identityOptions = null, string prefix = null) { services.InjectCognitoUser(identityOptions); @@ -35,7 +41,9 @@ public static IServiceCollection AddCognitoIdentity(this IServiceCollection serv services.TryAddCognitoUserPool(); return services; } - +#if NET8_0 + [RequiresUnreferencedCode("Identity middleware does not currently support trimming or native AOT.", Url = "https://aka.ms/aspnet/trimming")] +#endif private static IServiceCollection InjectCognitoUser(this IServiceCollection services, Action identityOptions = null) where TUser : CognitoUser { if (identityOptions != null) diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj index 0eb9be0..3c9cf78 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj @@ -1,18 +1,18 @@ - Library - netcoreapp3.1 + net8.0 Major - - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoSigninManagerTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoSigninManagerTests.cs index eb5d045..6701c94 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoSigninManagerTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoSigninManagerTests.cs @@ -38,18 +38,18 @@ public CognitoSigninManagerTests() : base() } [Fact] - public async void Test_GivenAnUnknownUser_WhenPasswordSignIn_ThenReturnSigninResultFailed() + public async Task Test_GivenAnUnknownUser_WhenPasswordSignIn_ThenReturnSigninResultFailed() { var signinResult = SignInResult.Failed; CognitoUser user = null; userManagerMock.Setup(mock => mock.FindByIdAsync(It.IsAny())).Returns(Task.FromResult(user)).Verifiable(); - var output = await signinManager.PasswordSignInAsync("userId", "password", true, false).ConfigureAwait(false); + var output = await signinManager.PasswordSignInAsync("userId", "password", true, false); Assert.Equal(signinResult, output); userManagerMock.Verify(); } [Fact] - public async void Test_GivenAUserWithWrongPassword_WhenPasswordSignIn_ThenReturnSigninResultFailed() + public async Task Test_GivenAUserWithWrongPassword_WhenPasswordSignIn_ThenReturnSigninResultFailed() { AuthFlowResponse authFlowResponse = null; bool isPasswordChangeRequired = false; @@ -57,13 +57,13 @@ public async void Test_GivenAUserWithWrongPassword_WhenPasswordSignIn_ThenReturn userManagerMock.Setup(mock => mock.FindByIdAsync(It.IsAny())).Returns(Task.FromResult(GetCognitoUser())).Verifiable(); userManagerMock.Setup(mock => mock.CheckPasswordAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(authFlowResponse)).Verifiable(); userManagerMock.Setup(mock => mock.IsPasswordChangeRequiredAsync(It.IsAny())).Returns(Task.FromResult(isPasswordChangeRequired)).Verifiable(); - var output = await signinManager.PasswordSignInAsync("userId", "password", true, false).ConfigureAwait(false); + var output = await signinManager.PasswordSignInAsync("userId", "password", true, false); Assert.Equal(signinResult, output); userManagerMock.Verify(); } [Fact] - public async void Test_GivenAUserWithNo2FA_WhenPasswordSignIn_ThenReturnSigninResultSuccess() + public async Task Test_GivenAUserWithNo2FA_WhenPasswordSignIn_ThenReturnSigninResultSuccess() { var cognitoUser = GetCognitoUser(); var authFlowResponse = new AuthFlowResponse("sessionId", null, null, null, null); @@ -81,7 +81,7 @@ public async void Test_GivenAUserWithNo2FA_WhenPasswordSignIn_ThenReturnSigninRe var context = MockUtils.MockContext(cognitoUser, IdentityConstants.TwoFactorUserIdScheme); contextAccessorMock.Setup(a => a.HttpContext).Returns(context).Verifiable(); - var output = await signinManager.PasswordSignInAsync("userId", "password", true, false).ConfigureAwait(false); + var output = await signinManager.PasswordSignInAsync("userId", "password", true, false); Assert.Equal(signinResult, output); userManagerMock.Verify(); @@ -89,7 +89,7 @@ public async void Test_GivenAUserWithNo2FA_WhenPasswordSignIn_ThenReturnSigninRe } [Fact] - public async void Test_GivenAUserWithPasswordChangeRequired_WhenPasswordSignIn_ThenReturnSigninResultPassowrdChangeRequired() + public async Task Test_GivenAUserWithPasswordChangeRequired_WhenPasswordSignIn_ThenReturnSigninResultPassowrdChangeRequired() { bool isPasswordChangeRequired = true; var signinResult = CognitoSignInResult.PasswordChangeRequired; @@ -97,13 +97,13 @@ public async void Test_GivenAUserWithPasswordChangeRequired_WhenPasswordSignIn_T userManagerMock.Setup(mock => mock.FindByIdAsync(It.IsAny())).Returns(Task.FromResult(GetCognitoUser())).Verifiable(); userManagerMock.Setup(mock => mock.IsPasswordChangeRequiredAsync(It.IsAny())).Returns(Task.FromResult(isPasswordChangeRequired)).Verifiable(); - var output = await signinManager.PasswordSignInAsync("userId", "password", true, false).ConfigureAwait(false); + var output = await signinManager.PasswordSignInAsync("userId", "password", true, false); Assert.Equal(signinResult, output); userManagerMock.Verify(); } [Fact] - public async void Test_GivenAUserWithPasswordResetRequired_WhenPasswordSignIn_ThenReturnSigninResultPassowrdResetRequired() + public async Task Test_GivenAUserWithPasswordResetRequired_WhenPasswordSignIn_ThenReturnSigninResultPassowrdResetRequired() { bool isPasswordResetRequired = true; var signinResult = CognitoSignInResult.PasswordResetRequired; @@ -111,13 +111,13 @@ public async void Test_GivenAUserWithPasswordResetRequired_WhenPasswordSignIn_Th userManagerMock.Setup(mock => mock.FindByIdAsync(It.IsAny())).Returns(Task.FromResult(GetCognitoUser())).Verifiable(); userManagerMock.Setup(mock => mock.IsPasswordResetRequiredAsync(It.IsAny())).Returns(Task.FromResult(isPasswordResetRequired)).Verifiable(); - var output = await signinManager.PasswordSignInAsync("userId", "password", true, false).ConfigureAwait(false); + var output = await signinManager.PasswordSignInAsync("userId", "password", true, false); Assert.Equal(signinResult, output); userManagerMock.Verify(); } [Fact] - public async void Test_GivenAUserWith2FA_WhenPasswordSignIn_ThenReturnSigninResultTwoFactorRequired() + public async Task Test_GivenAUserWith2FA_WhenPasswordSignIn_ThenReturnSigninResultTwoFactorRequired() { var cognitoUser = GetCognitoUser(); bool isPasswordChangeRequired = false; @@ -131,14 +131,14 @@ public async void Test_GivenAUserWith2FA_WhenPasswordSignIn_ThenReturnSigninResu var context = MockUtils.MockContext(cognitoUser, IdentityConstants.TwoFactorUserIdScheme); contextAccessorMock.Setup(a => a.HttpContext).Returns(context).Verifiable(); - var output = await signinManager.PasswordSignInAsync("userId", "password", true, false).ConfigureAwait(false); + var output = await signinManager.PasswordSignInAsync("userId", "password", true, false); Assert.Equal(signinResult, output); contextAccessorMock.Verify(); } [Fact] - public async void Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithCorrectCode_ThenReturnSigninResultSuccess() + public async Task Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithCorrectCode_ThenReturnSigninResultSuccess() { var cognitoUser = GetCognitoUser(); var context = MockUtils.MockContext(cognitoUser, IdentityConstants.TwoFactorUserIdScheme); @@ -153,7 +153,7 @@ public async void Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithCorr userManagerMock.Setup(mock => mock.GetClaimsAsync(It.IsAny())).Returns(Task.FromResult(new List() as IList)).Verifiable(); userManagerMock.Setup(mock => mock.GetRolesAsync(It.IsAny())).Returns(Task.FromResult(new List() as IList)).Verifiable(); - var output = await signinManager.RespondToTwoFactorChallengeAsync("2FACODE", true, false).ConfigureAwait(false); + var output = await signinManager.RespondToTwoFactorChallengeAsync("2FACODE", true, false); Assert.Equal(SignInResult.Success, output); contextAccessorMock.Verify(); @@ -161,7 +161,7 @@ public async void Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithCorr } [Fact] - public async void Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithWrongCode_ThenReturnSigninResultFailed() + public async Task Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithWrongCode_ThenReturnSigninResultFailed() { var cognitoUser = GetCognitoUser(); var context = MockUtils.MockContext(cognitoUser, IdentityConstants.TwoFactorUserIdScheme); @@ -173,7 +173,7 @@ public async void Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithWron userManagerMock.Setup(mock => mock.RespondToTwoFactorChallengeAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(Task.FromResult(authFlowResponse)).Verifiable(); - var output = await signinManager.RespondToTwoFactorChallengeAsync("2FACODE", true, false).ConfigureAwait(false); + var output = await signinManager.RespondToTwoFactorChallengeAsync("2FACODE", true, false); Assert.Equal(SignInResult.Failed, output); contextAccessorMock.Verify(); @@ -182,7 +182,7 @@ public async void Test_GivenAUserWith2FA_WhenRespondToTwoFactorChallengeWithWron [Fact] - public async void Test_GivenAUserSignedInWith2FAContext_WhenGetTwoFactorAuthenticationUser_ThenTheUserIsRetrieved() + public async Task Test_GivenAUserSignedInWith2FAContext_WhenGetTwoFactorAuthenticationUser_ThenTheUserIsRetrieved() { var cognitoUser = GetCognitoUser(); @@ -190,7 +190,7 @@ public async void Test_GivenAUserSignedInWith2FAContext_WhenGetTwoFactorAuthenti contextAccessorMock.Setup(a => a.HttpContext).Returns(context).Verifiable(); userManagerMock.Setup(mock => mock.FindByIdAsync(It.IsAny())).Returns(Task.FromResult(cognitoUser)).Verifiable(); - var output = await signinManager.GetTwoFactorAuthenticationUserAsync().ConfigureAwait(false); + var output = await signinManager.GetTwoFactorAuthenticationUserAsync(); Assert.Equal(cognitoUser, output); contextAccessorMock.Verify(); @@ -199,39 +199,39 @@ public async void Test_GivenAUserSignedInWith2FAContext_WhenGetTwoFactorAuthenti #region ExceptionTests [Fact] - public async void Test_GivenUserIdAndLockoutActivated_WhenPasswordSignIn_ThenThrowsNotSupportedException() + public async Task Test_GivenUserIdAndLockoutActivated_WhenPasswordSignIn_ThenThrowsNotSupportedException() { - var ex = await Assert.ThrowsAsync(() => signinManager.PasswordSignInAsync("userId", "password", true, lockoutOnFailure: true)).ConfigureAwait(false); + var ex = await Assert.ThrowsAsync(() => signinManager.PasswordSignInAsync("userId", "password", true, lockoutOnFailure: true)); Assert.Equal("Lockout is not enabled for the CognitoUserManager.", ex.Message); } [Fact] - public async void Test_GivenUserAndLockoutActivated_WhenPasswordSignIn_ThenThrowsNotSupportedException() + public async Task Test_GivenUserAndLockoutActivated_WhenPasswordSignIn_ThenThrowsNotSupportedException() { var cognitoUser = new CognitoUser("userId", "clientId", cognitoPoolMock.Object, cognitoClientMock.Object); - var ex = await Assert.ThrowsAsync(() => signinManager.PasswordSignInAsync(cognitoUser, "password", true, lockoutOnFailure: true)).ConfigureAwait(false); + var ex = await Assert.ThrowsAsync(() => signinManager.PasswordSignInAsync(cognitoUser, "password", true, lockoutOnFailure: true)); Assert.Equal("Lockout is not enabled for the CognitoUserManager.", ex.Message); } [Fact] - public async void Test_GivenUserAndLockoutActivated_WhenCheckPasswordSignIn_ThenThrowsNotSupportedException() + public async Task Test_GivenUserAndLockoutActivated_WhenCheckPasswordSignIn_ThenThrowsNotSupportedException() { var cognitoUser = new CognitoUser("userId", "clientId", cognitoPoolMock.Object, cognitoClientMock.Object); - var ex = await Assert.ThrowsAsync(() => signinManager.CheckPasswordSignInAsync(cognitoUser, "password", lockoutOnFailure: true)).ConfigureAwait(false); + var ex = await Assert.ThrowsAsync(() => signinManager.CheckPasswordSignInAsync(cognitoUser, "password", lockoutOnFailure: true)); Assert.Equal("Lockout is not enabled for the CognitoUserManager.", ex.Message); } [Fact] - public async void Test_GivenNullUser_WhenCheckPasswordSignIn_ThenThrowsArgumentNullException() + public async Task Test_GivenNullUser_WhenCheckPasswordSignIn_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => signinManager.CheckPasswordSignInAsync(null, "password", false)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => signinManager.CheckPasswordSignInAsync(null, "password", false)); } [Fact] - public async void Test_GivenNullUser_WhenPasswordSignIn_ThenThrowsArgumentNullException() + public async Task Test_GivenNullUser_WhenPasswordSignIn_ThenThrowsArgumentNullException() { CognitoUser user = null; - await Assert.ThrowsAsync(() => signinManager.PasswordSignInAsync(user, "password", false, false)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => signinManager.PasswordSignInAsync(user, "password", false, false)); } #endregion } diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserManagerTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserManagerTests.cs index f03be53..5cefb9e 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserManagerTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserManagerTests.cs @@ -46,183 +46,183 @@ public CognitoUserManagerTests() : base() } [Fact] - public async void Test_GivenAUser_WhenCheckPassword_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenCheckPassword_ThenResponseIsNotAltered() { var authFlowResponse = new AuthFlowResponse("sessionId", null, null, null, null); userStoreMock.Setup(mock => mock.StartValidatePasswordAsync(It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(authFlowResponse)).Verifiable(); - var output = await userManager.CheckPasswordAsync(GetCognitoUser(), "password").ConfigureAwait(false); + var output = await userManager.CheckPasswordAsync(GetCognitoUser(), "password"); Assert.Equal(authFlowResponse, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenRespondToTwoFactorChallenge_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenRespondToTwoFactorChallenge_ThenResponseIsNotAltered() { var authFlowResponse = new AuthFlowResponse("sessionId", null, ChallengeNameType.SMS_MFA, null, null); userStoreMock.Setup(mock => mock.RespondToTwoFactorChallengeAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(authFlowResponse)).Verifiable(); - var output = await userManager.RespondToTwoFactorChallengeAsync(GetCognitoUser(), "2FACODE", "SessionId").ConfigureAwait(false); + var output = await userManager.RespondToTwoFactorChallengeAsync(GetCognitoUser(), "2FACODE", "SessionId"); Assert.Equal(authFlowResponse, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenSetTwoFactorEnabled_ThenReturnIdentityResultSuccess() + public async Task Test_GivenAUser_WhenSetTwoFactorEnabled_ThenReturnIdentityResultSuccess() { - var output = await userManager.SetTwoFactorEnabledAsync(GetCognitoUser(), true).ConfigureAwait(false); + var output = await userManager.SetTwoFactorEnabledAsync(GetCognitoUser(), true); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenChangePassword_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenChangePassword_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.ChangePasswordAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.ChangePasswordAsync(GetCognitoUser(), "old", "new").ConfigureAwait(false); + var output = await userManager.ChangePasswordAsync(GetCognitoUser(), "old", "new"); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenIsPasswordChangeRequired_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenIsPasswordChangeRequired_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.IsPasswordChangeRequiredAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)).Verifiable(); - var output = await userManager.IsPasswordChangeRequiredAsync(GetCognitoUser()).ConfigureAwait(false); + var output = await userManager.IsPasswordChangeRequiredAsync(GetCognitoUser()); Assert.True(output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUserAndNewPassword_WhenResetPassword_ThenResponseIsNotAltered() + public async Task Test_GivenAUserAndNewPassword_WhenResetPassword_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.ChangePasswordWithTokenAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.ResetPasswordAsync(GetCognitoUser(), "token", "newPassword").ConfigureAwait(false); + var output = await userManager.ResetPasswordAsync(GetCognitoUser(), "token", "newPassword"); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenSendEmailOrPhoneConfirmationToken_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenSendEmailOrPhoneConfirmationToken_ThenResponseIsNotAltered() { var cognitoUser = GetCognitoUser(); userStoreMock.Setup(mock => mock.GetUserAttributeVerificationCodeAsync(It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.SendEmailConfirmationTokenAsync(cognitoUser).ConfigureAwait(false); + var output = await userManager.SendEmailConfirmationTokenAsync(cognitoUser); Assert.Equal(IdentityResult.Success, output); - output = await userManager.SendPhoneConfirmationTokenAsync(cognitoUser).ConfigureAwait(false); + output = await userManager.SendPhoneConfirmationTokenAsync(cognitoUser); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenCreate_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenCreate_ThenResponseIsNotAltered() { var cognitoUser = GetCognitoUser(); userStoreMock.Setup(mock => mock.CreateAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); userStoreMock.Setup(mock => mock.CreateAsync(It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); passwordValidatorsMock.Setup(mock => mock.ValidateAsync(It.IsAny>(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.CreateAsync(cognitoUser).ConfigureAwait(false); + var output = await userManager.CreateAsync(cognitoUser); Assert.Equal(IdentityResult.Success, output); - output = await userManager.CreateAsync(cognitoUser, "password").ConfigureAwait(false); + output = await userManager.CreateAsync(cognitoUser, "password"); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenResetPassword_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenResetPassword_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.ResetPasswordAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.ResetPasswordAsync(GetCognitoUser()).ConfigureAwait(false); + var output = await userManager.ResetPasswordAsync(GetCognitoUser()); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenConfirmEmailOrPhoneNumber_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenConfirmEmailOrPhoneNumber_ThenResponseIsNotAltered() { var cognitoUser = GetCognitoUser(); userStoreMock.Setup(mock => mock.VerifyUserAttributeAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.ConfirmEmailAsync(cognitoUser, "code").ConfigureAwait(false); + var output = await userManager.ConfirmEmailAsync(cognitoUser, "code"); Assert.Equal(IdentityResult.Success, output); - output = await userManager.ConfirmPhoneNumberAsync(cognitoUser, "code").ConfigureAwait(false); + output = await userManager.ConfirmPhoneNumberAsync(cognitoUser, "code"); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenConfirmSignUp_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenConfirmSignUp_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.ConfirmSignUpAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.ConfirmSignUpAsync(GetCognitoUser(), "code", true).ConfigureAwait(false); + var output = await userManager.ConfirmSignUpAsync(GetCognitoUser(), "code", true); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenAdminConfirmSignUp_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenAdminConfirmSignUp_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.AdminConfirmSignUpAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.AdminConfirmSignUpAsync(GetCognitoUser()).ConfigureAwait(false); + var output = await userManager.AdminConfirmSignUpAsync(GetCognitoUser()); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenResendSignupConfirmationCode_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenResendSignupConfirmationCode_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.ResendSignupConfirmationCodeAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.ResendSignupConfirmationCodeAsync(GetCognitoUser()).ConfigureAwait(false); + var output = await userManager.ResendSignupConfirmationCodeAsync(GetCognitoUser()); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenSetPhoneNumber_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenSetPhoneNumber_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.SetPhoneNumberAsync(It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(0)).Verifiable(); userStoreMock.Setup(mock => mock.UpdateAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.SetPhoneNumberAsync(GetCognitoUser(), "+1234567890").ConfigureAwait(false); + var output = await userManager.SetPhoneNumberAsync(GetCognitoUser(), "+1234567890"); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenSetEmail_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenSetEmail_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.SetEmailAsync(It.IsAny(), It.IsAny(), It.IsAny())).Returns(Task.FromResult(0)).Verifiable(); userStoreMock.Setup(mock => mock.UpdateAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.SetEmailAsync(GetCognitoUser(), "darth.vader@amazon.com").ConfigureAwait(false); + var output = await userManager.SetEmailAsync(GetCognitoUser(), "darth.vader@amazon.com"); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivennUser_WhenUpdateUser_ThenResponseIsNotAltered() + public async Task Test_GivennUser_WhenUpdateUser_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.UpdateAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.UpdateAsync(GetCognitoUser()).ConfigureAwait(false); + var output = await userManager.UpdateAsync(GetCognitoUser()); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenAddClaims_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenAddClaims_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.AddClaimsAsync(It.IsAny(), It.IsAny>(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.AddClaimsAsync(GetCognitoUser(), new List()).ConfigureAwait(false); + var output = await userManager.AddClaimsAsync(GetCognitoUser(), new List()); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenRemoveClaims_ThenResponseIsNotAltered() + public async Task Test_GivenAUser_WhenRemoveClaims_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.RemoveClaimsAsync(It.IsAny(), It.IsAny>(), It.IsAny())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); - var output = await userManager.RemoveClaimsAsync(GetCognitoUser(), new List()).ConfigureAwait(false); + var output = await userManager.RemoveClaimsAsync(GetCognitoUser(), new List()); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); } [Fact] - public async void Test_GivenAListOfUsers_WhenGetUsers_ThenResponseIsNotAltered() + public async Task Test_GivenAListOfUsers_WhenGetUsers_ThenResponseIsNotAltered() { var user1 = new CognitoUser("userId1", "clientId", cognitoPoolMock.Object, cognitoClientMock.Object); var user2 = new CognitoUser("userId2", "clientId", cognitoPoolMock.Object, cognitoClientMock.Object); @@ -234,7 +234,7 @@ public async void Test_GivenAListOfUsers_WhenGetUsers_ThenResponseIsNotAltered() user3 }; userStoreMock.Setup(mock => mock.GetUsersAsync(null, null, "", It.IsAny())).Returns(Task.FromResult(users)).Verifiable(); - var output = await userManager.GetUsersAsync().ConfigureAwait(false); + var output = await userManager.GetUsersAsync(); Assert.Equal(users, output); userStoreMock.Verify(); } @@ -242,81 +242,81 @@ public async void Test_GivenAListOfUsers_WhenGetUsers_ThenResponseIsNotAltered() #region ExceptionTests [Fact] - public async void Test_GivenANullUser_WhenCheckPassword_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenCheckPassword_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.CheckPasswordAsync(null, "password")).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.CheckPasswordAsync(null, "password")); } [Fact] - public async void Test_GivenANullUser_WhenRespondToTwoFactorChallenge_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenRespondToTwoFactorChallenge_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.RespondToTwoFactorChallengeAsync(null, "2FACODE", "SessionId")).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.RespondToTwoFactorChallengeAsync(null, "2FACODE", "SessionId")); } [Fact] - public async void Test_GivenANullUser_WhenSetTwoFactorEnabled_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenSetTwoFactorEnabled_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.SetTwoFactorEnabledAsync(null, true)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.SetTwoFactorEnabledAsync(null, true)); } [Fact] - public async void Test_GivenANullUser_WhenChangePassword_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenChangePassword_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.ChangePasswordAsync(null, "old", "new")).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.ChangePasswordAsync(null, "old", "new")); } [Fact] - public async void Test_GivenANullUser_WhenResetPassword_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenResetPassword_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.ResetPasswordAsync(null)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.ResetPasswordAsync(null)); } [Fact] - public async void Test_GivenANullUser_WhenUpdate_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenUpdate_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.UpdateAsync(null)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.UpdateAsync(null)); } [Fact] - public async void Test_GivenANullUser_WhenAddClaims_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenAddClaims_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.AddClaimsAsync(null, new List())).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.AddClaimsAsync(null, new List())); } [Fact] - public async void Test_GivenAUserAndNullListOfClaim_WhenAddClaims_ThenThrowsArgumentNullException() + public async Task Test_GivenAUserAndNullListOfClaim_WhenAddClaims_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.AddClaimsAsync(GetCognitoUser(), null)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.AddClaimsAsync(GetCognitoUser(), null)); } [Fact] - public async void Test_GivenANullUser_WhenRemoveClaims_ThenThrowsArgumentNullException() + public async Task Test_GivenANullUser_WhenRemoveClaims_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.RemoveClaimsAsync(null, new List())).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.RemoveClaimsAsync(null, new List())); } [Fact] - public async void Test_GivenAUserAndNullListOfClaim_WhenRemoveClaims_ThenThrowsArgumentNullException() + public async Task Test_GivenAUserAndNullListOfClaim_WhenRemoveClaims_ThenThrowsArgumentNullException() { - await Assert.ThrowsAsync(() => userManager.RemoveClaimsAsync(GetCognitoUser(), null)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.RemoveClaimsAsync(GetCognitoUser(), null)); } [Fact] - public async void Test_GivenAUser_WhenGenerateEmailConfirmationToken_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenGenerateEmailConfirmationToken_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => userManager.GenerateEmailConfirmationTokenAsync(null)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.GenerateEmailConfirmationTokenAsync(null)); } [Fact] - public async void Test_GivenAUser_WhenGenerateChangePhoneNumberToken_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenGenerateChangePhoneNumberToken_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => userManager.GenerateChangePhoneNumberTokenAsync(null, null)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.GenerateChangePhoneNumberTokenAsync(null, null)); } [Fact] - public async void Test_GivenAUser_WhenChangeEmail_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenChangeEmail_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => userManager.ChangeEmailAsync(null, null, null)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => userManager.ChangeEmailAsync(null, null, null)); } [Fact] diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserClaimStoreTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserClaimStoreTests.cs index 47eab39..ebd9e9a 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserClaimStoreTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserClaimStoreTests.cs @@ -49,10 +49,10 @@ public partial class CognitoUserStoreTests }; [Fact] - public async void Test_GivenAUser_WhenGetClaims_ThenTheListOfClaimsIsRetrieved() + public async Task Test_GivenAUser_WhenGetClaims_ThenTheListOfClaimsIsRetrieved() { _cognitoClientMock.Setup(mock => mock.AdminGetUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(GET_USER_RESPONSE)).Verifiable(); - var output = await _store.GetClaimsAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var output = await _store.GetClaimsAsync(_userMock.Object, CancellationToken.None); Assert.Equal(GET_USER_RESPONSE.UserAttributes.Count, output.Count); Assert.Equal(GET_USER_RESPONSE.UserAttributes[2].Name, output[2].Type); Assert.Equal(GET_USER_RESPONSE.UserAttributes[1].Value, output[1].Value); @@ -60,27 +60,27 @@ public async void Test_GivenAUser_WhenGetClaims_ThenTheListOfClaimsIsRetrieved() } [Fact] - public async void Test_GivenAUser_WhenAddClaimsWithPopulatedListOfClaims_ThenAdminUpdateUserAttributesIsCalled() + public async Task Test_GivenAUser_WhenAddClaimsWithPopulatedListOfClaims_ThenAdminUpdateUserAttributesIsCalled() { var claims = new List() { new Claim("Name1", "Value1") }; _cognitoClientMock.Setup(mock => mock.AdminUpdateUserAttributesAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminUpdateUserAttributesResponse())).Verifiable(); - await _store.AddClaimsAsync(_userMock.Object, claims, CancellationToken.None).ConfigureAwait(false); + await _store.AddClaimsAsync(_userMock.Object, claims, CancellationToken.None); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenAddClaimsWithEmptyListOfClaims_ThenAdminUpdateUserAttributesIsNeverCalled() + public async Task Test_GivenAUser_WhenAddClaimsWithEmptyListOfClaims_ThenAdminUpdateUserAttributesIsNeverCalled() { var claims = new List(); - await _store.AddClaimsAsync(_userMock.Object, claims, CancellationToken.None).ConfigureAwait(false); + await _store.AddClaimsAsync(_userMock.Object, claims, CancellationToken.None); _cognitoClientMock.Verify(mock => mock.AdminUpdateUserAttributesAsync(It.IsAny(), It.IsAny()), Times.Never); } [Fact] - public async void Test_GivenAUser_WhenRemoveClaimsWithAValidClaim_ThenAdminDeleteUserAttributesIsCalled() + public async Task Test_GivenAUser_WhenRemoveClaimsWithAValidClaim_ThenAdminDeleteUserAttributesIsCalled() { var claims = new List() { @@ -88,12 +88,12 @@ public async void Test_GivenAUser_WhenRemoveClaimsWithAValidClaim_ThenAdminDelet }; _cognitoClientMock.Setup(mock => mock.AdminGetUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(GET_USER_RESPONSE)).Verifiable(); _cognitoClientMock.Setup(mock => mock.AdminDeleteUserAttributesAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminDeleteUserAttributesResponse())).Verifiable(); - await _store.RemoveClaimsAsync(_userMock.Object, claims, CancellationToken.None).ConfigureAwait(false); + await _store.RemoveClaimsAsync(_userMock.Object, claims, CancellationToken.None); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenRemoveClaimsWithAnInvalidClaim_ThenAdminDeleteUserAttributesIsNeverCalled() + public async Task Test_GivenAUser_WhenRemoveClaimsWithAnInvalidClaim_ThenAdminDeleteUserAttributesIsNeverCalled() { var claims = new List() { @@ -101,20 +101,20 @@ public async void Test_GivenAUser_WhenRemoveClaimsWithAnInvalidClaim_ThenAdminDe }; _cognitoClientMock.Setup(mock => mock.AdminGetUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(GET_USER_RESPONSE)).Verifiable(); _cognitoClientMock.Setup(mock => mock.AdminDeleteUserAttributesAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminDeleteUserAttributesResponse())).Verifiable(); - await _store.RemoveClaimsAsync(_userMock.Object, claims, CancellationToken.None).ConfigureAwait(false); + await _store.RemoveClaimsAsync(_userMock.Object, claims, CancellationToken.None); _cognitoClientMock.Verify(mock => mock.AdminDeleteUserAttributesAsync(It.IsAny(), It.IsAny()), Times.Never); } [Fact] - public async void Test_GivenAUser_WhenReplaceClaim_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenReplaceClaim_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.ReplaceClaimAsync(null, null, null, CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.ReplaceClaimAsync(null, null, null, CancellationToken.None)); } [Fact] - public async void Test_GivenAClaim_WhenGetUsersForClaim_ThenThrowsANotSupportedException() + public async Task Test_GivenAClaim_WhenGetUsersForClaim_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.GetUsersForClaimAsync(new Claim("test", "test"), CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.GetUsersForClaimAsync(new Claim("test", "test"), CancellationToken.None)); } } diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserCognitoStoreTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserCognitoStoreTests.cs index ccf07d2..ad5fc5c 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserCognitoStoreTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserCognitoStoreTests.cs @@ -46,70 +46,70 @@ public CognitoUserStoreTests() [Theory] [InlineData("FORCE_CHANGE_PASSWORD", true)] [InlineData("CONFIRMED", false)] - public async void Test_GivenAUserWithStatus_WhenIsPasswordChangeRequired_ThenResponseIsValid(string status, bool isPasswordChangeRequired) + public async Task Test_GivenAUserWithStatus_WhenIsPasswordChangeRequired_ThenResponseIsValid(string status, bool isPasswordChangeRequired) { var user = new CognitoUser("userID", "clientID", _cognitoPoolMock.Object, _cognitoClientMock.Object, null, status, null, null); - var output = await _store.IsPasswordChangeRequiredAsync(user, CancellationToken.None).ConfigureAwait(false); + var output = await _store.IsPasswordChangeRequiredAsync(user, CancellationToken.None); Assert.Equal(isPasswordChangeRequired, output); } [Theory] [InlineData("RESET_REQUIRED", true)] [InlineData("CONFIRMED", false)] - public async void Test_GivenAUserWithStatus_WhenIsPasswordResetRequired_ThenResponseIsValid(string status, bool isPasswordResetRequired) + public async Task Test_GivenAUserWithStatus_WhenIsPasswordResetRequired_ThenResponseIsValid(string status, bool isPasswordResetRequired) { var user = new CognitoUser("userID", "clientID", _cognitoPoolMock.Object, _cognitoClientMock.Object, null, status, null, null); - var output = await _store.IsPasswordResetRequiredAsync(user, CancellationToken.None).ConfigureAwait(false); + var output = await _store.IsPasswordResetRequiredAsync(user, CancellationToken.None); Assert.Equal(isPasswordResetRequired, output); } [Fact] - public async void Test_GivenAUser_WhenResetPassword_ThenTheRequestIsSuccessful() + public async Task Test_GivenAUser_WhenResetPassword_ThenTheRequestIsSuccessful() { _cognitoClientMock.Setup(mock => mock.AdminResetUserPasswordAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminResetUserPasswordResponse())).Verifiable(); - var output = await _store.ResetPasswordAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var output = await _store.ResetPasswordAsync(_userMock.Object, CancellationToken.None); Assert.Equal(IdentityResult.Success, output); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenCreate_ThenTheUserGetsAddedToThePool() + public async Task Test_GivenAUser_WhenCreate_ThenTheUserGetsAddedToThePool() { - var output = await _store.CreateAsync(_userMock.Object, "password", null, CancellationToken.None).ConfigureAwait(false); + var output = await _store.CreateAsync(_userMock.Object, "password", null, CancellationToken.None); Assert.Equal(IdentityResult.Success, output); } [Fact] - public async void Test_GivenAUser_WhenAdminConfirmSignUp_ThenTheRequestIsSuccessful() + public async Task Test_GivenAUser_WhenAdminConfirmSignUp_ThenTheRequestIsSuccessful() { _cognitoClientMock.Setup(mock => mock.AdminConfirmSignUpAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminConfirmSignUpResponse())).Verifiable(); - var output = await _store.AdminConfirmSignUpAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var output = await _store.AdminConfirmSignUpAsync(_userMock.Object, CancellationToken.None); Assert.Equal(IdentityResult.Success, output); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenGetUserAttributeVerificationCodeOtherThanEmailOrPhone_ThenThrowsArgumentException() + public async Task Test_GivenAUser_WhenGetUserAttributeVerificationCodeOtherThanEmailOrPhone_ThenThrowsArgumentException() { - await Assert.ThrowsAsync(() => _store.GetUserAttributeVerificationCodeAsync(_userMock.Object, "UNKNOWN_ATTRIBUTE", CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.GetUserAttributeVerificationCodeAsync(_userMock.Object, "UNKNOWN_ATTRIBUTE", CancellationToken.None)); } [Fact] - public async void Test_GivenAUser_WhenGetUserAttributeVerificationCode_ThenTheRequestIsSuccessfun() + public async Task Test_GivenAUser_WhenGetUserAttributeVerificationCode_ThenTheRequestIsSuccessfun() { _cognitoClientMock.Setup(mock => mock.GetUserAttributeVerificationCodeAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new GetUserAttributeVerificationCodeResponse())).Verifiable(); _userMock.Object.SessionTokens = new CognitoUserSession(null, null, null, DateTime.Now, DateTime.MaxValue); - var output = await _store.GetUserAttributeVerificationCodeAsync(_userMock.Object, CognitoAttribute.PhoneNumber.AttributeName, CancellationToken.None).ConfigureAwait(false); + var output = await _store.GetUserAttributeVerificationCodeAsync(_userMock.Object, CognitoAttribute.PhoneNumber.AttributeName, CancellationToken.None); Assert.Equal(IdentityResult.Success, output); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenVerifyUserAttribute_ThenTheRequestIsSuccessfun() + public async Task Test_GivenAUser_WhenVerifyUserAttribute_ThenTheRequestIsSuccessfun() { _cognitoClientMock.Setup(mock => mock.VerifyUserAttributeAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new VerifyUserAttributeResponse())).Verifiable(); _userMock.Object.SessionTokens = new CognitoUserSession(null, null, null, DateTime.Now, DateTime.MaxValue); - var output = await _store.VerifyUserAttributeAsync(_userMock.Object, CognitoAttribute.PhoneNumber.AttributeName, "code", CancellationToken.None).ConfigureAwait(false); + var output = await _store.VerifyUserAttributeAsync(_userMock.Object, CognitoAttribute.PhoneNumber.AttributeName, "code", CancellationToken.None); Assert.Equal(IdentityResult.Success, output); _cognitoClientMock.Verify(); } diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserEmailStoreTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserEmailStoreTests.cs index cecd705..89f0590 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserEmailStoreTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserEmailStoreTests.cs @@ -26,7 +26,7 @@ namespace Amazon.AspNetCore.Identity.Cognito.Tests public partial class CognitoUserStoreTests { [Fact] - public async void Test_GivenAnEmail_WhenFindByEmail_ThenTheUserIsRetrieved() + public async Task Test_GivenAnEmail_WhenFindByEmail_ThenTheUserIsRetrieved() { var username = "UserName"; var status = "CONFIRMED"; @@ -43,28 +43,28 @@ public async void Test_GivenAnEmail_WhenFindByEmail_ThenTheUserIsRetrieved() } }; _cognitoClientMock.Setup(mock => mock.ListUsersAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(response)).Verifiable(); - var user = await _store.FindByEmailAsync("user@domain.tld", CancellationToken.None).ConfigureAwait(false); + var user = await _store.FindByEmailAsync("user@domain.tld", CancellationToken.None); Assert.Equal(username, user.Username); Assert.Equal(status, user.Status); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenGetNormalizedEmail_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenGetNormalizedEmail_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.GetNormalizedEmailAsync(_userMock.Object, CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.GetNormalizedEmailAsync(_userMock.Object, CancellationToken.None)); } [Fact] - public async void Test_GivenAUser_WhenSetEmailConfirmed_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenSetEmailConfirmed_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.SetEmailConfirmedAsync(_userMock.Object, true, CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.SetEmailConfirmedAsync(_userMock.Object, true, CancellationToken.None)); } [Fact] - public async void Test_GivenAUser_WhenSetNormalizedEmail_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenSetNormalizedEmail_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.SetNormalizedEmailAsync(_userMock.Object, "email", CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.SetNormalizedEmailAsync(_userMock.Object, "email", CancellationToken.None)); } } } diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserPhoneNumberStoreTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserPhoneNumberStoreTests.cs index 8bf34dd..2c99727 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserPhoneNumberStoreTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserPhoneNumberStoreTests.cs @@ -15,6 +15,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Xunit; namespace Amazon.AspNetCore.Identity.Cognito.Tests @@ -22,9 +23,9 @@ namespace Amazon.AspNetCore.Identity.Cognito.Tests public partial class CognitoUserStoreTests { [Fact] - public async void Test_GivenAUser_WhenSetPhoneNumberConfirmed_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenSetPhoneNumberConfirmed_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.SetPhoneNumberConfirmedAsync(_userMock.Object, true, CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.SetPhoneNumberConfirmedAsync(_userMock.Object, true, CancellationToken.None)); } } diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserRoleStoreTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserRoleStoreTests.cs index 291d7cd..47fff8a 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserRoleStoreTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserRoleStoreTests.cs @@ -36,48 +36,48 @@ public partial class CognitoUserStoreTests }; [Fact] - public async void Test_GivenAUser_WhenGetUserId_ThenTheUserIdIsRetrieved() + public async Task Test_GivenAUser_WhenGetUserId_ThenTheUserIdIsRetrieved() { - var userId = await _store.GetUserIdAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var userId = await _store.GetUserIdAsync(_userMock.Object, CancellationToken.None); Assert.Equal(_userMock.Object.UserID, userId); } [Fact] - public async void Test_GivenAUser_WhenGetUserName_ThenTheUserNameIsRetrieved() + public async Task Test_GivenAUser_WhenGetUserName_ThenTheUserNameIsRetrieved() { - var userName = await _store.GetUserNameAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var userName = await _store.GetUserNameAsync(_userMock.Object, CancellationToken.None); Assert.Equal(_userMock.Object.Username, userName); } [Fact] - public async void Test_GivenAUser_WhenDelete_ThenAdminDeleteUserAsyncIsCalled() + public async Task Test_GivenAUser_WhenDelete_ThenAdminDeleteUserAsyncIsCalled() { _cognitoClientMock.Setup(mock => mock.AdminDeleteUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminDeleteUserResponse())).Verifiable(); - await _store.DeleteAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + await _store.DeleteAsync(_userMock.Object, CancellationToken.None); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenAddToRole_ThenAdminAddUserToGroupAsyncIsCalled() + public async Task Test_GivenAUser_WhenAddToRole_ThenAdminAddUserToGroupAsyncIsCalled() { _cognitoClientMock.Setup(mock => mock.AdminAddUserToGroupAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminAddUserToGroupResponse())).Verifiable(); - await _store.AddToRoleAsync(_userMock.Object, "roleName", CancellationToken.None).ConfigureAwait(false); + await _store.AddToRoleAsync(_userMock.Object, "roleName", CancellationToken.None); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenRemoveFromRole_ThenAdminRemoveUserFromGroupAsyncIsCalled() + public async Task Test_GivenAUser_WhenRemoveFromRole_ThenAdminRemoveUserFromGroupAsyncIsCalled() { _cognitoClientMock.Setup(mock => mock.AdminRemoveUserFromGroupAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminRemoveUserFromGroupResponse())).Verifiable(); - await _store.RemoveFromRoleAsync(_userMock.Object, "roleName", CancellationToken.None).ConfigureAwait(false); + await _store.RemoveFromRoleAsync(_userMock.Object, "roleName", CancellationToken.None); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenGetRoles_ThenTheUserRolesAreRetrieved() + public async Task Test_GivenAUser_WhenGetRoles_ThenTheUserRolesAreRetrieved() { _cognitoClientMock.Setup(mock => mock.AdminListGroupsForUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(LIST_GROUPS_FOR_USERS_RESPONSE)).Verifiable(); - var output = await _store.GetRolesAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var output = await _store.GetRolesAsync(_userMock.Object, CancellationToken.None); Assert.Equal(LIST_GROUPS_FOR_USERS_RESPONSE.Groups.Count, output.Count); Assert.Equal(LIST_GROUPS_FOR_USERS_RESPONSE.Groups[0].GroupName, output[0]); Assert.Equal(LIST_GROUPS_FOR_USERS_RESPONSE.Groups[1].GroupName, output[1]); @@ -88,30 +88,30 @@ public async void Test_GivenAUser_WhenGetRoles_ThenTheUserRolesAreRetrieved() [Theory] [InlineData("group1", true)] [InlineData("unknownGroup", false)] - public async void Test_GivenAUserAndARoleName_WhenIsInRole_ThenTheResponseIsValid(string roleName, bool isInRole) + public async Task Test_GivenAUserAndARoleName_WhenIsInRole_ThenTheResponseIsValid(string roleName, bool isInRole) { _cognitoClientMock.Setup(mock => mock.AdminListGroupsForUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(LIST_GROUPS_FOR_USERS_RESPONSE)).Verifiable(); - var output = await _store.IsInRoleAsync(_userMock.Object, roleName, CancellationToken.None).ConfigureAwait(false); + var output = await _store.IsInRoleAsync(_userMock.Object, roleName, CancellationToken.None); Assert.Equal(isInRole, output); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenGetNormalizedUserName_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenGetNormalizedUserName_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.GetNormalizedUserNameAsync(_userMock.Object, CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.GetNormalizedUserNameAsync(_userMock.Object, CancellationToken.None)); } [Fact] - public async void Test_GivenAUser_WhenSetNormalizedUserName_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenSetNormalizedUserName_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.SetNormalizedUserNameAsync(_userMock.Object, "userName", CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.SetNormalizedUserNameAsync(_userMock.Object, "userName", CancellationToken.None)); } [Fact] - public async void Test_GivenAUser_WhenSetSetUserName_ThenThrowsANotSupportedException() + public async Task Test_GivenAUser_WhenSetSetUserName_ThenThrowsANotSupportedException() { - await Assert.ThrowsAsync(() => _store.SetUserNameAsync(_userMock.Object, "userName", CancellationToken.None)).ConfigureAwait(false); + await Assert.ThrowsAsync(() => _store.SetUserNameAsync(_userMock.Object, "userName", CancellationToken.None)); } } } diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserTwoFactorStoreTests.cs b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserTwoFactorStoreTests.cs index 2888419..dd3fd32 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserTwoFactorStoreTests.cs +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/CognitoUserStore.IUserTwoFactorStoreTests.cs @@ -25,7 +25,7 @@ namespace Amazon.AspNetCore.Identity.Cognito.Tests public partial class CognitoUserStoreTests { [Fact] - public async void Test_GivenAUser_WhenGetTwoFactorEnabledWithAnMFAOption_ThenTheResponseIsTrue() + public async Task Test_GivenAUser_WhenGetTwoFactorEnabledWithAnMFAOption_ThenTheResponseIsTrue() { var response = new AdminGetUserResponse() { @@ -35,29 +35,29 @@ public async void Test_GivenAUser_WhenGetTwoFactorEnabledWithAnMFAOption_ThenThe } }; _cognitoClientMock.Setup(mock => mock.AdminGetUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(response)).Verifiable(); - var output = await _store.GetTwoFactorEnabledAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var output = await _store.GetTwoFactorEnabledAsync(_userMock.Object, CancellationToken.None); Assert.True(output); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenGetTwoFactorEnabledWithoutAnMFAOption_ThenTheResponseIsFalse() + public async Task Test_GivenAUser_WhenGetTwoFactorEnabledWithoutAnMFAOption_ThenTheResponseIsFalse() { var response = new AdminGetUserResponse() { MFAOptions = new List() }; _cognitoClientMock.Setup(mock => mock.AdminGetUserAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(response)).Verifiable(); - var output = await _store.GetTwoFactorEnabledAsync(_userMock.Object, CancellationToken.None).ConfigureAwait(false); + var output = await _store.GetTwoFactorEnabledAsync(_userMock.Object, CancellationToken.None); Assert.False(output); _cognitoClientMock.Verify(); } [Fact] - public async void Test_GivenAUser_WhenSetTwoFactorEnabled_ThenAdminSetUserSettingsAsyncIsCalled() + public async Task Test_GivenAUser_WhenSetTwoFactorEnabled_ThenAdminSetUserSettingsAsyncIsCalled() { _cognitoClientMock.Setup(mock => mock.AdminSetUserSettingsAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(new AdminSetUserSettingsResponse())).Verifiable(); - await _store.SetTwoFactorEnabledAsync(_userMock.Object, false, CancellationToken.None).ConfigureAwait(false); + await _store.SetTwoFactorEnabledAsync(_userMock.Object, false, CancellationToken.None); _cognitoClientMock.Verify(); } }