refactoring, improvements, fixes...

This commit is contained in:
jozsef.b@aycode.com 2024-05-03 15:37:41 +02:00
parent fa4b55f7e8
commit c1b0fcd0d7
9 changed files with 86 additions and 14 deletions

View File

@ -2,6 +2,7 @@
using System.Security;
using System.Text;
using AyCode.Core.Extensions;
using AyCode.Utils.Extensions;
namespace AyCode.Core.Consts
{
@ -81,8 +82,8 @@ namespace AyCode.Core.Consts
private static string _tiamProjectIdString = "684f34d1-163a-4077-918f-a9d9df5ce789";
static AcConst()
{
ProjectId = Guid.Parse(_tiamProjectIdString);
ProjectSalt = GenerateProjectSalt(ProjectId.ToString("N"));
ProjectId = Guid.Parse(_tiamProjectIdString.ToLower());
ProjectSalt = GenerateProjectSalt(ProjectId.ToString("N").ToLower());
//var anataFolder = AcDomain.IsProductVersion ? "Anata" : "AnataDev";

View File

@ -2,6 +2,7 @@
using System.Text;
using AyCode.Core.Consts;
using AyCode.Core.Extensions;
using AyCode.Utils.Extensions;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
namespace AyCode.Core.Helpers

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />

View File

@ -7,7 +7,7 @@ using AyCode.Interfaces.Server.Logins;
namespace AyCode.Models.Server.Logins;
public class AcLoggedInModelServer<TResultLoggedInModel, TUser, TUserToken, TProfile, TServiceProvider, TUserToServiceProvider, TProfileAddress> : IAcLoggedInModelBase<TUser, TUserToken, TProfile, TServiceProvider, TUserToServiceProvider, TProfileAddress>
public class AcLoggedInModelServer<TUser, TUserToken, TProfile, TServiceProvider, TUserToServiceProvider, TProfileAddress> : IAcLoggedInModelBase<TUser, TUserToken, TProfile, TServiceProvider, TUserToServiceProvider, TProfileAddress>
where TUser : class, IAcUser<TProfile, TServiceProvider, TUserToServiceProvider, TProfileAddress>
where TUserToken : class, IAcUserTokenBase

View File

@ -14,6 +14,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
@ -23,6 +24,7 @@
<ItemGroup>
<ProjectReference Include="..\AyCode.Core.Server\AyCode.Core.Server.csproj" />
<ProjectReference Include="..\AyCode.Core.Tests\AyCode.Core.Tests.csproj" />
<ProjectReference Include="..\AyCode.Core\AyCode.Core.csproj" />
<ProjectReference Include="..\AyCode.Database.Tests\AyCode.Database.Tests.csproj" />
<ProjectReference Include="..\AyCode.Database\AyCode.Database.csproj" />
@ -32,6 +34,7 @@
<ProjectReference Include="..\AyCode.Interfaces\AyCode.Interfaces.csproj" />
<ProjectReference Include="..\AyCode.Models.Server\AyCode.Models.Server.csproj" />
<ProjectReference Include="..\AyCode.Models\AyCode.Models.csproj" />
<ProjectReference Include="..\AyCode.Services.Server\AyCode.Services.Server.csproj" />
<ProjectReference Include="..\AyCode.Services\AyCode.Services.csproj" />
<ProjectReference Include="..\AyCode.Utils.Server\AyCode.Utils.Server.csproj" />
<ProjectReference Include="..\AyCode.Utils\AyCode.Utils.csproj" />

View File

@ -8,6 +8,10 @@ using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Server.Logins;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using AyCode.Core.Consts;
using AyCode.Core.Extensions;
using AyCode.Services.Server.Logins;
using AyCode.Utils.Extensions;
namespace AyCode.Services.Server.Tests.LoginServices
{
@ -24,10 +28,69 @@ namespace AyCode.Services.Server.Tests.LoginServices
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
where TEmailMessage : class, IAcEmailMessageBase
{
public TUser RegisterUserTest()
[DataTestMethod]
[DataRow(["", "", ""])]
public virtual async Task AcBase_RegisterUser_ReturnsUser_WhenUserExist(string[] userIdEmailPasswordStrings)
{
//Activator.CreateInstance(typeof(TLoginServiceServer), )
throw new NotImplementedException();
var registerUserId = Guid.Parse(userIdEmailPasswordStrings[0]);
var registerEmail = userIdEmailPasswordStrings[1];
var registerPassword = userIdEmailPasswordStrings[2];
await Dal.RemoveUserAsync(registerUserId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
var loginService = Activator.CreateInstance(typeof(TLoginServiceServer), Dal, AcEnv.AppConfiguration) as TLoginServiceServer;
Assert.IsNotNull(loginService);
var errorCode = await loginService.RegistrationAsync(registerUserId, registerEmail, registerPassword, null);
Assert.IsTrue(errorCode == AcErrorCode.Unset);
var user = Dal.GetUserByEmail(registerEmail, false);
Assert.IsNotNull(user);
Assert.IsNotNull(user.Profile);
Assert.IsNotNull(user.Profile.Address);
await Dal.RemoveUserAsync(user); //kitöröljük a szemetet - J.
}
[DataTestMethod]
[DataRow(["", ""])]
public virtual void AcBase_LoginUser_ReturnsUser_WhenUserExist(string[] emailPasswordStrings)
{
var loginEmail = emailPasswordStrings[0];
var loginPassword = emailPasswordStrings[1];
var loginService = Activator.CreateInstance(typeof(TLoginServiceServer), Dal, AcEnv.AppConfiguration) as TLoginServiceServer;
Assert.IsNotNull(loginService);
#region Valid email+password test
var loggedInModel = loginService.Login(loginEmail, loginPassword);
Assert.IsNotNull(loggedInModel);
Assert.IsNotNull(loggedInModel.LoggedInUser);
Assert.IsNotNull(loginService.LoggedInModel?.LoggedInUser);
Assert.IsTrue(loggedInModel.LoginErrorCode == AcErrorCode.Unset, $"errorCode: {loggedInModel.LoginErrorCode}");
Assert.IsTrue(loggedInModel.IsLoggedIn, $"loggedInModel.IsLoggedIn == false; errorCode: {loggedInModel.LoginErrorCode}");
Assert.IsTrue(string.Equals(loggedInModel.LoggedInUser.EmailAddress, loginEmail, StringComparison.CurrentCultureIgnoreCase));
#endregion Valid email+password test
#region Wrong email test
loggedInModel = loginService.Login("gffsdgdfg@gu.hu", loginPassword);
Assert.IsNotNull(loggedInModel);
Assert.IsFalse(loggedInModel.IsLoggedIn);
Assert.IsTrue(loggedInModel.LoginErrorCode == AcErrorCode.WrongLoginData);
#endregion Wrong email test
#region Wrong password test
loggedInModel = loginService.Login(loginEmail, "fsdgfsdg");
Assert.IsNotNull(loggedInModel);
Assert.IsFalse(loggedInModel.IsLoggedIn);
Assert.IsTrue(loggedInModel.LoginErrorCode == AcErrorCode.WrongLoginData);
#endregion Wrong password test
}
}
}

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="SendGrid" Version="9.29.3" />
</ItemGroup>

View File

@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System.Diagnostics.CodeAnalysis;
namespace AyCode.Utils.Extensions
{
@ -6,10 +7,10 @@ namespace AyCode.Utils.Extensions
{
//[ContractAnnotation("=> true, result: notnull; => false, result: null")]
//[ContractAnnotation("true => null; false => notnull")]
public static bool IsNullOrEmpty(this Guid guid) => guid == Guid.Empty;
public static bool IsNullOrEmpty([NotNullWhen(false)] this Guid guid) => guid == Guid.Empty;
//[ContractAnnotation("=> true, result: notnull; => false, result: null")]
[ContractAnnotation("guid:null => true; guid:notnull <= false")]
public static bool IsNullOrEmpty(this Guid? guid) => guid == null || guid == Guid.Empty;
//[ContractAnnotation("guid:null => true; guid:notnull <= false")]
public static bool IsNullOrEmpty([NotNullWhen(false)] this Guid? guid) => guid == null || guid == Guid.Empty;
}
}

View File

@ -2,16 +2,17 @@
using System.Text;
using JetBrains.Annotations;
namespace AyCode.Core.Extensions
namespace AyCode.Utils.Extensions
{
public static class StringExtensions
{
//[ContractAnnotation("str:null => true; str:notnull <= false")]
[ContractAnnotation("str:null => true; str:notnull <= false")]
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)] this string str) => str == null || str.Length == 0;
//[return: NotNullIfNotNull(nameof(str))]
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? str) => str == null || str.Length == 0;
[ContractAnnotation("str:null => true;")]
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)] this string str)
//[ContractAnnotation("str:null => true;; str:notnull <= false")]
//[return: NotNullIfNotNull(nameof(str))]
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? str)
{
if (str == null || str.Length == 0) return true;
if (!char.IsWhiteSpace(str[0])) return false;