Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/DKNet.Fw.Extensions/DKNet.Fw.Extensions.csproj
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO NOT changes .NET framework version. This must be a .NET 9

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please fix this

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
4 changes: 2 additions & 2 deletions src/Core/DKNet.Fw.Extensions/Encryption/StringHashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static string ToCmd5(this string value, string key)

using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(key));
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(value));
return Convert.ToHexStringLower(hash);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement of Convert.ToHexStringLower(hash) with BitConverter.ToString(hash).Replace(\"-\", \"\").ToLowerInvariant() creates unnecessary string allocations. Consider using Convert.ToHexString(hash).ToLowerInvariant() if available in .NET 8, or implement a more efficient hex conversion method.

Suggested change
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
return Convert.ToHexString(hash).ToLowerInvariant();

Copilot uses AI. Check for mistakes.
}

/// <summary>
Expand All @@ -54,6 +54,6 @@ public static string ToSha256(this string value)
var hashBytes = SHA256.HashData(inputBytes);

// Use built-in .NET framework method for hex conversion
return Convert.ToHexStringLower(hashBytes);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
Comment on lines 56 to +57
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement of Convert.ToHexStringLower(hash) with BitConverter.ToString(hash).Replace(\"-\", \"\").ToLowerInvariant() creates unnecessary string allocations. Consider using Convert.ToHexString(hash).ToLowerInvariant() if available in .NET 8, or implement a more efficient hex conversion method.

Copilot uses AI. Check for mistakes.
}
}
2 changes: 1 addition & 1 deletion src/Core/DKNet.RandomCreator/DKNet.RandomCreator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Fw.Extensions.Tests/Fw.Extensions.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>-->
<LangVersion>default</LangVersion>
<Nullable>disable</Nullable>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/RandomCreatorTests/RandomCreatorTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>RandomCreatorTests</PackageId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion src/EfCore/DKNet.EfCore.Events/DKNet.EfCore.Events.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public sealed class GuidV7ValueGenerator : ValueGenerator<Guid>
{
public override bool GeneratesTemporaryValues => false;

public override Guid Next(EntityEntry entry) => Guid.CreateVersion7();
public override Guid Next(EntityEntry entry) => Guid.NewGuid(); // Replace with compatible method
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment 'Replace with compatible method' indicates this is a temporary workaround. Consider implementing a proper GUID v7 generator for .NET 8 or documenting that this changes the GUID generation behavior from version 7 to version 4.

Copilot uses AI. Check for mistakes.
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ .. assemblies.Extract().Classes()
/// <summary>
/// </summary>
public static DbContextOptionsBuilder UseAutoDataSeeding(this DbContextOptionsBuilder @this,
params ICollection<Assembly> assemblies)
params Assembly[] assemblies)
{
ArgumentNullException.ThrowIfNull(@this);

if (assemblies.Count == 0)
if (assemblies.Length == 0)
{
var op = @this.GetOrCreateExtension();
assemblies = [.. op.Registrations.SelectMany(r => r.EntityAssemblies)];
Expand Down
2 changes: 1 addition & 1 deletion src/EfCore/DKNet.EfCore.Hooks/DKNet.EfCore.Hooks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion src/EfCore/DKNet.EfCore.Repos/DKNet.EfCore.Repos.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Authors>Steven Hoang</Authors>
<Authors>https://drunkcoding.net</Authors>
<Copyright>@2026 drunkcoding</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>-->
<LangVersion>default</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>-->
<LangVersion>default</LangVersion>
<Nullable>annotations</Nullable>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/EfCore/EfCore.Events.Tests/EfCore.Events.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>-->
<LangVersion>default</LangVersion>
<Nullable>annotations</Nullable>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/EfCore/EfCore.HookTests/EfCore.HookTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>-->
<LangVersion>default</LangVersion>
<Nullable>annotations</Nullable>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>-->
<LangVersion>default</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

Expand Down
182 changes: 182 additions & 0 deletions src/EfCore/EfCore.Repos.Tests/AndSpecificationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using DKNet.EfCore.Specifications;
using EfCore.Repos.Tests.TestEntities;
using Shouldly;

namespace EfCore.Repos.Tests;

/// <summary>
/// Tests for the AndSpecification class functionality
/// </summary>
public class AndSpecificationTests
{
[Fact]
public void Constructor_WithBothSpecificationsHavingFilters_ShouldCombineWithAnd()
{
// Arrange
var leftSpec = new TestSpecification();
leftSpec.AddTestFilter(u => u.FirstName == "John");

var rightSpec = new TestSpecification();
rightSpec.AddTestFilter(u => u.LastName == "Doe");

// Act
var andSpec = new AndSpecification<User>(leftSpec, rightSpec);

// Assert
andSpec.FilterQuery.ShouldNotBeNull();

// Test combined filter with matching entity
var matchingUser = new User("test") { FirstName = "John", LastName = "Doe" };
andSpec.Match(matchingUser).ShouldBeTrue();

// Test combined filter with non-matching entity (wrong first name)
var nonMatchingUser1 = new User("test") { FirstName = "Jane", LastName = "Doe" };
andSpec.Match(nonMatchingUser1).ShouldBeFalse();

// Test combined filter with non-matching entity (wrong last name)
var nonMatchingUser2 = new User("test") { FirstName = "John", LastName = "Smith" };
andSpec.Match(nonMatchingUser2).ShouldBeFalse();
}

[Fact]
public void Constructor_WithLeftSpecificationNull_ShouldUseRightSpecification()
{
// Arrange
var leftSpec = new TestSpecification(); // No filter
var rightSpec = new TestSpecification();
rightSpec.AddTestFilter(u => u.LastName == "Doe");

// Act
var andSpec = new AndSpecification<User>(leftSpec, rightSpec);

// Assert
andSpec.FilterQuery.ShouldNotBeNull();

var user = new User("test") { FirstName = "John", LastName = "Doe" };
andSpec.Match(user).ShouldBeTrue();

var user2 = new User("test") { FirstName = "John", LastName = "Smith" };
andSpec.Match(user2).ShouldBeFalse();
}

[Fact]
public void Constructor_WithRightSpecificationNull_ShouldUseLeftSpecification()
{
// Arrange
var leftSpec = new TestSpecification();
leftSpec.AddTestFilter(u => u.FirstName == "John");

var rightSpec = new TestSpecification(); // No filter

// Act
var andSpec = new AndSpecification<User>(leftSpec, rightSpec);

// Assert
andSpec.FilterQuery.ShouldNotBeNull();

var user = new User("test") { FirstName = "John", LastName = "Doe" };
andSpec.Match(user).ShouldBeTrue();

var user2 = new User("test") { FirstName = "Jane", LastName = "Doe" };
andSpec.Match(user2).ShouldBeFalse();
}

[Fact]
public void Constructor_WithBothSpecificationsNull_ShouldHaveNullFilter()
{
// Arrange
var leftSpec = new TestSpecification(); // No filter
var rightSpec = new TestSpecification(); // No filter

// Act
var andSpec = new AndSpecification<User>(leftSpec, rightSpec);

// Assert
andSpec.FilterQuery.ShouldBeNull();

var user = new User("test") { FirstName = "John", LastName = "Doe" };
andSpec.Match(user).ShouldBeFalse(); // Returns false when FilterQuery is null
}

[Fact]
public void Constructor_WithComplexExpressions_ShouldCombineCorrectly()
{
// Arrange
var leftSpec = new TestSpecification();
leftSpec.AddTestFilter(u => u.FirstName.StartsWith("J"));

var rightSpec = new TestSpecification();
rightSpec.AddTestFilter(u => u.LastName.Length > 3);

// Act
var andSpec = new AndSpecification<User>(leftSpec, rightSpec);

// Assert
andSpec.FilterQuery.ShouldNotBeNull();

// Test with user that matches both conditions
var matchingUser = new User("test") { FirstName = "John", LastName = "Smith" }; // J* and length > 3
andSpec.Match(matchingUser).ShouldBeTrue();

// Test with user that matches first but not second
var nonMatchingUser1 = new User("test") { FirstName = "John", LastName = "Do" }; // J* but length <= 3
andSpec.Match(nonMatchingUser1).ShouldBeFalse();

// Test with user that matches second but not first
var nonMatchingUser2 = new User("test") { FirstName = "Mike", LastName = "Johnson" }; // Not J* but length > 3
andSpec.Match(nonMatchingUser2).ShouldBeFalse();
}

[Fact]
public void Constructor_WithNestedAndSpecifications_ShouldWork()
{
// Arrange
var spec1 = new TestSpecification();
spec1.AddTestFilter(u => u.FirstName == "John");

var spec2 = new TestSpecification();
spec2.AddTestFilter(u => u.LastName == "Doe");

var spec3 = new TestSpecification();
spec3.AddTestFilter(u => u.FirstName.Length > 2);

var andSpec1 = new AndSpecification<User>(spec1, spec2);

// Act
var nestedAndSpec = new AndSpecification<User>(andSpec1, spec3);

// Assert
nestedAndSpec.FilterQuery.ShouldNotBeNull();

// Test with user that matches all three conditions
var matchingUser = new User("test") { FirstName = "John", LastName = "Doe" };
nestedAndSpec.Match(matchingUser).ShouldBeTrue();

// Test with user that doesn't match first condition
var nonMatchingUser = new User("test") { FirstName = "Jane", LastName = "Doe" };
nestedAndSpec.Match(nonMatchingUser).ShouldBeFalse();
}

[Fact]
public void Constructor_WithIdenticalSpecifications_ShouldWork()
{
// Arrange
var spec1 = new TestSpecification();
spec1.AddTestFilter(u => u.FirstName == "John");

var spec2 = new TestSpecification();
spec2.AddTestFilter(u => u.FirstName == "John");

// Act
var andSpec = new AndSpecification<User>(spec1, spec2);

// Assert
andSpec.FilterQuery.ShouldNotBeNull();

var matchingUser = new User("test") { FirstName = "John", LastName = "Doe" };
andSpec.Match(matchingUser).ShouldBeTrue();

var nonMatchingUser = new User("test") { FirstName = "Jane", LastName = "Doe" };
andSpec.Match(nonMatchingUser).ShouldBeFalse();
}
}
Loading
Loading