UserModels, Tests improvements, fixes

This commit is contained in:
jozsef.b@aycode.com 2023-12-19 11:41:04 +01:00
parent e7bbf97773
commit ede481f858
4 changed files with 21 additions and 17 deletions

View File

@ -12,31 +12,31 @@ namespace AyCode.Database.Tests.Users
where TUser : class, IUserBase<TProfile> where TUser : class, IUserBase<TProfile>
where TProfile : class, IAcProfileBase where TProfile : class, IAcProfileBase
where TUserToken : class, IUserTokenBase where TUserToken : class, IUserTokenBase
{ {
[TestMethod] [TestMethod]
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
public virtual void GetUserById_ReturnsUser_WhenUserExists(string userIdString) public virtual void GetUserById_ReturnsUser_WhenUserExists(string userIdString)
{ {
var userId = Guid.Parse(userIdString); var userId = Guid.Parse(userIdString);
var user = Dal.GetUserById(userId); var user = Dal.GetUserById(userId);
Assert.IsNotNull(user, "User is null"); Assert.IsNotNull(user, "User is null");
Assert.IsNotNull(user.Profile, "Profile is null");
Assert.AreEqual(userId, user.Id); Assert.AreEqual(userId, user.Id);
} }
[TestMethod] [TestMethod]
[DataRow("test@tiam.hu")]
public virtual void GetUserByEmail_ReturnsUser_WhenUserExists(string email) public virtual void GetUserByEmail_ReturnsUser_WhenUserExists(string email)
{ {
var user = Dal.GetUserByEmail(email); var user = Dal.GetUserByEmail(email);
Assert.IsNotNull(user, "User is null"); Assert.IsNotNull(user, "User is null");
Assert.IsNotNull(user.Profile, "Profile is null");
Assert.AreEqual(email, user.EmailAddress); Assert.AreEqual(email, user.EmailAddress);
} }
[TestMethod] [TestMethod]
[DataRow("test@tiam.hu")]
public virtual async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email) public virtual async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
{ {
TUser? user = null; TUser? user = null;
@ -51,6 +51,8 @@ namespace AyCode.Database.Tests.Users
//} //}
Assert.IsNotNull(user, "User is null"); Assert.IsNotNull(user, "User is null");
Assert.IsNotNull(user.Profile, "Profile is null");
Assert.AreEqual(email, user.EmailAddress); Assert.AreEqual(email, user.EmailAddress);
} }
} }

View File

@ -5,22 +5,14 @@ using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Models.Users; namespace AyCode.Models.Users;
public abstract class AcUserModelDtoBase<TUserDto, TProfile, TProfileDto> : AcUserModelDtoMinBase<TUserDto, TProfile> public abstract class AcUserModelDtoBase<TUserDto, TProfile, TProfileDto> : AcUserModelDtoMinBase<TUserDto, TProfile, TProfileDto>
where TUserDto : class, IAcUserDtoBase where TUserDto : class, IAcUserDtoBase
where TProfile : class, IAcProfileBase where TProfile : class, IAcProfileBase
where TProfileDto : class, IAcProfileDtoBase where TProfileDto : class, IAcProfileDtoBase
{ {
public TProfileDto Profile { get; set; }
protected AcUserModelDtoBase() {} protected AcUserModelDtoBase() {}
protected AcUserModelDtoBase(IUserBase<TProfile> user, TProfile? profile) : base(user) protected AcUserModelDtoBase(IUserBase<TProfile> user) : base(user)
{ {
if (profile == null) return; //ServiceProvider...
Profile = Activator.CreateInstance<TProfileDto>();
Profile.Id = profile.Id;
Profile.Name = profile.Name;
Profile.OwnerId = profile.OwnerId;
} }
} }

View File

@ -11,7 +11,7 @@ public abstract class AcUserModelDtoDetailBase<TUserDtoDetail, TProfile, TProfil
where TProfileDto : class, IAcProfileDtoBase where TProfileDto : class, IAcProfileDtoBase
{ {
protected AcUserModelDtoDetailBase() {} protected AcUserModelDtoDetailBase() {}
protected AcUserModelDtoDetailBase(IUserBase<TProfile> user, TProfile profile) : base(user, profile) protected AcUserModelDtoDetailBase(IUserBase<TProfile> user) : base(user)
{ {
} }
} }

View File

@ -1,12 +1,17 @@
using AyCode.Interfaces.Profiles; using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Profiles.Dtos;
using AyCode.Interfaces.Users; using AyCode.Interfaces.Users;
using AyCode.Interfaces.Users.Dtos; using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Models.Users; namespace AyCode.Models.Users;
public abstract class AcUserModelDtoMinBase<TUserDtoMin, TProfile> : AcModelDtoBase where TUserDtoMin : IAcUserDtoMinBase where TProfile : class, IAcProfileBase public abstract class AcUserModelDtoMinBase<TUserDtoMin, TProfile, TProfileDto> : AcModelDtoBase
where TUserDtoMin : class, IAcUserDtoMinBase
where TProfile : class, IAcProfileBase
where TProfileDto : class, IAcProfileDtoBase
{ {
public TUserDtoMin UserDto { get; set;} public TUserDtoMin UserDto { get; set;}
public TProfileDto? Profile { get; set; }
protected AcUserModelDtoMinBase() {} protected AcUserModelDtoMinBase() {}
protected AcUserModelDtoMinBase(IUserBase<TProfile> user) : base(user.Id) protected AcUserModelDtoMinBase(IUserBase<TProfile> user) : base(user.Id)
@ -15,5 +20,10 @@ public abstract class AcUserModelDtoMinBase<TUserDtoMin, TProfile> : AcModelDtoB
UserDto = Activator.CreateInstance<TUserDtoMin>(); UserDto = Activator.CreateInstance<TUserDtoMin>();
UserDto.Id = user.Id; UserDto.Id = user.Id;
Profile = Activator.CreateInstance<TProfileDto>();
Profile.Id = user.Profile.Id;
Profile.Name = user.Profile.Name;
Profile.OwnerId = user.Profile.OwnerId;
} }
} }