refactoring, improvements...
This commit is contained in:
parent
764bc71386
commit
3af9cb10e0
|
|
@ -572,51 +572,5 @@ namespace TIAM.Database.Test
|
|||
}
|
||||
|
||||
#endregion EmailMessage
|
||||
|
||||
#region User
|
||||
[DataTestMethod]
|
||||
[DataRow(["e31044d7-1771-4a32-8dd9-6f9853ed53c6", "0a831191-70a3-4504-9ec4-c5902affaba7", "8eed080c-d2ce-4cc3-bcfe-2268c220bba7", "addUser_test9432@tiam.hu"])]
|
||||
public async Task AddUserTest(string[] userIdProfileIdAddressIdEmailStrings)
|
||||
{
|
||||
var userId = Guid.Parse(userIdProfileIdAddressIdEmailStrings[0]);
|
||||
var profileId = Guid.Parse(userIdProfileIdAddressIdEmailStrings[1]);
|
||||
var addressId = Guid.Parse(userIdProfileIdAddressIdEmailStrings[2]);
|
||||
var email = userIdProfileIdAddressIdEmailStrings[3];
|
||||
|
||||
var fromAddress = "Budapest, Liszt Ferenc tér";
|
||||
var toAddress = "1211 Budapest, Kossuth Lajos utca 145";
|
||||
//var userProductToCarId = Guid.Parse("97179a87-d99f-4f12-b7b2-75e21aaec6ab");
|
||||
|
||||
await Dal.RemoveUserAsync(userId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
||||
|
||||
var user = new User(userId, email, "235664", "dsfglfjg45r34903t3kggvq");
|
||||
//user.ProfileId = profileId;
|
||||
|
||||
var profile = new Profile();
|
||||
profile.Id = profileId;;
|
||||
profile.Name = "Add user test name";
|
||||
|
||||
var address = new Address();
|
||||
address.Id = addressId;
|
||||
address.Latitude = 5362.2341652256;
|
||||
address.Longitude = 5362.2341333317;
|
||||
address.AddressText = "1214 Kossuth Lajos utca 124.";
|
||||
|
||||
user.Profile = profile;
|
||||
user.Profile.Address = address;
|
||||
|
||||
Assert.IsTrue(await Dal.AddUserAsync(user));
|
||||
user = Dal.GetUserById(userId);
|
||||
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsNotNull(user.Profile);
|
||||
Assert.IsNotNull(user.Profile.Address);
|
||||
|
||||
Assert.IsTrue(await Dal.RemoveUserAsync(userId)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
|
||||
|
||||
user = Dal.GetUserById(userId);
|
||||
Assert.IsNull(user); //a korábbi törlés miatt NULL kell legyen - J.
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,16 +10,10 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.Development.json" />
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
|
|
@ -32,6 +26,8 @@
|
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" 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" />
|
||||
<PackageReference Include="Moq" Version="4.20.70" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
|
||||
|
|
|
|||
|
|
@ -24,15 +24,13 @@ namespace TIAM.Database.Test
|
|||
private const string LoginEmail = "asdfsdf@ggggg.hu";
|
||||
private const string LoginPassword = "alad'r";
|
||||
|
||||
private WebAssemblyHostConfiguration _configuration = new();
|
||||
//private WebAssemblyHostConfiguration _configuration = new();
|
||||
//private Mock<UserDbContext> _mockContext;
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
_configuration = new WebAssemblyHostConfiguration();
|
||||
_configuration.Build();
|
||||
_configuration.Reload();
|
||||
//AppSettingsConfiguration = InitAppSettingsConfiguration();
|
||||
|
||||
//_configuration["JWT:Key"] = "Cee4400-rDMFkVvHPufyLDSzbfu2grgRhpepos299IhTLOXsljkcpt3yUR4RRjPQ";
|
||||
//_configuration["JWT:Audience"] = "http://localhost:5000";
|
||||
|
|
@ -57,10 +55,18 @@ namespace TIAM.Database.Test
|
|||
|
||||
await Dal.RemoveUserAsync(_registerUserId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
||||
|
||||
var loginService = new LoginService(Dal, _configuration);
|
||||
var loginService = new LoginService(Dal, AppSettingsConfiguration);
|
||||
var errorCode = await loginService.RegistrationAsync(_registerUserId, RegisterEmail, RegisterPassword, null);
|
||||
|
||||
Assert.IsTrue(errorCode == AcErrorCode.Unset);
|
||||
|
||||
var user = Dal.GetUserByEmail(RegisterEmail);
|
||||
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsNotNull(user.Profile);
|
||||
Assert.IsNotNull(user.Profile.Address);
|
||||
|
||||
await Dal.RemoveUserAsync(user); //kitöröljük a szemetet - J.
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
@ -68,7 +74,7 @@ namespace TIAM.Database.Test
|
|||
{
|
||||
//var a = TiamConst.ProjectIdString;
|
||||
|
||||
var loginService = new LoginService(Dal, _configuration);
|
||||
var loginService = new LoginService(Dal, AppSettingsConfiguration);
|
||||
|
||||
#region Valid email+password test
|
||||
var loggedInModel = loginService.Login(LoginEmail, LoginPassword);
|
||||
|
|
@ -161,6 +167,50 @@ namespace TIAM.Database.Test
|
|||
Assert.IsTrue(userModel.UserToServiceProviders.Count > 0);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(["e31044d7-1771-4a32-8dd9-6f9853ed53c6", "0a831191-70a3-4504-9ec4-c5902affaba7", "8eed080c-d2ce-4cc3-bcfe-2268c220bba7", "addUser_test9432@tiam.hu"])]
|
||||
public async Task AddUserTest(string[] userIdProfileIdAddressIdEmailStrings)
|
||||
{
|
||||
var userId = Guid.Parse(userIdProfileIdAddressIdEmailStrings[0]);
|
||||
var profileId = Guid.Parse(userIdProfileIdAddressIdEmailStrings[1]);
|
||||
var addressId = Guid.Parse(userIdProfileIdAddressIdEmailStrings[2]);
|
||||
var email = userIdProfileIdAddressIdEmailStrings[3];
|
||||
|
||||
var fromAddress = "Budapest, Liszt Ferenc tér";
|
||||
var toAddress = "1211 Budapest, Kossuth Lajos utca 145";
|
||||
//var userProductToCarId = Guid.Parse("97179a87-d99f-4f12-b7b2-75e21aaec6ab");
|
||||
|
||||
await Dal.RemoveUserAsync(userId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
||||
|
||||
var user = new User(userId, email, "235664", "dsfglfjg45r34903t3kggvq");
|
||||
user.ProfileId = profileId;
|
||||
|
||||
var profile = new Profile();
|
||||
profile.Id = profileId;;
|
||||
profile.Name = "Add user test name";
|
||||
|
||||
var address = new Address();
|
||||
address.Id = addressId;
|
||||
address.Latitude = 5362.2341652256;
|
||||
address.Longitude = 5362.2341333317;
|
||||
address.AddressText = "1214 Kossuth Lajos utca 124.";
|
||||
|
||||
user.Profile = profile;
|
||||
user.Profile.AddressId = addressId;
|
||||
user.Profile.Address = address;
|
||||
|
||||
Assert.IsTrue(await Dal.AddUserAsync(user));
|
||||
user = Dal.GetUserById(userId);
|
||||
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsNotNull(user.Profile);
|
||||
Assert.IsNotNull(user.Profile.Address);
|
||||
|
||||
Assert.IsTrue(await Dal.RemoveUserAsync(userId)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
|
||||
|
||||
user = Dal.GetUserById(userId);
|
||||
Assert.IsNull(user); //a korábbi törlés miatt NULL kell legyen - J.
|
||||
}
|
||||
//[TestMethod]
|
||||
//[DataRow("test@tiam.hu")]
|
||||
//public async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"JWT": {
|
||||
"Key": "Cee4400-rDMFkVvHPufyLDSzbfu2grgRhpepos299IhTLOXsljkcpt3yUR4RRjPQ",
|
||||
"Issuer": "https://localhost:7116",
|
||||
"Audience": "http://localhost:7116"
|
||||
},
|
||||
"SendGrid": {
|
||||
//"Key": "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"
|
||||
"Key": "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"
|
||||
}
|
||||
}
|
||||
|
|
@ -101,30 +101,30 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
public string? GetUserJsonById(Guid userId) => Session(ctx => ctx.GetUserById(userId)?.ToJson());
|
||||
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
|
||||
|
||||
public Task<bool> AddUserAsync(User user) => TransactionAsync(ctx => ctx.AddUser(user));
|
||||
//public Task<bool> AddUserAsync(User user) => TransactionAsync(ctx => ctx.AddUser(user));
|
||||
|
||||
public Task<bool> AddUserAsync(User user, string profileName, Address address, string? firstName = null, string? lastName = null)
|
||||
{
|
||||
return TransactionAsync(ctx =>
|
||||
{
|
||||
var profile = new Profile
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = profileName,
|
||||
FirstName = firstName,
|
||||
LastName = lastName,
|
||||
Address = address,
|
||||
AddressId = address.Id
|
||||
};
|
||||
//public Task<bool> AddUserAsync(User user, string profileName, Address address, string? firstName = null, string? lastName = null)
|
||||
//{
|
||||
// return TransactionAsync(ctx =>
|
||||
// {
|
||||
// var profile = new Profile
|
||||
// {
|
||||
// Id = Guid.NewGuid(),
|
||||
// Name = profileName,
|
||||
// FirstName = firstName,
|
||||
// LastName = lastName,
|
||||
// Address = address,
|
||||
// AddressId = address.Id
|
||||
// };
|
||||
|
||||
user.Profile= profile;
|
||||
// user.Profile= profile;
|
||||
|
||||
return ctx.AddUser(user);
|
||||
});
|
||||
}
|
||||
// return ctx.AddUser(user);
|
||||
// });
|
||||
//}
|
||||
|
||||
public Task<bool> RemoveUserAsync(User user) => TransactionAsync(ctx => ctx.RemoveUser(user));
|
||||
public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx => ctx.RemoveUser(userId));
|
||||
//public Task<bool> RemoveUserAsync(User user) => TransactionAsync(ctx => ctx.RemoveUser(user));
|
||||
//public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx => ctx.RemoveUser(userId));
|
||||
|
||||
public Product? GetProductById(Guid contextId, bool includeUsers = true) => Session(ctx => ctx.GetProductById(contextId, includeUsers));
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace TIAM.Database.DbContexts.Users
|
|||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<UserToken> UserTokens { get; set; }
|
||||
|
||||
public DbSet<Profile> Profiles { get; set; }
|
||||
public DbSet<Address> Addresses { get; set; }
|
||||
|
||||
public DbSet<Transfer> Transfers { get; set; }
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
userToCreate.Profile.Address.AddressText = null;
|
||||
userToCreate.Profile.Address.Latitude = Math.Round(90 + rnd.NextDouble(), 8);
|
||||
userToCreate.Profile.Address.Longitude = Math.Round(180 + rnd.NextDouble(), 8);
|
||||
result = await _adminDal.AddUserAsync(userToCreate);
|
||||
result = await _userDal.AddUserAsync(userToCreate);
|
||||
guestUser = await _userDal.GetUserModelDtoDetailByIdAsync(userId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue