Skip to content

Commit

Permalink
Fixed updated events, added integration tests. (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: Francis Pion <francis.pion@akinox.com>
  • Loading branch information
Utar94 and fpion-akinox authored Feb 8, 2024
1 parent f4c9fc6 commit bab47f9
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public record ApiKeyUpdatedEvent : DomainEvent, INotification
/// <summary>
/// Gets or sets the display name of the API key.
/// </summary>
public DisplayNameUnit? DisplayName { get; internal set; }
public DisplayNameUnit? DisplayName { get; set; }
/// <summary>
/// Gets or sets the description of the API key.
/// </summary>
public Modification<DescriptionUnit>? Description { get; internal set; }
public Modification<DescriptionUnit>? Description { get; set; }
/// <summary>
/// Gets or sets the expiration date and time of the API key.
/// </summary>
public DateTime? ExpiresOn { get; internal set; }
public DateTime? ExpiresOn { get; set; }

/// <summary>
/// Gets or sets the custom attribute modifications of the API key.
Expand Down
6 changes: 3 additions & 3 deletions src/Logitar.Identity.Domain/Logitar.Identity.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/Logitar/Identity</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>0.11.5.0</AssemblyVersion>
<AssemblyVersion>0.11.6.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Version>0.11.5</Version>
<Version>0.11.6</Version>
<NeutralLanguage>en-CA</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReleaseNotes>Fixed LocaleUnit.</PackageReleaseNotes>
<PackageReleaseNotes>Fixed updated events.</PackageReleaseNotes>
<PackageTags>logitar;net;framework;identity;domain</PackageTags>
<PackageProjectUrl>https://github.com/Logitar/Identity/tree/main/src/Logitar.Identity.Domain</PackageProjectUrl>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Logitar.Identity.Domain/Roles/Events/RoleUpdatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public record RoleUpdatedEvent : DomainEvent, INotification
/// <summary>
/// Gets or sets the display name of the role.
/// </summary>
public Modification<DisplayNameUnit>? DisplayName { get; internal set; }
public Modification<DisplayNameUnit>? DisplayName { get; set; }
/// <summary>
/// Gets or sets the description of the role.
/// </summary>
public Modification<DescriptionUnit>? Description { get; internal set; }
public Modification<DescriptionUnit>? Description { get; set; }

/// <summary>
/// Gets or sets the custom attribute modifications of the role.
Expand Down
24 changes: 12 additions & 12 deletions src/Logitar.Identity.Domain/Users/Events/UserUpdatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@ public record UserUpdatedEvent : DomainEvent, INotification
/// <summary>
/// Gets or sets the first name of the user.
/// </summary>
public Modification<PersonNameUnit>? FirstName { get; internal set; }
public Modification<PersonNameUnit>? FirstName { get; set; }
/// <summary>
/// Gets or sets the middle name of the user.
/// </summary>
public Modification<PersonNameUnit>? MiddleName { get; internal set; }
public Modification<PersonNameUnit>? MiddleName { get; set; }
/// <summary>
/// Gets or sets the last name of the user.
/// </summary>
public Modification<PersonNameUnit>? LastName { get; internal set; }
public Modification<PersonNameUnit>? LastName { get; set; }
/// <summary>
/// Gets or sets the full name of the user.
/// </summary>
public Modification<string>? FullName { get; internal set; }
public Modification<string>? FullName { get; set; }
/// <summary>
/// Gets or sets the nickname of the user.
/// </summary>
public Modification<PersonNameUnit>? Nickname { get; internal set; }
public Modification<PersonNameUnit>? Nickname { get; set; }

/// <summary>
/// Gets or sets the birthdate of the user.
/// </summary>
public Modification<DateTime?>? Birthdate { get; internal set; }
public Modification<DateTime?>? Birthdate { get; set; }
/// <summary>
/// Gets or sets the gender of the user.
/// </summary>
public Modification<GenderUnit>? Gender { get; internal set; }
public Modification<GenderUnit>? Gender { get; set; }
/// <summary>
/// Gets or sets the locale of the user.
/// </summary>
public Modification<LocaleUnit>? Locale { get; internal set; }
public Modification<LocaleUnit>? Locale { get; set; }
/// <summary>
/// Gets or sets the time zone of the user.
/// </summary>
public Modification<TimeZoneUnit>? TimeZone { get; internal set; }
public Modification<TimeZoneUnit>? TimeZone { get; set; }

/// <summary>
/// Gets or sets the URL to the picture of the user.
/// </summary>
public Modification<UrlUnit>? Picture { get; internal set; }
public Modification<UrlUnit>? Picture { get; set; }
/// <summary>
/// Gets or sets the URL to the profile page of the user.
/// </summary>
public Modification<UrlUnit>? Profile { get; internal set; }
public Modification<UrlUnit>? Profile { get; set; }
/// <summary>
/// Gets or sets the URL to the website of the user.
/// </summary>
public Modification<UrlUnit>? Website { get; internal set; }
public Modification<UrlUnit>? Website { get; set; }

/// <summary>
/// Gets or sets the custom attribute modifications of the user.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Logitar.Identity.Domain.Roles;
using Logitar.Identity.EntityFrameworkCore.Relational.Entities;

namespace Logitar.Identity.EntityFrameworkCore.SqlServer;

internal static class AssertRoles
{
public static void AreEqual(RoleAggregate? role, RoleEntity? entity)
{
if (role == null || entity == null)
{
Assert.Null(role);
Assert.Null(entity);
return;
}

Assert.Equal(role.Version, entity.Version);
Assert.Equal(role.CreatedBy.Value, entity.CreatedBy);
Assertions.Equal(role.CreatedOn, entity.CreatedOn, TimeSpan.FromMinutes(1));
Assert.Equal(role.UpdatedBy.Value, entity.UpdatedBy);
Assertions.Equal(role.UpdatedOn, entity.UpdatedOn, TimeSpan.FromMinutes(1));

Assert.Equal(role.TenantId?.Value, entity.TenantId);
Assert.Equal(role.UniqueName.Value, entity.UniqueName);
Assert.Equal(role.DisplayName?.Value, entity.DisplayName);
Assert.Equal(role.Description?.Value, entity.Description);

Assert.Equal(role.CustomAttributes, entity.CustomAttributes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ApiKeyRepositoryTests() : base()
Description = new DescriptionUnit("This is the default API key.")
};
_apiKey.SetExpiration(DateTime.Now.AddYears(1));
_apiKey.SetCustomAttribute("TODO", "TODO");
_apiKey.SetCustomAttribute("OwnerId", Guid.NewGuid().ToString());
_apiKey.Update(actorId);

_apiKey.AddRole(_role, actorId);
Expand Down Expand Up @@ -153,8 +153,8 @@ public async Task LoadAsync_it_should_load_the_Api_keys_by_identifiers()
[Fact(DisplayName = "SaveAsync: it should save the deleted API key.")]
public async Task SaveAsync_it_should_save_the_deleted_Api_key()
{
_apiKey.SetCustomAttribute("TODO", "TODO");
_apiKey.SetCustomAttribute("TODO", "TODO");
_apiKey.SetCustomAttribute("Confidentiality", "Private");
_apiKey.SetCustomAttribute("SubSystem", "IntegrationTests");
_apiKey.Update();
await _apiKeyRepository.SaveAsync(_apiKey);

Expand Down Expand Up @@ -197,6 +197,12 @@ public async Task SaveAsync_it_should_save_the_specified_Api_key()
.Where(x => x.EntityType == nameof(IdentityContext.ApiKeys) && x.EntityId == entity.ApiKeyId)
.ToDictionaryAsync(x => x.Key, x => x.Value);
Assert.Equal(_apiKey.CustomAttributes, customAttributes);

ApiKeyAggregate? apiKey = await _apiKeyRepository.LoadAsync(_apiKey.Id);
Assert.NotNull(apiKey);
Assert.Equal(_apiKey.Description, apiKey.Description);
Assert.Equal(_apiKey.ExpiresOn, apiKey.ExpiresOn);
Assert.Equal(_apiKey.CustomAttributes, apiKey.CustomAttributes);
}

[Fact(DisplayName = "SaveAsync: it should save the specified API keys.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public OneTimePasswordRepositoryTests() : base()

_password = _passwordManager.Create(PasswordString);
_oneTimePassword = new(_password, tenantId, expiresOn, maximumAttempts, actorId, id);
_oneTimePassword.SetCustomAttribute("Purpose", "MultiFactorAuthentication");
_oneTimePassword.SetCustomAttribute("UserId", Guid.NewGuid().ToString());
_oneTimePassword.Update(actorId);
}

public async Task InitializeAsync()
Expand Down Expand Up @@ -151,6 +154,10 @@ public async Task SaveAsync_it_should_save_the_specified_One_Time_Password()
.Where(x => x.EntityType == nameof(IdentityContext.OneTimePasswords) && x.EntityId == entity.OneTimePasswordId)
.ToDictionaryAsync(x => x.Key, x => x.Value);
Assert.Equal(_oneTimePassword.CustomAttributes, customAttributes);

OneTimePasswordAggregate? oneTimePassword = await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.Id);
Assert.NotNull(oneTimePassword);
Assert.Equal(_oneTimePassword.CustomAttributes, oneTimePassword.CustomAttributes);
}

[Fact(DisplayName = "SaveAsync: it should save the specified One-Time Passwords.")]
Expand Down
Loading

0 comments on commit bab47f9

Please sign in to comment.