-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...s/Server.Presentation.Grpc.IntegrationTests/Services/AccountServices/ConfirmEmailTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using MadWorldNL.Server.Infrastructure.Database.Users; | ||
using MadWorldNL.Server.Presentation.Grpc.IntegrationTests.TestBase; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Server.Presentation.Grpc; | ||
using Shouldly; | ||
|
||
namespace MadWorldNL.Server.Presentation.Grpc.IntegrationTests.Services.AccountServices; | ||
|
||
[Collection(Collections.Applcation)] | ||
public class ConfirmEmailTests : IAsyncLifetime | ||
{ | ||
private readonly GrpcFactory _factory; | ||
|
||
public ConfirmEmailTests(GrpcFactory factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
[Fact] | ||
public async Task ConfirmEmail_GivenToken_ReturnsOK() | ||
{ | ||
// Arrange | ||
const string email = "[email protected]"; | ||
|
||
string token; | ||
using (var scope = _factory.CreateScope()) | ||
{ | ||
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUserExtended>>(); | ||
|
||
var user = new IdentityUserExtended() | ||
{ | ||
UserName = email, | ||
Email = email | ||
}; | ||
|
||
await userManager.CreateAsync(user); | ||
token = await userManager.GenerateEmailConfirmationTokenAsync(user); | ||
|
||
} | ||
|
||
var request = new ConfirmEmailRequest() | ||
{ | ||
ConfirmCode = token, | ||
Email = email | ||
}; | ||
|
||
var client = new Account.AccountClient(_factory.Channel); | ||
|
||
// Act | ||
var response = client.ConfirmEmail(request); | ||
|
||
// Assert | ||
response.IsSuccess.ShouldBeTrue(); | ||
response.Message.ShouldBe(string.Empty); | ||
|
||
using var assertScope = _factory.CreateScope(); | ||
var assertUserManager = assertScope.ServiceProvider.GetRequiredService<UserManager<IdentityUserExtended>>(); | ||
var assertUser = await assertUserManager.FindByEmailAsync(email); | ||
assertUser.ShouldNotBeNull(); | ||
assertUser.EmailConfirmed.ShouldBeTrue(); | ||
} | ||
|
||
public Task InitializeAsync() => Task.CompletedTask; | ||
public Task DisposeAsync() | ||
{ | ||
return _factory.ResetDatabase(); | ||
} | ||
} |