Skip to content

Commit

Permalink
Version 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bdongus committed Mar 22, 2024
1 parent c380497 commit 107a42e
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using idee5.Common;
using idee5.Globalization.Models;
using idee5.Globalization.Queries;
using idee5.Globalization.Repositories;

using Microsoft.EntityFrameworkCore;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -47,4 +45,4 @@ public async Task<IList<ResourceKey>> HandleAsync(GetResourceKeysForResourceSetQ
}).Distinct().ToListAsync(cancellationToken);
}
#endregion Public Methods
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using idee5.Common;
using idee5.Globalization.Models;
using idee5.Globalization.Queries;

using Microsoft.EntityFrameworkCore;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace idee5.Globalization.EFCore;

/// <summary>
/// The search resource keys for resource set query handler.
/// </summary>
public class SearchResourceKeysForResourceSetQueryHandler : IQueryHandlerAsync<SearchResourceKeysForResourceSetQuery, IList<ResourceKey>> {
#region Private Fields

private readonly GlobalizationDbContext _context;

#endregion Private Fields

#region Public Constructors

public SearchResourceKeysForResourceSetQueryHandler(GlobalizationDbContext context) => _context = context;

#endregion Public Constructors

#region Public Methods

/// <summary>
/// Query the resource ids in a resource set. Including all parlances.
/// </summary>
/// <param name="query">The query.</param>
/// <exception cref="ArgumentNullException"><paramref name="query"/> is <c>null</c>.</exception>
public async Task<IList<ResourceKey>> HandleAsync(SearchResourceKeysForResourceSetQuery query, CancellationToken cancellationToken = default) {
ArgumentNullException.ThrowIfNull(query);
return await _context.Resources.Where(Specifications.ContainsInResourceSet(query.ResourceSet, query.SearchValue)).Select(r => new ResourceKey() {
// just casting results in all records being read
ResourceSet = r.ResourceSet,
Id = r.Id,
Industry = r.Industry,
Customer = r.Customer
}).Distinct().ToListAsync(cancellationToken);
}
#endregion Public Methods
}
49 changes: 49 additions & 0 deletions idee5.Globalization.EFCore/SearchResourceKeysQueryHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using idee5.Common;
using idee5.Globalization.Models;
using idee5.Globalization.Queries;

using Microsoft.EntityFrameworkCore;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace idee5.Globalization.EFCore;

/// <summary>
/// The search resource keys query handler.
/// </summary>
public class SearchResourceKeysQueryHandler : IQueryHandlerAsync<SearchResourceKeysQuery, IList<ResourceKey>> {
#region Private Fields

private readonly GlobalizationDbContext _context;

#endregion Private Fields

#region Public Constructors

public SearchResourceKeysQueryHandler(GlobalizationDbContext context) => _context = context;

#endregion Public Constructors

#region Public Methods

/// <summary>
/// Query the resource ids in a resource set. Including all parlances.
/// </summary>
/// <param name="query">The query.</param>
/// <exception cref="ArgumentNullException"><paramref name="query"/> is <c>null</c>.</exception>
public async Task<IList<ResourceKey>> HandleAsync(SearchResourceKeysQuery query, CancellationToken cancellationToken = default) {
ArgumentNullException.ThrowIfNull(query);
return await _context.Resources.Where(Specifications.Contains(query.SearchValue)).Select(r => new ResourceKey() {
// just casting results in all records being read
ResourceSet = r.ResourceSet,
Id = r.Id,
Industry = r.Industry,
Customer = r.Customer
}).Distinct().ToListAsync(cancellationToken);
}
#endregion Public Methods
}
4 changes: 2 additions & 2 deletions idee5.Globalization.EFCore/idee5.Globalization.EFCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<Description>Entity Framework Core context provider for idee5.Globalization.</Description>
<Copyright>© idee5 2022-2024</Copyright>
<PackageTags>idee5, Globalization, Localization, EFCore</PackageTags>
<PackageReleaseNotes>Added get resource keys query</PackageReleaseNotes>
<Version>3.2.1</Version>
<PackageReleaseNotes>Search queries added</PackageReleaseNotes>
<Version>3.3</Version>
<Authors>Bernd Dongus</Authors>
<Nullable>enable</Nullable>
<Title>EF core data layer for idee5.Globalization</Title>
Expand Down
2 changes: 2 additions & 0 deletions idee5.Globalization.Test/ImportResoucesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public async Task CanImportResxFileAsync() {
var inputHandler = new ResxFileInputHandler();
var outputHandler = new DataAnnotationValidationCommandHandlerAsync<ImportResourcesCommand>(recursiveAnnotationsValidator, validationReporter, handler);
var converter = new DataConverterAsync<ResxFileInputHandlerQuery, ImportResourcesCommand>(inputHandler, outputHandler);

// TODO: var converter = new AsyncDataImporter<ResxFileInputHandlerQuery, ImportResourcesCommand, NoCleanupCommand>(inputHandler, outputHandler,new NoCleanupCommandHandler());
var query = new ResxFileInputHandlerQuery("", "", null, null, null) {
Path = "ImportTes.resx",
ResourceSet = "testset",
Expand Down
49 changes: 49 additions & 0 deletions idee5.Globalization.Test/QueryWithSQLiteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,55 @@ public async Task CanGetResourceKeysForResoureSet() {
var query = new GetResourceKeysForResourceSetQuery(Constants.CommonTerms);
var result = await qh.HandleAsync(query, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.AreEqual(4, result.Count);
}
[TestMethod]
public async Task CanFindResourceKeysInResourceSetByValue() {
// Arrange
var qh = new SearchResourceKeysForResourceSetQueryHandler(context);

// Act
var query = new SearchResourceKeysForResourceSetQuery(Constants.CommonTerms, "May");
var result = await qh.HandleAsync(query, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.AreEqual(4, result.Count);
}
[TestMethod]
public async Task CanFindResourceKeysInResourceSetByCustomer() {
// Arrange
var qh = new SearchResourceKeysForResourceSetQueryHandler(context);

// Act
var query = new SearchResourceKeysForResourceSetQuery(Constants.CommonTerms, "idee5");
var result = await qh.HandleAsync(query, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.AreEqual(2, result.Count);
}
[TestMethod]
public async Task CanFindValueInResourceKeys() {
// Arrange
var qh = new SearchResourceKeysQueryHandler(context);

// Act
var query = new SearchResourceKeysQuery("May");
var result = await qh.HandleAsync(query, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.AreEqual(4, result.Count);
}

[TestMethod]
public async Task CanFindResourceSetInResourceKeys() {
// Arrange
var qh = new SearchResourceKeysQueryHandler(context);

// Act
var query = new SearchResourceKeysQuery("Terms");
var result = await qh.HandleAsync(query, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.AreEqual(4, result.Count);
}
Expand Down
2 changes: 1 addition & 1 deletion idee5.Globalization.Test/idee5.Globalization.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="idee5.Common.Data" version="2.1.1" />
<PackageReference Include="idee5.Common.Data" version="2.2.0" />
<PackageReference Include="NSpecifications" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ namespace idee5.Globalization.Queries;
/// <summary>
/// The get the resource keys for a resource set query.
/// </summary>
/// <param name="ResourceSet">Resource set to get the keys for</param>
public record GetResourceKeysForResourceSetQuery(string ResourceSet) : IQuery<IList<ResourceKey>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using idee5.Common;
using idee5.Globalization.Models;

using System.Collections.Generic;

namespace idee5.Globalization.Queries;

/// <summary>
/// Search a value in a resource set query.
/// </summary>
/// <param name="ResourceSet">Resource set to search in</param>
/// <param name="SearchValue">Value to search for</param>
public record SearchResourceKeysForResourceSetQuery(string ResourceSet, string SearchValue) : IQuery<IList<ResourceKey>>;
12 changes: 12 additions & 0 deletions idee5.Globalization/Queries/SearchResourceKeysQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using idee5.Common;
using idee5.Globalization.Models;

using System.Collections.Generic;

namespace idee5.Globalization.Queries;

/// <summary>
/// Search a value in all resource sets query.
/// </summary>
/// <param name="SearchValue">Value to search for</param>
public record SearchResourceKeysQuery(string SearchValue) : IQuery<IList<ResourceKey>>;
2 changes: 1 addition & 1 deletion idee5.Globalization/Repositories/AResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class AResourceRepository : ACompositeKeyRepository<Resource>, I
#region Public Methods

/// <inheritdoc/>
public abstract Task<List<string>> SearchResourceSetsAsync(string contains, CancellationToken cancellationToken = default);
public abstract Task<List<string>> SearchResourceSetsAsync(string searchValue, CancellationToken cancellationToken = default);

/// <inheritdoc />
public override async Task UpdateOrAddAsync(Resource resource, CancellationToken cancellationToken = default) {
Expand Down
4 changes: 2 additions & 2 deletions idee5.Globalization/Repositories/IResourceQueryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IResourceQueryRepository : IQueryRepository<Resource> {
/// <summary>
/// Search resource sets containing a given string
/// </summary>
/// <param contains="contains">String to search for</param>
/// <param name="searchValue">String to search for</param>
/// <returns>List of found resource sets</returns>
Task<List<string>> SearchResourceSetsAsync(string contains, CancellationToken cancellationToken = default);
Task<List<string>> SearchResourceSetsAsync(string searchValue, CancellationToken cancellationToken = default);
}
35 changes: 35 additions & 0 deletions idee5.Globalization/Specifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,40 @@ public static class Specifications {
/// <returns>The new <see cref="Spec{Resource}"/></returns>
public static ASpec<Resource> ResourceId(string id) => new Spec<Resource>(r => r.Id == id);

/// <summary>
/// Search the for a value in the resource set property
/// </summary>
/// <param name="searchValue">The search value.</param>
/// <returns>An ASpec</returns>
public static ASpec<Resource> ResourceSetContains(string searchValue) => new Spec<Resource>(r =>r.ResourceSet.Contains(searchValue));

/// <summary>
/// Search the for a value in the resource set, id, value,industry, customer or comment
/// </summary>
/// <param name="searchValue">The search value.</param>
/// <returns>An ASpec</returns>
public static ASpec<Resource> Contains(string searchValue) => new Spec<Resource>(r =>
r.ResourceSet.Contains(searchValue)
|| r.Id.Contains(searchValue)
|| r.Value.Contains(searchValue)
|| (r.Industry != null && r.Industry.Contains(searchValue))
|| (r.Customer != null && r.Customer.Contains(searchValue))
|| (r.Comment !=null && r.Comment.Contains(searchValue))
);

/// <summary>
/// Search the for a value in the resource set, id, value,industry, customer or comment
/// </summary>
/// <param name="resourceSet">Resource set to search in.</param>
/// <param name="searchValue">The search value.</param>
/// <returns>An ASpec</returns>
public static ASpec<Resource> ContainsInResourceSet(string resourceSet, string searchValue) => new Spec<Resource>(r =>
r.ResourceSet == resourceSet
&& (r.Id.Contains(searchValue)
|| r.Value.Contains(searchValue)
|| (r.Industry != null && r.Industry.Contains(searchValue))
|| (r.Customer != null && r.Customer.Contains(searchValue))
|| (r.Comment !=null && r.Comment.Contains(searchValue)))
);
#endregion Public Methods
}
6 changes: 3 additions & 3 deletions idee5.Globalization/idee5.Globalization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<Description>Globalization extensions. Enables database support for localization resources and parlances for industries and customers..</Description>
<Company>idee5</Company>
<Copyright>© idee5 2016 - 2024</Copyright>
<Version>3.2.1</Version>
<Version>3.3</Version>
<PackageTags>idee5, Globalization, Localization</PackageTags>
<PackageReleaseNotes>Removed own implementation of the resx stuff</PackageReleaseNotes>
<PackageReleaseNotes>Search queries added</PackageReleaseNotes>
<Nullable>enable</Nullable>
<Authors>Bernd Dongus</Authors>
<Title>Globalization tool for parlances for industries and customers</Title>
Expand All @@ -42,7 +42,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="idee5.Common" Version="4.0.0" />
<PackageReference Include="idee5.Common.Data" Version="2.1.1" />
<PackageReference Include="idee5.Common.Data" Version="2.2.0" />
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit 107a42e

Please sign in to comment.