-
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.
Upgrade Wilcommerce.Auth package 1.0.0-rc4
- Loading branch information
Showing
10 changed files
with
91 additions
and
245 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,22 +2,21 @@ | |
using Microsoft.EntityFrameworkCore; | ||
using Moq; | ||
using System; | ||
using System.Linq; | ||
using Wilcommerce.Auth.Models; | ||
using Wilcommerce.Auth.Services; | ||
using Wilcommerce.Core.Common.Domain.Models; | ||
|
||
namespace Wilcommerce.Auth.Data.EFCore.Test.Fixtures | ||
{ | ||
public class AuthContextFixture : IDisposable | ||
{ | ||
public AuthContext Context { get; protected set; } | ||
|
||
public User TestAdmin { get; protected set; } | ||
|
||
public string Token { get; protected set; } | ||
public IPasswordHasher<User> PasswordHasher { get; protected set; } | ||
|
||
public AuthContextFixture() | ||
{ | ||
PasswordHasher = new Mock<IPasswordHasher<User>>().Object; | ||
|
||
BuildContext(); | ||
PrepareData(); | ||
} | ||
|
@@ -35,20 +34,20 @@ public void Dispose() | |
|
||
protected virtual void CleanData() | ||
{ | ||
Context.UserTokens.RemoveRange(Context.UserTokens); | ||
if (Context.Users.Any()) | ||
{ | ||
Context.RemoveRange(Context.Users); | ||
} | ||
|
||
Context.SaveChanges(); | ||
} | ||
|
||
protected virtual void PrepareData() | ||
{ | ||
var passwordHasher = new Mock<IPasswordHasher<User>>().Object; | ||
|
||
TestAdmin = User.CreateAsAdministrator("Admin", "[email protected]", "password", passwordHasher); | ||
var tokenGenerator = new TokenGenerator(); | ||
Token = tokenGenerator.GenerateForUser(TestAdmin); | ||
|
||
var userToken = UserToken.PasswordRecovery(TestAdmin, Token, DateTime.Now.AddDays(10)); | ||
var user = User.CreateAsAdministrator("Administrator", "[email protected]", true); | ||
user.PasswordHash = PasswordHasher.HashPassword(user, "password"); | ||
|
||
Context.UserTokens.Add(userToken); | ||
Context.Add(user); | ||
Context.SaveChanges(); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
using Wilcommerce.Auth.Data.EFCore.ReadModels; | ||
using Wilcommerce.Auth.Data.EFCore.Test.Fixtures; | ||
using Wilcommerce.Auth.Models; | ||
using Wilcommerce.Auth.ReadModels; | ||
using Xunit; | ||
|
||
namespace Wilcommerce.Auth.Data.EFCore.Test.ReadModels | ||
|
@@ -19,24 +20,32 @@ public AuthDatabaseTest(AuthContextFixture fixture) | |
} | ||
|
||
[Fact] | ||
public void AuthDatabase_Should_Contain_A_PasswordRecovery_Token() | ||
public void Users_Should_Contains_An_Administrator_User() | ||
{ | ||
bool existsToken = _database.Tokens.Any(t => t.TokenType == TokenTypes.PasswordRecovery); | ||
Assert.True(existsToken); | ||
bool existAdministrator = _database.Users | ||
.Any(u => u.UserName == "[email protected]" && u.Email == "[email protected]" && u.Name == "Administrator"); | ||
|
||
Assert.True(existAdministrator); | ||
} | ||
|
||
[Fact] | ||
public void AuthDatabase_Should_Contain_A_Token_With_Fixture_Value() | ||
public void Users_WithUsername_Should_Match_Given_Username() | ||
{ | ||
bool existsToken = _database.Tokens.Any(t => t.Token == _fixture.Token); | ||
Assert.True(existsToken); | ||
bool exists = _database.Users | ||
.WithUsername("[email protected]") | ||
.Any(); | ||
|
||
Assert.True(exists); | ||
} | ||
|
||
[Fact] | ||
public void AuthDatabase_Should_Contain_A_Token_With_TestAdmin_Id() | ||
public void Users_Actives_Should_Return_Only_Users_With_IsActive_Equal_To_True() | ||
{ | ||
bool existsToken = _database.Tokens.Any(t => t.UserId == _fixture.TestAdmin.Id); | ||
Assert.True(existsToken); | ||
bool exists = _database.Users | ||
.Actives() | ||
.Any(u => !u.IsActive); | ||
|
||
Assert.False(exists); | ||
} | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
Wilcommerce.Auth.Data.EFCore.Test/Repository/RepositoryTest.cs
This file was deleted.
Oops, something went wrong.
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
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
31 changes: 31 additions & 0 deletions
31
src/Wilcommerce.Auth.Data.EFCore/Mapping/IdentityMapping.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,31 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Wilcommerce.Auth.Models; | ||
|
||
namespace Wilcommerce.Auth.Data.EFCore.Mapping | ||
{ | ||
/// <summary> | ||
/// Defines all the extension methods which maps the identity classes | ||
/// </summary> | ||
public static class IdentityMapping | ||
{ | ||
/// <summary> | ||
/// Maps all the Identity classes | ||
/// </summary> | ||
/// <param name="modelBuilder">The modelBuilder instance</param> | ||
/// <returns>The modelBuilder instance</returns> | ||
public static ModelBuilder MapIdentity(this ModelBuilder modelBuilder) | ||
{ | ||
foreach (var entity in modelBuilder.Model.GetEntityTypes()) | ||
{ | ||
entity | ||
.Relational() | ||
.TableName = $"Wilcommerce_{entity.ClrType.Name}"; | ||
} | ||
|
||
modelBuilder.Entity<User>() | ||
.OwnsOne(u => u.ProfileImage); | ||
|
||
return modelBuilder; | ||
} | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
src/Wilcommerce.Auth.Data.EFCore/Mapping/UserTokenMapping.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.