Skip to content

Commit

Permalink
Merge pull request #10 from alexmurari/dev
Browse files Browse the repository at this point in the history
Fix query parser not working with short name properties
  • Loading branch information
alexmurari authored Sep 29, 2020
2 parents 7303e3f + 0ca4ab4 commit 90c2810
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 142 deletions.
5 changes: 2 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>2.0.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Product>Exprelsior</Product>
<Authors>Alexandre Murari Junior (alexmurari)</Authors>
Expand All @@ -12,8 +12,7 @@
<PackageProjectUrl>https://github.com/alexmurari/Exprelsior/</PackageProjectUrl>
<!-- Keep package release notes section without indentation -->
<PackageReleaseNotes>
- Assemblies are strong-name signed
- Other minor code improvements
- Fixed query parser not working with short name properties.
</PackageReleaseNotes>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Exprelsior.Shared/Exprelsior.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageOutputPath>bin\$(Configuration)\Package</PackageOutputPath>
<Description>Shared functions library for Exprelsior, a .NET Standard lambda expression generator for creating dynamic predicates.</Description>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>C# .NET .netstandard</PackageTags>
<PackageTags>C# .NET .netstandard expression predicate expression-builder predicate-builder dynamic-predicate</PackageTags>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<SignAssembly>true</SignAssembly>
Expand Down
44 changes: 21 additions & 23 deletions Exprelsior.Shared/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public static class TypeExtensions
{
/// <summary>
/// The numeric types.
/// The numeric types.
/// </summary>
public static readonly Type[] NumericTypes =
{
Expand All @@ -24,11 +24,10 @@ public static class TypeExtensions
/// Returns a value indicating whether the provided type is a collection type.
/// </summary>
/// <remarks>
/// Although <see cref="string" /> implements <see cref="IEnumerable{T}" />, it is not considered a collection type by
/// this method.
/// Although <see cref="string" /> implements <see cref="IEnumerable{T}" />, it is not considered a collection type by this method.
/// </remarks>
/// <param name="type">The type to be checked.</param>
/// <returns>True if it is a collection type; otherwise, false.</returns>
/// <returns><c>True</c> if it is a collection type; otherwise, <c>false</c>.</returns>
public static bool IsCollection(this Type type)
{
if (type.IsString())
Expand All @@ -45,7 +44,7 @@ public static bool IsCollection(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a <see cref="DateTime" /> type; otherwise, false.
/// <c>True</c> if the type is a <see cref="DateTime" /> type; otherwise, <c>false</c>.
/// </returns>
public static bool IsDateTime(this Type type)
{
Expand All @@ -64,7 +63,7 @@ public static bool IsDateTime(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a <see cref="TimeSpan" /> type; otherwise, false.
/// <c>True</c> if the type is a <see cref="TimeSpan" /> type; otherwise, <c>false</c>.
/// </returns>
public static bool IsTimeSpan(this Type type)
{
Expand All @@ -86,10 +85,10 @@ public static bool IsTimeSpan(this Type type)
/// The type to be checked.
/// </param>
/// <param name="includeArrays">
/// Informs whether <see cref="Array"/> objects should be considered generic collection types by this method.
/// The value that indicates whether <see cref="Array"/> objects should be considered generic collection types by this method.
/// </param>
/// <returns>
/// True if the type is a generic collection; otherwise, false.
/// <c>True</c> if the type is a generic collection; otherwise, <c>false</c>.
/// </returns>
public static bool IsGenericCollection(this Type type, bool includeArrays = true)
{
Expand All @@ -101,8 +100,7 @@ public static bool IsGenericCollection(this Type type, bool includeArrays = true
}

/// <summary>
/// Returns a value indicating whether the provided type is a generic collection and the generic type parameter is the
/// same as the provided type.
/// Returns a value indicating whether the provided type is a generic collection and the generic type parameter is the same as the provided type.
/// </summary>
/// <remarks>
/// Although <see cref="string" /> implements <see cref="IEnumerable{T}" />, it is not considered a collection type by this method.
Expand All @@ -114,10 +112,10 @@ public static bool IsGenericCollection(this Type type, bool includeArrays = true
/// The generic type argument of the collection.
/// </param>
/// <param name="includeArrays">
/// Informs whether <see cref="Array"/> objects should be considered generic collection types by this method.
/// The value that indicates whether <see cref="Array"/> objects should be considered generic collection types by this method.
/// </param>
/// <returns>
/// True if the type is a generic collection of the provided generic type argument; otherwise, false.
/// <c>True</c> if the type is a generic collection of the provided generic type argument; otherwise, <c>false</c>.
/// </returns>
public static bool IsGenericCollection(this Type type, Type genericTypeArgument, bool includeArrays = true)
{
Expand All @@ -132,8 +130,7 @@ public static bool IsGenericCollection(this Type type, Type genericTypeArgument,
/// Returns a value indicating whether the provided type is a generic collection and the generic type parameter is included in he specified type list.
/// </summary>
/// <remarks>
/// Although <see cref="string" /> implements <see cref="IEnumerable{T}" />, it is not considered a collection type by
/// this method.
/// Although <see cref="string" /> implements <see cref="IEnumerable{T}" />, it is not considered a collection type by this method.
/// </remarks>
/// <param name="type">
/// The type to be checked.
Expand All @@ -142,10 +139,10 @@ public static bool IsGenericCollection(this Type type, Type genericTypeArgument,
/// The collection of generic type arguments of the collection.
/// </param>
/// <param name="includeArrays">
/// Informs whether <see cref="Array"/> objects should be considered generic collection types by this method.
/// The value that indicates whether <see cref="Array"/> objects should be considered generic collection types by this method.
/// </param>
/// <returns>
/// True if the type is a generic collection of the provided generic type argument; otherwise, false.
/// <c>True</c> if the type is a generic collection of the provided generic type argument; otherwise, <c>false</c>.
/// </returns>
public static bool IsGenericCollection(this Type type, Type[] genericTypeArguments, bool includeArrays = true)
{
Expand All @@ -163,7 +160,7 @@ public static bool IsGenericCollection(this Type type, Type[] genericTypeArgumen
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a non-generic <see cref="IList" />; otherwise, false.
/// <c>True</c> if the type is a non-generic <see cref="IList" />; otherwise, <c>false</c>.
/// </returns>
public static bool IsNonGenericIList(this Type type)
{
Expand All @@ -177,7 +174,7 @@ public static bool IsNonGenericIList(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a numeric type; otherwise, false.
/// <c>True</c> if the type is a numeric type; otherwise, <c>false</c>.
/// </returns>
public static bool IsNumeric(this Type type)
{
Expand All @@ -196,7 +193,7 @@ public static bool IsNumeric(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a <see cref="string"/> type; otherwise, false.
/// <c>True</c> if the type is a <see cref="string"/> type; otherwise, <c>false</c>.
/// </returns>
public static bool IsString(this Type type)
{
Expand All @@ -210,7 +207,7 @@ public static bool IsString(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a <see cref="char" /> type; otherwise, false.
/// <c>True</c> if the type is a <see cref="char" /> type; otherwise, <c>false</c>.
/// </returns>
public static bool IsChar(this Type type)
{
Expand All @@ -229,7 +226,7 @@ public static bool IsChar(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a <see cref="bool" /> type; otherwise, false.
/// <c>True</c> if the type is a <see cref="bool" /> type; otherwise, <c>false</c>.
/// </returns>
public static bool IsBoolean(this Type type)
{
Expand All @@ -248,7 +245,7 @@ public static bool IsBoolean(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a <see cref="Guid" /> type; otherwise, false.
/// <c>True</c> if the type is a <see cref="Guid" /> type; otherwise, <c>false</c>.
/// </returns>
public static bool IsGuid(this Type type)
{
Expand All @@ -267,7 +264,8 @@ public static bool IsGuid(this Type type)
/// The type to be checked.
/// </param>
/// <returns>
/// True if the type is a <see cref="Nullable{T}" /> type; otherwise, false.
/// A tuple consisting of a value indicating whether the provided type is a <see cref="Nullable{T}" /> type
/// and the type argument of the <see cref="Nullable{T}" /> representing the underlying type.
/// </returns>
public static (bool IsNullable, Type UnderlyingType) IsNullableType(this Type type)
{
Expand Down
12 changes: 6 additions & 6 deletions Exprelsior.Tests/Exprelsior.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<AssemblyVersion>1.0.0.0</AssemblyVersion>

<FileVersion>1.0.0.0</FileVersion>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>..\ExprelsiorKey.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down Expand Up @@ -35,10 +35,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="29.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Bogus" Version="31.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
32 changes: 32 additions & 0 deletions Exprelsior.Tests/QueryParser/QueryParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Exprelsior.Tests.QueryParser
{
using System.Linq;
using Xunit;

/// <summary>
/// Unit tests for the query parser.
/// </summary>
public class QueryParserTests
{
/// <summary>
/// Asserts that short name properties are correctly parsed by the query parser.
/// </summary>
/// <param name="propertyName">The property name to test.</param>
[Theory]
[InlineData("F")]
[InlineData("Fo")]
[InlineData("Foo")]
public void Assert_Short_Name_Properties_Are_Parsed_Correctly(string propertyName)
{
// Arrange
var query = $"eq('{propertyName}', '1')";

// Act
var queryElements = Exprelsior.DynamicQuery.Parser.QueryParser.ParseQuery(query).ToList();

// Assert
Assert.NotEmpty(queryElements);
Assert.Contains(queryElements, t => t.PropertyName == propertyName);
}
}
}
1 change: 0 additions & 1 deletion Exprelsior.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
ExprelsiorKey.pfx = ExprelsiorKey.pfx
icon.png = icon.png
Import-PfxCertificate.psm1 = Import-PfxCertificate.psm1
README.md = README.md
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion Exprelsior/DynamicQuery/Parser/QueryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal static class QueryParser
/// </remarks>
private static readonly Regex QueryElementsRegex =
new Regex(
@"((?<operator>[A-Za-z]{2,3})(?=(\s*\(\s*))|(?<=^[A-Za-z]{2,3}\s*\(\s*)'(?<property>(?!\.).[a-zA-Z][a-zA-Z0-9._]+)(?<!\.)'\s*(?=(,\s*)))|(?<=(^[a-zA-Z]{2,3}\s*\(\s*\'[a-zA-Z\.]+\'\s*\,\s*))'(?<value>.+?)'\s*(?=\))|((?:\[\s*|\G(?!\A))('(?<arrayValues>.+?)')(?:(?:\s*,\s*(?=[^\]]*?\]))|\s*\]))",
@"((?<operator>[A-Za-z]{2,3})(?=(\s*\(\s*))|(?<=^[A-Za-z]{2,3}\s*\(\s*)'(?<property>(?!\.).[a-zA-Z0-9._]*)(?<!\.)'\s*(?=(,\s*)))|(?<=(^[a-zA-Z]{2,3}\s*\(\s*\'[a-zA-Z\.]+\'\s*\,\s*))'(?<value>.+?)'\s*(?=\))|((?:\[\s*|\G(?!\A))('(?<arrayValues>.+?)')(?:(?:\s*,\s*(?=[^\]]*?\]))|\s*\]))",
RegexOptions.Compiled & RegexOptions.ExplicitCapture);

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion Exprelsior/Exprelsior.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageOutputPath>bin\$(Configuration)\Package</PackageOutputPath>
<Description>A .NET Standard lambda expression generator for creating dynamic predicates.</Description>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>C# .NET .netstandard expression predicate dynamicpredicates</PackageTags>
<PackageTags>C# .NET .netstandard expression predicate expression-builder predicate-builder dynamic-predicate</PackageTags>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -25,6 +25,14 @@
<ProjectReference Include="..\Exprelsior.Shared\Exprelsior.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>
Exprelsior.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100ed6ebae92a81ca8042974fc0424b278c77e37027c44a3093ba08da000462165d7d1f9f2cf6619d592af4c66f925f9a143395f8ddd981cbaeaeb2775db782b10c94fd77cb47da9bb488528fc24889eddd653bdf6d6a732a3629e388361e84a31fcf059dd1b7826433c49f69ff080f18cad84506fbffe50502e3d1786903f5f5b6
</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<None Include="..\icon.png" Pack="true" Visible="false" PackagePath="" />
<None Include="..\LICENSE" Pack="true" Visible="false" PackagePath="" />
Expand Down
Loading

0 comments on commit 90c2810

Please sign in to comment.