Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from PandaTechAM/development
Browse files Browse the repository at this point in the history
Added BaseConverter supported characters check before conversion
  • Loading branch information
ruboarm authored Apr 24, 2024
2 parents 6e9d745 + d6e21b8 commit 92346bb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/EFCoreQueryMagic/EFCoreQueryMagic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>PandaTech</Authors>
<Copyright>MIT</Copyright>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<PackageId>Pandatech.EFCoreQueryMagic</PackageId>
<Title>Pandatech.EFCoreQueryMagic: Dynamic Query and Filter Generator for EF Core</Title>
<Description>Unlock the full potential of your Entity Framework Core applications with Pandatech.EFCoreQueryMagic. This innovative package empowers developers to seamlessly create dynamic, complex queries and filters for SQL tables without diving deep into the intricacies of LINQ or manual query construction. Designed to enhance productivity and maintainability, EFCoreQueryMagic automates the translation of front-end filter requests into optimized, ready-to-execute EF Core queries. Embrace the magic of streamlined data retrieval and manipulation, and elevate your applications to new heights of efficiency and performance.</Description>
Expand Down
11 changes: 11 additions & 0 deletions src/EFCoreQueryMagic/Helpers/PropertyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq.Expressions;
using System.Text.Json;
using BaseConverter;
using EFCoreQueryMagic.Attributes;
using EFCoreQueryMagic.Converters;
using EFCoreQueryMagic.Dto;
Expand Down Expand Up @@ -52,6 +53,16 @@ public static List<T> GetValues<T>(this FilterDto filter, MappedToPropertyAttrib
typeof(PropertyHelper).GetMethod("FromJsonElement")!.MakeGenericMethod(fromJsonElementType);
var val = fromJsonElementMethod.Invoke(null, [value, propertyAttribute])!;

// Check supported characters for Base Converter
if (converter is FilterPandaBaseConverter)
{
var base36Chars = PandaBaseConverter.Base36Chars;
if (!base36Chars.Contains(val.ToString()!))
{
throw new UnsupportedValueException($"Property {filter.PropertyName} has unsupported value");
}
}

var valConverted = method.Invoke(converter, [val])!;

list.Add((T)valConverted);
Expand Down
22 changes: 22 additions & 0 deletions test/EFCoreQueryMagic.Test/FilterTests/LongTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BaseConverter;
using EFCoreQueryMagic.Dto;
using EFCoreQueryMagic.Enums;
using EFCoreQueryMagic.Exceptions;
using EFCoreQueryMagic.Extensions;
using EFCoreQueryMagic.Test.EntityFilters;
using EFCoreQueryMagic.Test.Infrastructure;
Expand Down Expand Up @@ -38,4 +39,25 @@ public void TestEmptyValues()

query.Should().Equal(result);
}

[Fact]
public void TestBaseConverterWithWrongCharacter()
{
var set = _context.Orders;

var qString = new GetDataRequest
{
Filters =
[
new FilterDto
{
Values = ["ա"],
ComparisonType = ComparisonType.Equal,
PropertyName = nameof(OrderFilter.Id)
}
]
};

Assert.Throws<UnsupportedValueException>(() => set.ApplyFilters(qString.Filters));
}
}
2 changes: 1 addition & 1 deletion test/EFCoreQueryMagic.Test/Infrastructure/TestDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestDbContext(DbContextOptions<TestDbContext> options)
public static TestDbContext CreateNewInMemoryContext()
{
var options = new DbContextOptionsBuilder<TestDbContext>()
.UseNpgsql("Host=localhost;Database=filter_tests;Username=postgres;Password=root")
.UseNpgsql("Host=localhost;Database=filter_tests;Username=test;Password=test")
// .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Use a unique name for the database to avoid conflicts between tests
.Options;

Expand Down

0 comments on commit 92346bb

Please sign in to comment.