From 86e621db1cf270b46a7254b98e8d7faa66029f1e Mon Sep 17 00:00:00 2001 From: Paul Welter Date: Sun, 31 Dec 2023 19:33:22 -0600 Subject: [PATCH] fix unit tests --- .../Data/Entities/Audit.cs | 2 +- .../Data/Entities/Priority.cs | 2 +- .../Data/Entities/Role.cs | 2 +- .../Data/Entities/SchemaVersions.cs | 27 +++++++++ .../Data/Entities/Status.cs | 2 +- .../Data/Entities/Task.cs | 2 +- .../Data/Entities/TaskExtended.cs | 2 +- .../Data/Entities/Tenant.cs | 2 +- .../Data/Entities/User.cs | 2 +- .../Data/Entities/UserLogin.cs | 2 +- .../Data/Mapping/AuditMap.cs | 3 +- .../Data/Mapping/PriorityMap.cs | 8 ++- .../Data/Mapping/RoleMap.cs | 3 +- .../Data/Mapping/SchemaVersionsMap.cs | 56 +++++++++++++++++++ .../Data/Mapping/StatusMap.cs | 8 ++- .../Data/Mapping/TaskExtendedMap.cs | 3 +- .../Data/Mapping/TaskMap.cs | 6 +- .../Data/Mapping/TenantMap.cs | 5 +- .../Data/Mapping/UserLoginMap.cs | 6 +- .../Data/Mapping/UserMap.cs | 15 +++-- .../Data/Queries/AuditExtensions.cs | 15 +++-- .../Data/Queries/PriorityExtensions.cs | 15 +++-- .../Data/Queries/RoleExtensions.cs | 27 ++++++--- .../Data/Queries/SchemaVersionsExtensions.cs | 38 +++++++++++++ .../Data/Queries/StatusExtensions.cs | 15 +++-- .../Data/Queries/TaskExtendedExtensions.cs | 15 +++-- .../Data/Queries/TaskExtensions.cs | 35 +++++++++--- .../Data/Queries/TenantExtensions.cs | 15 +++-- .../Data/Queries/UserExtensions.cs | 27 ++++++--- .../Data/Queries/UserLoginExtensions.cs | 25 ++++++--- .../Data/Queries/UserRoleExtensions.cs | 27 ++++++--- .../Data/TrackerContext.cs | 3 + .../Domain/Audit/Mapping/AuditProfile.cs | 3 +- .../Mapping/SchemaVersionsProfile.cs | 26 +++++++++ .../Models/SchemaVersionsCreateModel.cs | 17 ++++++ .../Models/SchemaVersionsReadModel.cs | 17 ++++++ .../Models/SchemaVersionsUpdateModel.cs | 17 ++++++ .../SchemaVersionsCreateModelValidator.cs | 19 +++++++ .../SchemaVersionsUpdateModelValidator.cs | 19 +++++++ .../generation.yml | 4 +- 40 files changed, 440 insertions(+), 97 deletions(-) create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/SchemaVersions.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/SchemaVersionsMap.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/SchemaVersionsExtensions.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Mapping/SchemaVersionsProfile.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsCreateModel.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsReadModel.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsUpdateModel.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsCreateModelValidator.cs create mode 100644 test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsUpdateModelValidator.cs diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Audit.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Audit.cs index 040406d0..d360e718 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Audit.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Audit.cs @@ -33,7 +33,7 @@ public Audit() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Priority.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Priority.cs index 8c764631..5e19bff2 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Priority.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Priority.cs @@ -33,7 +33,7 @@ public Priority() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Role.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Role.cs index 14d6d360..85f30263 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Role.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Role.cs @@ -29,7 +29,7 @@ public Role() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/SchemaVersions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/SchemaVersions.cs new file mode 100644 index 00000000..97dceb46 --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/SchemaVersions.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities +{ + public partial class SchemaVersions + { + public SchemaVersions() + { + #region Generated Constructor + #endregion + } + + #region Generated Properties + public int Id { get; set; } + + public string ScriptName { get; set; } + + public DateTime Applied { get; set; } + + #endregion + + #region Generated Relationships + #endregion + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Status.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Status.cs index 823b6e35..a9c6a87f 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Status.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Status.cs @@ -33,7 +33,7 @@ public Status() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Task.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Task.cs index 783edd01..91e6988c 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Task.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Task.cs @@ -43,7 +43,7 @@ public Task() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/TaskExtended.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/TaskExtended.cs index f69bc660..30ed7be9 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/TaskExtended.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/TaskExtended.cs @@ -29,7 +29,7 @@ public TaskExtended() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Tenant.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Tenant.cs index 7c84ebb4..1b369790 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Tenant.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/Tenant.cs @@ -31,7 +31,7 @@ public Tenant() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/User.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/User.cs index 359b3f87..d3b58af8 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/User.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/User.cs @@ -49,7 +49,7 @@ public User() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/UserLogin.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/UserLogin.cs index e6025970..e4e1c419 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/UserLogin.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Entities/UserLogin.cs @@ -45,7 +45,7 @@ public UserLogin() public string UpdatedBy { get; set; } - public Byte[] RowVersion { get; set; } + public long RowVersion { get; set; } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/AuditMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/AuditMap.cs index fd718935..9bf9bb4a 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/AuditMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/AuditMap.cs @@ -73,10 +73,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/PriorityMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/PriorityMap.cs index 79da8889..5b5f265d 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/PriorityMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/PriorityMap.cs @@ -39,13 +39,14 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.DisplayOrder) .IsRequired() .HasColumnName("DisplayOrder") - .HasColumnType("int"); + .HasColumnType("int") + .HasDefaultValue(0); builder.Property(t => t.IsActive) .IsRequired() .HasColumnName("IsActive") .HasColumnType("bit") - .HasDefaultValueSql("((1))"); + .HasDefaultValue(true); builder.Property(t => t.Created) .IsRequired() @@ -71,10 +72,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/RoleMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/RoleMap.cs index 5351f507..7a5eeefe 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/RoleMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/RoleMap.cs @@ -59,10 +59,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/SchemaVersionsMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/SchemaVersionsMap.cs new file mode 100644 index 00000000..4a5459a3 --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/SchemaVersionsMap.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping +{ + public partial class SchemaVersionsMap + : IEntityTypeConfiguration + { + public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder builder) + { + #region Generated Configure + // table + builder.ToTable("SchemaVersions", "dbo"); + + // key + builder.HasKey(t => t.Id); + + // properties + builder.Property(t => t.Id) + .IsRequired() + .HasColumnName("Id") + .HasColumnType("int") + .ValueGeneratedOnAdd(); + + builder.Property(t => t.ScriptName) + .IsRequired() + .HasColumnName("ScriptName") + .HasColumnType("nvarchar(255)") + .HasMaxLength(255); + + builder.Property(t => t.Applied) + .IsRequired() + .HasColumnName("Applied") + .HasColumnType("datetime"); + + // relationships + #endregion + } + + #region Generated Constants + public readonly struct Table + { + public const string Schema = "dbo"; + public const string Name = "SchemaVersions"; + } + + public readonly struct Columns + { + public const string Id = "Id"; + public const string ScriptName = "ScriptName"; + public const string Applied = "Applied"; + } + #endregion + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/StatusMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/StatusMap.cs index bc4b2515..165d2e07 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/StatusMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/StatusMap.cs @@ -39,13 +39,14 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.DisplayOrder) .IsRequired() .HasColumnName("DisplayOrder") - .HasColumnType("int"); + .HasColumnType("int") + .HasDefaultValue(0); builder.Property(t => t.IsActive) .IsRequired() .HasColumnName("IsActive") .HasColumnType("bit") - .HasDefaultValueSql("((1))"); + .HasDefaultValue(true); builder.Property(t => t.Created) .IsRequired() @@ -71,10 +72,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskExtendedMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskExtendedMap.cs index 4c9b82e9..f22f080f 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskExtendedMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskExtendedMap.cs @@ -62,10 +62,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskMap.cs index 5d54e0f6..89b1a700 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TaskMap.cs @@ -68,7 +68,8 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.IsDeleted) .IsRequired() .HasColumnName("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("bit") + .HasDefaultValue(false); builder.Property(t => t.Created) .IsRequired() @@ -94,10 +95,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TenantMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TenantMap.cs index ba029cb9..4cc5f462 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TenantMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/TenantMap.cs @@ -40,7 +40,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType .IsRequired() .HasColumnName("IsActive") .HasColumnType("bit") - .HasDefaultValueSql("((1))"); + .HasDefaultValue(true); builder.Property(t => t.Created) .IsRequired() @@ -66,10 +66,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserLoginMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserLoginMap.cs index 983040d5..66ae2e87 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserLoginMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserLoginMap.cs @@ -72,7 +72,8 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.IsSuccessful) .IsRequired() .HasColumnName("IsSuccessful") - .HasColumnType("bit"); + .HasColumnType("bit") + .HasDefaultValue(false); builder.Property(t => t.FailureMessage) .HasColumnName("FailureMessage") @@ -103,10 +104,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserMap.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserMap.cs index 3bea49e1..65da68be 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserMap.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Mapping/UserMap.cs @@ -34,7 +34,8 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.IsEmailAddressConfirmed) .IsRequired() .HasColumnName("IsEmailAddressConfirmed") - .HasColumnType("bit"); + .HasColumnType("bit") + .HasDefaultValue(false); builder.Property(t => t.DisplayName) .IsRequired() @@ -57,12 +58,14 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.AccessFailedCount) .IsRequired() .HasColumnName("AccessFailedCount") - .HasColumnType("int"); + .HasColumnType("int") + .HasDefaultValue(0); builder.Property(t => t.LockoutEnabled) .IsRequired() .HasColumnName("LockoutEnabled") - .HasColumnType("bit"); + .HasColumnType("bit") + .HasDefaultValue(false); builder.Property(t => t.LockoutEnd) .HasColumnName("LockoutEnd") @@ -75,7 +78,8 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.IsDeleted) .IsRequired() .HasColumnName("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("bit") + .HasDefaultValue(false); builder.Property(t => t.Created) .IsRequired() @@ -101,10 +105,11 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType builder.Property(t => t.RowVersion) .IsRequired() + .HasConversion() .IsRowVersion() + .IsConcurrencyToken() .HasColumnName("RowVersion") .HasColumnType("rowversion") - .HasMaxLength(8) .ValueGeneratedOnAddOrUpdate(); // relationships diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/AuditExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/AuditExtensions.cs index 11d9ec1f..5f94b64f 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/AuditExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/AuditExtensions.cs @@ -11,21 +11,26 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class AuditExtensions { #region Generated Extensions - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Audit GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Audit GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/PriorityExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/PriorityExtensions.cs index e5ebf30c..f870cf1d 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/PriorityExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/PriorityExtensions.cs @@ -11,21 +11,26 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class PriorityExtensions { #region Generated Extensions - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Priority GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Priority GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/RoleExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/RoleExtensions.cs index 4a0e4e70..544a65ee 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/RoleExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/RoleExtensions.cs @@ -11,31 +11,42 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class RoleExtensions { #region Generated Extensions - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Role GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Role GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Role GetByName(this IQueryable queryable, string name) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Role GetByName(this System.Linq.IQueryable queryable, string name) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.FirstOrDefault(q => q.Name == name); } - public static Task GetByNameAsync(this IQueryable queryable, string name) + public static async System.Threading.Tasks.Task GetByNameAsync(this System.Linq.IQueryable queryable, string name, System.Threading.CancellationToken cancellationToken = default) { - return queryable.FirstOrDefaultAsync(q => q.Name == name); + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + + return await queryable.FirstOrDefaultAsync(q => q.Name == name, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/SchemaVersionsExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/SchemaVersionsExtensions.cs new file mode 100644 index 00000000..22f4e9ca --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/SchemaVersionsExtensions.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries +{ + public static partial class SchemaVersionsExtensions + { + #region Generated Extensions + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.SchemaVersions GetByKey(this System.Linq.IQueryable queryable, int id) + { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + + if (queryable is DbSet dbSet) + return dbSet.Find(id); + + return queryable.FirstOrDefault(q => q.Id == id); + } + + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, int id, System.Threading.CancellationToken cancellationToken = default) + { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + + if (queryable is DbSet dbSet) + return await dbSet.FindAsync(new object[] { id }, cancellationToken); + + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); + } + + #endregion + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/StatusExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/StatusExtensions.cs index daeb8dc0..6d9edeaa 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/StatusExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/StatusExtensions.cs @@ -11,21 +11,26 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class StatusExtensions { #region Generated Extensions - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Status GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Status GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtendedExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtendedExtensions.cs index 2286aee2..9c74485d 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtendedExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtendedExtensions.cs @@ -11,21 +11,26 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class TaskExtendedExtensions { #region Generated Extensions - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.TaskExtended GetByKey(this IQueryable queryable, Guid taskId) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.TaskExtended GetByKey(this System.Linq.IQueryable queryable, Guid taskId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(taskId); return queryable.FirstOrDefault(q => q.TaskId == taskId); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid taskId) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid taskId, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(taskId); + return await dbSet.FindAsync(new object[] { taskId }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.TaskId == taskId); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.TaskId == taskId, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtensions.cs index 76c1b96b..1262d82a 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TaskExtensions.cs @@ -11,40 +11,57 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class TaskExtensions { #region Generated Extensions - public static IQueryable ByAssignedId(this IQueryable queryable, Guid? assignedId) + public static System.Linq.IQueryable ByAssignedId(this System.Linq.IQueryable queryable, Guid? assignedId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => (q.AssignedId == assignedId || (assignedId == null && q.AssignedId == null))); } - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Task GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Task GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } - public static IQueryable ByPriorityId(this IQueryable queryable, Guid? priorityId) + public static System.Linq.IQueryable ByPriorityId(this System.Linq.IQueryable queryable, Guid? priorityId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => (q.PriorityId == priorityId || (priorityId == null && q.PriorityId == null))); } - public static IQueryable ByStatusId(this IQueryable queryable, Guid statusId) + public static System.Linq.IQueryable ByStatusId(this System.Linq.IQueryable queryable, Guid statusId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => q.StatusId == statusId); } - public static IQueryable ByTenantId(this IQueryable queryable, Guid tenantId) + public static System.Linq.IQueryable ByTenantId(this System.Linq.IQueryable queryable, Guid tenantId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => q.TenantId == tenantId); } diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TenantExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TenantExtensions.cs index 97ba3db4..03746205 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TenantExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/TenantExtensions.cs @@ -11,21 +11,26 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class TenantExtensions { #region Generated Extensions - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Tenant GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.Tenant GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserExtensions.cs index 8bab67c2..eb3aee0c 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserExtensions.cs @@ -11,31 +11,42 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class UserExtensions { #region Generated Extensions - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.User GetByEmailAddress(this IQueryable queryable, string emailAddress) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.User GetByEmailAddress(this System.Linq.IQueryable queryable, string emailAddress) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.FirstOrDefault(q => q.EmailAddress == emailAddress); } - public static Task GetByEmailAddressAsync(this IQueryable queryable, string emailAddress) + public static async System.Threading.Tasks.Task GetByEmailAddressAsync(this System.Linq.IQueryable queryable, string emailAddress, System.Threading.CancellationToken cancellationToken = default) { - return queryable.FirstOrDefaultAsync(q => q.EmailAddress == emailAddress); + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + + return await queryable.FirstOrDefaultAsync(q => q.EmailAddress == emailAddress, cancellationToken); } - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.User GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.User GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserLoginExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserLoginExtensions.cs index 94cffb49..0ea787de 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserLoginExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserLoginExtensions.cs @@ -11,30 +11,41 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class UserLoginExtensions { #region Generated Extensions - public static IQueryable ByEmailAddress(this IQueryable queryable, string emailAddress) + public static System.Linq.IQueryable ByEmailAddress(this System.Linq.IQueryable queryable, string emailAddress) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => q.EmailAddress == emailAddress); } - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.UserLogin GetByKey(this IQueryable queryable, Guid id) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.UserLogin GetByKey(this System.Linq.IQueryable queryable, Guid id) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(id); return queryable.FirstOrDefault(q => q.Id == id); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid id, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(id); + return await dbSet.FindAsync(new object[] { id }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.Id == id); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.Id == id, cancellationToken); } - public static IQueryable ByUserId(this IQueryable queryable, Guid? userId) + public static System.Linq.IQueryable ByUserId(this System.Linq.IQueryable queryable, Guid? userId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => (q.UserId == userId || (userId == null && q.UserId == null))); } diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserRoleExtensions.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserRoleExtensions.cs index cc536c76..d1380dc8 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserRoleExtensions.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/Queries/UserRoleExtensions.cs @@ -11,18 +11,27 @@ namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Queries; public static partial class UserRoleExtensions { #region Generated Extensions - public static IQueryable ByRoleId(this IQueryable queryable, Guid roleId) + public static System.Linq.IQueryable ByRoleId(this System.Linq.IQueryable queryable, Guid roleId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => q.RoleId == roleId); } - public static IQueryable ByUserId(this IQueryable queryable, Guid userId) + public static System.Linq.IQueryable ByUserId(this System.Linq.IQueryable queryable, Guid userId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + return queryable.Where(q => q.UserId == userId); } - public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.UserRole GetByKey(this IQueryable queryable, Guid userId, Guid roleId) + public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities.UserRole GetByKey(this System.Linq.IQueryable queryable, Guid userId, Guid roleId) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) return dbSet.Find(userId, roleId); @@ -30,14 +39,16 @@ public static MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Enti && q.RoleId == roleId); } - public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid userId, Guid roleId) + public static async System.Threading.Tasks.ValueTask GetByKeyAsync(this System.Linq.IQueryable queryable, Guid userId, Guid roleId, System.Threading.CancellationToken cancellationToken = default) { + if (queryable is null) + throw new ArgumentNullException(nameof(queryable)); + if (queryable is DbSet dbSet) - return dbSet.FindAsync(userId, roleId); + return await dbSet.FindAsync(new object[] { userId, roleId }, cancellationToken); - var task = queryable.FirstOrDefaultAsync(q => q.UserId == userId - && q.RoleId == roleId); - return new ValueTask(task); + return await queryable.FirstOrDefaultAsync(q => q.UserId == userId + && q.RoleId == roleId, cancellationToken); } #endregion diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/TrackerContext.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/TrackerContext.cs index ae9c010e..2b4e8982 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/TrackerContext.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Data/TrackerContext.cs @@ -16,6 +16,8 @@ public TrackerContext(DbContextOptions options) public virtual DbSet Roles { get; set; } + public virtual DbSet SchemaVersions { get; set; } + public virtual DbSet Statuses { get; set; } public virtual DbSet TaskExtendeds { get; set; } @@ -38,6 +40,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.ApplyConfiguration(new MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping.AuditMap()); modelBuilder.ApplyConfiguration(new MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping.PriorityMap()); modelBuilder.ApplyConfiguration(new MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping.RoleMap()); + modelBuilder.ApplyConfiguration(new MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping.SchemaVersionsMap()); modelBuilder.ApplyConfiguration(new MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping.StatusMap()); modelBuilder.ApplyConfiguration(new MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping.TaskExtendedMap()); modelBuilder.ApplyConfiguration(new MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Mapping.TaskMap()); diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/Audit/Mapping/AuditProfile.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/Audit/Mapping/AuditProfile.cs index e9eb2b6f..65bf64be 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/Audit/Mapping/AuditProfile.cs +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/Audit/Mapping/AuditProfile.cs @@ -7,8 +7,7 @@ public partial class AuditProfile { public AuditProfile() { - CreateMap() - .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))); + CreateMap(); CreateMap(); diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Mapping/SchemaVersionsProfile.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Mapping/SchemaVersionsProfile.cs new file mode 100644 index 00000000..ef1b4b76 --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Mapping/SchemaVersionsProfile.cs @@ -0,0 +1,26 @@ +using System; +using AutoMapper; +using MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Data.Entities; +using MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Models; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Mapping +{ + public partial class SchemaVersionsProfile + : AutoMapper.Profile + { + public SchemaVersionsProfile() + { + CreateMap(); + + CreateMap(); + + CreateMap(); + + CreateMap(); + + CreateMap(); + + } + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsCreateModel.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsCreateModel.cs new file mode 100644 index 00000000..d2faea94 --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsCreateModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Models +{ + public partial class SchemaVersionsCreateModel + : EntityCreateModel + { + #region Generated Properties + public string ScriptName { get; set; } + + public DateTime Applied { get; set; } + + #endregion + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsReadModel.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsReadModel.cs new file mode 100644 index 00000000..14d90c49 --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsReadModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Models +{ + public partial class SchemaVersionsReadModel + : EntityReadModel + { + #region Generated Properties + public string ScriptName { get; set; } + + public DateTime Applied { get; set; } + + #endregion + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsUpdateModel.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsUpdateModel.cs new file mode 100644 index 00000000..81b3eff5 --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Models/SchemaVersionsUpdateModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Models +{ + public partial class SchemaVersionsUpdateModel + : EntityUpdateModel + { + #region Generated Properties + public string ScriptName { get; set; } + + public DateTime Applied { get; set; } + + #endregion + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsCreateModelValidator.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsCreateModelValidator.cs new file mode 100644 index 00000000..34b09d4c --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsCreateModelValidator.cs @@ -0,0 +1,19 @@ +using System; +using FluentValidation; +using MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Models; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Validation +{ + public partial class SchemaVersionsCreateModelValidator + : AbstractValidator + { + public SchemaVersionsCreateModelValidator() + { + #region Generated Constructor + RuleFor(p => p.ScriptName).NotEmpty(); + RuleFor(p => p.ScriptName).MaximumLength(255); + #endregion + } + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsUpdateModelValidator.cs b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsUpdateModelValidator.cs new file mode 100644 index 00000000..7717c702 --- /dev/null +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/Domain/SchemaVersions/Validation/SchemaVersionsUpdateModelValidator.cs @@ -0,0 +1,19 @@ +using System; +using FluentValidation; +using MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Models; + +namespace MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests.Domain.Validation +{ + public partial class SchemaVersionsUpdateModelValidator + : AbstractValidator + { + public SchemaVersionsUpdateModelValidator() + { + #region Generated Constructor + RuleFor(p => p.ScriptName).NotEmpty(); + RuleFor(p => p.ScriptName).MaximumLength(255); + #endregion + } + + } +} diff --git a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/generation.yml b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/generation.yml index 6a801141..53a7d92f 100644 --- a/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/generation.yml +++ b/test/MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests/generation.yml @@ -1,8 +1,9 @@ project: namespace: 'MediatR.CommandQuery.EntityFrameworkCore.SqlServer.Tests' directory: .\ + fileScopedNamespace: true database: - connectionString: Data Source=.\SQL2019;Initial Catalog=TrackerCommandQuery;Integrated Security=True + connectionString: Data Source=(local);Initial Catalog=TrackerCommandQuery;Integrated Security=True;TrustServerCertificate=True data: context: name: 'TrackerContext' @@ -15,6 +16,7 @@ data: mapping: namespace: '{Project.Namespace}.Data.Mapping' directory: '{Project.Directory}\Data\Mapping' + rowVersion: long query: generate: true indexPrefix: By