From c6794c3cb0ba6e15c63b9dcf374bfc8ce0806eb3 Mon Sep 17 00:00:00 2001 From: Yuriy Durov Date: Fri, 15 Sep 2023 16:15:28 +0400 Subject: [PATCH] Prerelease-0.1.0 (#2) * Split WithEndpoint/WithIdEndpoint extensions * Add parameters to WithIdEndpoint * Add parameters to GetIdEndpoint * Rename project * Update namespaces * Enable Complex Requests --- .github/workflows/Publish Communicator.yml | 39 ------------ .github/workflows/Publish Flex.Net.yml | 39 ++++++++++++ Communicator.sln => Flex.Net.sln | 10 ++-- .../Extensions/AddEntityExtension.cs | 6 +- ...ommunicatorRestServiceBuilderExtensions.cs | 2 +- .../Extensions/UsingRestExtension.cs | 5 +- .../Extensions/WithEndpointExtension.cs | 20 +++++++ .../Extensions/WithIdEndpointExtension.cs} | 32 +++++----- .../Flex.Net.REST.csproj} | 14 ++--- .../ICommunicatorRestEntityBuilder.cs | 2 +- .../ICommunicatorRestServiceBuilder.cs | 2 +- .../Models/CommunicatorRestEntityBuilder.cs | 2 +- .../Models/CommunicatorRestEntityContext.cs | 45 ++++++++------ .../Models/CommunicatorRestEntityOptions.cs | 12 ++-- .../Models/CommunicatorRestServiceBuilder.cs | 2 +- .../Models/CommunicatorRestServiceOptions.cs | 2 +- .../Models/CommunicatorRestServiceProvider.cs | 2 +- .../Utility/RequestParameterParsingUtility.cs | 52 ++++++++++++++++ .../Extensions/AddCommunicatorExtension.cs | 6 +- .../Extensions/AddServiceExtension.cs | 4 +- .../Flex.Net.csproj} | 16 ++--- .../Interfaces/ICommunicationContext.cs | 12 ++-- .../Interfaces/ICommunicatorBuilder.cs | 2 +- .../Interfaces/ICommunicatorEntityBuilder.cs | 2 +- .../Interfaces/ICommunicatorServiceBuilder.cs | 2 +- .../Interfaces/ICommunicatorServiceFactory.cs | 2 +- .../ICommunicatorServicePreBuilder.cs | 2 +- .../ICommunicatorServiceProvider.cs | 2 +- .../Models/CommunicationContext.cs | 2 +- .../Models/CommunicatorBuilder.cs | 2 +- .../Models/CommunicatorEntitySignature.cs | 2 +- .../Models/CommunicatorServiceFactory.cs | 2 +- .../Models/CommunicatorServicePreBuilder.cs | 2 +- .../Flex.Net.REST.Tests.csproj} | 4 +- .../MockedRestServiceTests.cs | 60 ++++++++++++++++++- .../MockedService/MockedService.cs | 4 +- .../MockedService/TestEntity.cs | 2 +- .../MockedService/TestEntityContext.cs | 2 +- .../ServiceRegistrationTests.cs | 2 +- .../Flex.Net.Tests.csproj} | 4 +- .../ServiceRegistrationTests.cs | 3 +- 41 files changed, 279 insertions(+), 150 deletions(-) delete mode 100644 .github/workflows/Publish Communicator.yml create mode 100644 .github/workflows/Publish Flex.Net.yml rename Communicator.sln => Flex.Net.sln (78%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Extensions/AddEntityExtension.cs (94%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Extensions/ICommunicatorRestServiceBuilderExtensions.cs (94%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Extensions/UsingRestExtension.cs (87%) create mode 100644 src/Flex.Net.REST/Extensions/WithEndpointExtension.cs rename src/{BitzArt.Communicator.REST/Extensions/ICommunicatorRestEntityBuilderExtensions.cs => Flex.Net.REST/Extensions/WithIdEndpointExtension.cs} (66%) rename src/{BitzArt.Communicator.REST/BitzArt.Communicator.REST.csproj => Flex.Net.REST/Flex.Net.REST.csproj} (54%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Interfaces/ICommunicatorRestEntityBuilder.cs (92%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Interfaces/ICommunicatorRestServiceBuilder.cs (86%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Models/CommunicatorRestEntityBuilder.cs (97%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Models/CommunicatorRestEntityContext.cs (76%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Models/CommunicatorRestEntityOptions.cs (64%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Models/CommunicatorRestServiceBuilder.cs (96%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Models/CommunicatorRestServiceOptions.cs (90%) rename src/{BitzArt.Communicator.REST => Flex.Net.REST}/Models/CommunicatorRestServiceProvider.cs (98%) create mode 100644 src/Flex.Net.REST/Utility/RequestParameterParsingUtility.cs rename src/{BitzArt.Communicator => Flex.Net}/Extensions/AddCommunicatorExtension.cs (86%) rename src/{BitzArt.Communicator => Flex.Net}/Extensions/AddServiceExtension.cs (84%) rename src/{BitzArt.Communicator/BitzArt.Communicator.csproj => Flex.Net/Flex.Net.csproj} (69%) rename src/{BitzArt.Communicator => Flex.Net}/Interfaces/ICommunicationContext.cs (63%) rename src/{BitzArt.Communicator => Flex.Net}/Interfaces/ICommunicatorBuilder.cs (86%) rename src/{BitzArt.Communicator => Flex.Net}/Interfaces/ICommunicatorEntityBuilder.cs (69%) rename src/{BitzArt.Communicator => Flex.Net}/Interfaces/ICommunicatorServiceBuilder.cs (89%) rename src/{BitzArt.Communicator => Flex.Net}/Interfaces/ICommunicatorServiceFactory.cs (92%) rename src/{BitzArt.Communicator => Flex.Net}/Interfaces/ICommunicatorServicePreBuilder.cs (88%) rename src/{BitzArt.Communicator => Flex.Net}/Interfaces/ICommunicatorServiceProvider.cs (94%) rename src/{BitzArt.Communicator => Flex.Net}/Models/CommunicationContext.cs (95%) rename src/{BitzArt.Communicator => Flex.Net}/Models/CommunicatorBuilder.cs (92%) rename src/{BitzArt.Communicator => Flex.Net}/Models/CommunicatorEntitySignature.cs (70%) rename src/{BitzArt.Communicator => Flex.Net}/Models/CommunicatorServiceFactory.cs (97%) rename src/{BitzArt.Communicator => Flex.Net}/Models/CommunicatorServicePreBuilder.cs (93%) rename tests/{BitzArt.Communicator.REST.Tests/BitzArt.Communicator.REST.Tests.csproj => Flex.Net.REST.Tests/Flex.Net.REST.Tests.csproj} (87%) rename tests/{BitzArt.Communicator.REST.Tests => Flex.Net.REST.Tests}/MockedRestServiceTests.cs (63%) rename tests/{BitzArt.Communicator.REST.Tests => Flex.Net.REST.Tests}/MockedService/MockedService.cs (86%) rename tests/{BitzArt.Communicator.REST.Tests => Flex.Net.REST.Tests}/MockedService/TestEntity.cs (95%) rename tests/{BitzArt.Communicator.REST.Tests => Flex.Net.REST.Tests}/MockedService/TestEntityContext.cs (95%) rename tests/{BitzArt.Communicator.REST.Tests => Flex.Net.REST.Tests}/ServiceRegistrationTests.cs (99%) rename tests/{BitzArt.Communicator.Tests/BitzArt.Communicator.Tests.csproj => Flex.Net.Tests/Flex.Net.Tests.csproj} (87%) rename tests/{BitzArt.Communicator.Tests => Flex.Net.Tests}/ServiceRegistrationTests.cs (95%) diff --git a/.github/workflows/Publish Communicator.yml b/.github/workflows/Publish Communicator.yml deleted file mode 100644 index 4443926..0000000 --- a/.github/workflows/Publish Communicator.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Release Communicator - -on: - repository_dispatch: - push: - tags: - - "Communicator-v[0-9]+.[0-9]+.[0-9]+*" - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NUGET_APIKEY: ${{ secrets.NUGET_APIKEY}} - -jobs: - - Communicator: - name: Communicator - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Verify commit - run: | - git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* - git branch --remote --contains | grep origin/main - - - name: Set version - run: echo "VERSION=${GITHUB_REF/refs\/tags\/Communicator-v/}" >> $GITHUB_ENV - - - name: Build - run: | - dotnet build Communicator.sln --configuration Release /p:Version=${VERSION} - dotnet pack Communicator.sln --configuration Release /p:Version=${VERSION} --no-build --output . - - - name: Push - run: | - dotnet nuget push BitzArt.Communicator.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY} - dotnet nuget push BitzArt.Communicator.REST.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY} diff --git a/.github/workflows/Publish Flex.Net.yml b/.github/workflows/Publish Flex.Net.yml new file mode 100644 index 0000000..ee2acdb --- /dev/null +++ b/.github/workflows/Publish Flex.Net.yml @@ -0,0 +1,39 @@ +name: Release + +on: + repository_dispatch: + push: + tags: + - "Flex.Net-v[0-9]+.[0-9]+.[0-9]+*" + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NUGET_APIKEY: ${{ secrets.NUGET_APIKEY}} + +jobs: + + Release: + name: Release + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Verify commit + run: | + git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* + git branch --remote --contains | grep origin/main + + - name: Set version + run: echo "VERSION=${GITHUB_REF/refs\/tags\/Flex.Net-v/}" >> $GITHUB_ENV + + - name: Build + run: | + dotnet build Flex.Net.sln --configuration Release /p:Version=${VERSION} + dotnet pack Flex.Net.sln --configuration Release /p:Version=${VERSION} --no-build --output . + + - name: Push + run: | + dotnet nuget push Flex.Net.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY} + dotnet nuget push Flex.Net.REST.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY} diff --git a/Communicator.sln b/Flex.Net.sln similarity index 78% rename from Communicator.sln rename to Flex.Net.sln index 88faf70..ae48a03 100644 --- a/Communicator.sln +++ b/Flex.Net.sln @@ -3,17 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitzArt.Communicator", "src\BitzArt.Communicator\BitzArt.Communicator.csproj", "{FE9CED3F-83D8-43DA-BB05-93F5807F746E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flex.Net", "src\Flex.Net\Flex.Net.csproj", "{FE9CED3F-83D8-43DA-BB05-93F5807F746E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitzArt.Communicator.REST", "src\BitzArt.Communicator.REST\BitzArt.Communicator.REST.csproj", "{E78BC020-AC54-4F92-8628-14EE6FF9EDBF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flex.Net.REST", "src\Flex.Net.REST\Flex.Net.REST.csproj", "{E78BC020-AC54-4F92-8628-14EE6FF9EDBF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{A3976FBB-F37A-4468-955D-8B2FCC79ACD0}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A0FAE66D-5574-463E-8723-E28ECEE565EE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitzArt.Communicator.Tests", "tests\BitzArt.Communicator.Tests\BitzArt.Communicator.Tests.csproj", "{AEA2C975-E99C-4E44-B121-0CF3D4956732}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flex.Net.Tests", "tests\Flex.Net.Tests\Flex.Net.Tests.csproj", "{AEA2C975-E99C-4E44-B121-0CF3D4956732}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.Communicator.REST.Tests", "tests\BitzArt.Communicator.REST.Tests\BitzArt.Communicator.REST.Tests.csproj", "{6A90BCF4-FB3B-4B4A-A992-3D288972B4AF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flex.Net.REST.Tests", "tests\Flex.Net.REST.Tests\Flex.Net.REST.Tests.csproj", "{6A90BCF4-FB3B-4B4A-A992-3D288972B4AF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{1CF88BCF-544C-463E-A639-594ADE0A9F15}" ProjectSection(SolutionItems) = preProject @@ -22,8 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{1CF8 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ABC1CAE6-C4A2-42AB-8F24-9A32299CC512}" ProjectSection(SolutionItems) = preProject - .github\workflows\Publish Communicator.yml = .github\workflows\Publish Communicator.yml .github\workflows\Tests.yml = .github\workflows\Tests.yml + .github\workflows\Publish Flex.Net.yml = .github\workflows\Publish Flex.Net.yml EndProjectSection EndProject Global diff --git a/src/BitzArt.Communicator.REST/Extensions/AddEntityExtension.cs b/src/Flex.Net.REST/Extensions/AddEntityExtension.cs similarity index 94% rename from src/BitzArt.Communicator.REST/Extensions/AddEntityExtension.cs rename to src/Flex.Net.REST/Extensions/AddEntityExtension.cs index d4b693c..1106c1f 100644 --- a/src/BitzArt.Communicator.REST/Extensions/AddEntityExtension.cs +++ b/src/Flex.Net.REST/Extensions/AddEntityExtension.cs @@ -1,8 +1,6 @@ -using BitzArt.Communicator; -using Microsoft.Extensions.DependencyInjection; -using System.Net; +using Microsoft.Extensions.DependencyInjection; -namespace BitzArt; +namespace Flex; public static class AddEntityExtension { diff --git a/src/BitzArt.Communicator.REST/Extensions/ICommunicatorRestServiceBuilderExtensions.cs b/src/Flex.Net.REST/Extensions/ICommunicatorRestServiceBuilderExtensions.cs similarity index 94% rename from src/BitzArt.Communicator.REST/Extensions/ICommunicatorRestServiceBuilderExtensions.cs rename to src/Flex.Net.REST/Extensions/ICommunicatorRestServiceBuilderExtensions.cs index 816a9c1..3090959 100644 --- a/src/BitzArt.Communicator.REST/Extensions/ICommunicatorRestServiceBuilderExtensions.cs +++ b/src/Flex.Net.REST/Extensions/ICommunicatorRestServiceBuilderExtensions.cs @@ -1,6 +1,6 @@ using System.Text.Json; -namespace BitzArt.Communicator; +namespace Flex; public static class ICommunicatorRestServiceBuilderExtensions { diff --git a/src/BitzArt.Communicator.REST/Extensions/UsingRestExtension.cs b/src/Flex.Net.REST/Extensions/UsingRestExtension.cs similarity index 87% rename from src/BitzArt.Communicator.REST/Extensions/UsingRestExtension.cs rename to src/Flex.Net.REST/Extensions/UsingRestExtension.cs index e205c3b..40e9f72 100644 --- a/src/BitzArt.Communicator.REST/Extensions/UsingRestExtension.cs +++ b/src/Flex.Net.REST/Extensions/UsingRestExtension.cs @@ -1,7 +1,6 @@ -using BitzArt.Communicator; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; -namespace BitzArt; +namespace Flex; public static class UsingRestExtension { diff --git a/src/Flex.Net.REST/Extensions/WithEndpointExtension.cs b/src/Flex.Net.REST/Extensions/WithEndpointExtension.cs new file mode 100644 index 0000000..fbba44a --- /dev/null +++ b/src/Flex.Net.REST/Extensions/WithEndpointExtension.cs @@ -0,0 +1,20 @@ +namespace Flex; + +public static class WithEndpointExtension +{ + public static ICommunicatorRestEntityBuilder WithEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) + where TEntity : class + { + builder.EntityOptions.Endpoint = endpoint; + + return builder; + } + + public static ICommunicatorRestEntityBuilder WithEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) + where TEntity : class + { + builder.EntityOptions.Endpoint = endpoint; + + return builder; + } +} diff --git a/src/BitzArt.Communicator.REST/Extensions/ICommunicatorRestEntityBuilderExtensions.cs b/src/Flex.Net.REST/Extensions/WithIdEndpointExtension.cs similarity index 66% rename from src/BitzArt.Communicator.REST/Extensions/ICommunicatorRestEntityBuilderExtensions.cs rename to src/Flex.Net.REST/Extensions/WithIdEndpointExtension.cs index f2d7a1e..f687104 100644 --- a/src/BitzArt.Communicator.REST/Extensions/ICommunicatorRestEntityBuilderExtensions.cs +++ b/src/Flex.Net.REST/Extensions/WithIdEndpointExtension.cs @@ -1,56 +1,56 @@ -namespace BitzArt.Communicator; +namespace Flex; -public static class ICommunicatorRestEntityBuilderExtensions +public static class WithIdEndpointExtension { - public static ICommunicatorRestEntityBuilder WithEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) where TEntity : class { - builder.EntityOptions.Endpoint = endpoint; + builder.EntityOptions.GetIdEndpointAction = (key, parameters) => endpoint; return builder; } - public static ICommunicatorRestEntityBuilder WithEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) where TEntity : class { - builder.EntityOptions.Endpoint = endpoint; + builder.EntityOptions.GetIdEndpointAction = (key, parameters) => endpoint; return builder; } - public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) where TEntity : class { - builder.EntityOptions.GetIdEndpointAction = (key) => endpoint; + builder.EntityOptions.GetIdEndpointAction = (key, parameters) => getEndpoint(); return builder; } - public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, string endpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) where TEntity : class { - builder.EntityOptions.GetIdEndpointAction = (key) => endpoint; + builder.EntityOptions.GetIdEndpointAction = (key, parameters) => getEndpoint(); return builder; } - public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) where TEntity : class { - builder.EntityOptions.GetIdEndpointAction = (key) => getEndpoint(); + builder.EntityOptions.GetIdEndpointAction = (key, parameters) => getEndpoint(key); return builder; } - public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) where TEntity : class { - builder.EntityOptions.GetIdEndpointAction = (key) => getEndpoint(); + builder.EntityOptions.GetIdEndpointAction = (key, parameters) => getEndpoint(key); return builder; } - public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) where TEntity : class { builder.EntityOptions.GetIdEndpointAction = getEndpoint; @@ -58,7 +58,7 @@ public static ICommunicatorRestEntityBuilder WithIdEndpoint(th return builder; } - public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) + public static ICommunicatorRestEntityBuilder WithIdEndpoint(this ICommunicatorRestEntityBuilder builder, Func getEndpoint) where TEntity : class { builder.EntityOptions.GetIdEndpointAction = getEndpoint; diff --git a/src/BitzArt.Communicator.REST/BitzArt.Communicator.REST.csproj b/src/Flex.Net.REST/Flex.Net.REST.csproj similarity index 54% rename from src/BitzArt.Communicator.REST/BitzArt.Communicator.REST.csproj rename to src/Flex.Net.REST/Flex.Net.REST.csproj index cdf0406..902b721 100644 --- a/src/BitzArt.Communicator.REST/BitzArt.Communicator.REST.csproj +++ b/src/Flex.Net.REST/Flex.Net.REST.csproj @@ -4,15 +4,15 @@ net7.0 enable enable - BitzArt.Communicator + Flex - BitzArt.Communicator.REST + Flex.Net.Rest BitzArt - Communicator's default RESTful client implementation + Flex.Net - REST Api client implementation MIT git - https://github.com/BitzArt/Communicator - https://github.com/BitzArt/Communicator + https://github.com/BitzArt/Flex.Net + https://github.com/BitzArt/Flex.Net @@ -20,12 +20,12 @@ - + - <_Parameter1>BitzArt.Communicator.REST.Tests + <_Parameter1>Flex.Net.REST.Tests diff --git a/src/BitzArt.Communicator.REST/Interfaces/ICommunicatorRestEntityBuilder.cs b/src/Flex.Net.REST/Interfaces/ICommunicatorRestEntityBuilder.cs similarity index 92% rename from src/BitzArt.Communicator.REST/Interfaces/ICommunicatorRestEntityBuilder.cs rename to src/Flex.Net.REST/Interfaces/ICommunicatorRestEntityBuilder.cs index 3d09686..36e840b 100644 --- a/src/BitzArt.Communicator.REST/Interfaces/ICommunicatorRestEntityBuilder.cs +++ b/src/Flex.Net.REST/Interfaces/ICommunicatorRestEntityBuilder.cs @@ -1,4 +1,4 @@ -namespace BitzArt.Communicator; +namespace Flex; public interface ICommunicatorRestEntityBuilder : ICommunicatorEntityBuilder, ICommunicatorRestServiceBuilder where TEntity : class diff --git a/src/BitzArt.Communicator.REST/Interfaces/ICommunicatorRestServiceBuilder.cs b/src/Flex.Net.REST/Interfaces/ICommunicatorRestServiceBuilder.cs similarity index 86% rename from src/BitzArt.Communicator.REST/Interfaces/ICommunicatorRestServiceBuilder.cs rename to src/Flex.Net.REST/Interfaces/ICommunicatorRestServiceBuilder.cs index 48be5a4..8b7735c 100644 --- a/src/BitzArt.Communicator.REST/Interfaces/ICommunicatorRestServiceBuilder.cs +++ b/src/Flex.Net.REST/Interfaces/ICommunicatorRestServiceBuilder.cs @@ -1,4 +1,4 @@ -namespace BitzArt.Communicator; +namespace Flex; public interface ICommunicatorRestServiceBuilder : ICommunicatorServiceBuilder { diff --git a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityBuilder.cs b/src/Flex.Net.REST/Models/CommunicatorRestEntityBuilder.cs similarity index 97% rename from src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityBuilder.cs rename to src/Flex.Net.REST/Models/CommunicatorRestEntityBuilder.cs index 85678bb..1215c4f 100644 --- a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityBuilder.cs +++ b/src/Flex.Net.REST/Models/CommunicatorRestEntityBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicatorRestEntityBuilder : ICommunicatorRestEntityBuilder where TEntity : class diff --git a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityContext.cs b/src/Flex.Net.REST/Models/CommunicatorRestEntityContext.cs similarity index 76% rename from src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityContext.cs rename to src/Flex.Net.REST/Models/CommunicatorRestEntityContext.cs index e9f7081..fad01f9 100644 --- a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityContext.cs +++ b/src/Flex.Net.REST/Models/CommunicatorRestEntityContext.cs @@ -1,10 +1,9 @@ using BitzArt.Pagination; using Microsoft.Extensions.Logging; -using System.Text; using System.Text.Json; using System.Web; -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicatorRestEntityContext : ICommunicationContext where TEntity : class @@ -20,13 +19,17 @@ internal virtual CommunicatorRestEntityOptions EntityOptions set => _entityOptions = value; } - internal string GetFullPath(string path) + internal string GetFullPath(string path, bool handleParameters, object[]? parameters = null) { if (ServiceOptions.BaseUrl is null) return path; var p1 = ServiceOptions.BaseUrl.TrimEnd('/'); var p2 = path.TrimStart('/'); - return $"{p1}/{p2}"; + var result = $"{p1}/{p2}"; + + if (handleParameters) result = RequestParameterParsingUtility.ParseRequestUrl(_logger, result, parameters); + + return result; } internal async Task HandleRequestAsync(HttpRequestMessage message) where TResult : class @@ -60,10 +63,10 @@ public CommunicatorRestEntityContext(HttpClient httpClient, CommunicatorRestServ _entityOptions = entityOptions; } - public virtual async Task> GetAllAsync() + public virtual async Task> GetAllAsync(params object[]? parameters) { var path = EntityOptions.Endpoint is not null ? EntityOptions.Endpoint : string.Empty; - var route = GetFullPath(path); + var route = GetFullPath(path, true, parameters); _logger.LogInformation("GetAll {type}: {path}", typeof(TEntity).Name, route); @@ -73,9 +76,9 @@ public virtual async Task> GetAllAsync() return result; } - public virtual async Task> GetPageAsync(int offset, int limit) => await GetPageAsync(new PageRequest(offset, limit)); + public virtual async Task> GetPageAsync(int offset, int limit, params object[]? parameters) => await GetPageAsync(new PageRequest(offset, limit), parameters); - public virtual async Task> GetPageAsync(PageRequest pageRequest) + public virtual async Task> GetPageAsync(PageRequest pageRequest, params object[]? parameters) { var path = EntityOptions.Endpoint is not null ? EntityOptions.Endpoint : string.Empty; var queryIndex = path.IndexOf('?'); @@ -90,7 +93,7 @@ public virtual async Task> GetPageAsync(PageRequest pageRequ if (queryIndex != -1) path = path[..queryIndex]; path = path + "?" + query.ToString(); - var route = GetFullPath(path); + var route = GetFullPath(path, true, parameters); _logger.LogInformation("GetPage {type}: {route}", typeof(TEntity).Name, route); var message = new HttpRequestMessage(HttpMethod.Get, route); @@ -99,12 +102,12 @@ public virtual async Task> GetPageAsync(PageRequest pageRequ return result; } - public virtual async Task GetAsync(object? id) + public virtual async Task GetAsync(object? id, params object[]? parameters) { if (EntityOptions.GetIdEndpointAction is null) throw new KeyNotFoundException(); - var idEndpoint = EntityOptions.GetIdEndpointAction(id); - var route = GetFullPath(idEndpoint); + var idEndpoint = EntityOptions.GetIdEndpointAction(id, parameters); + var route = GetFullPath(idEndpoint, false); _logger.LogInformation("Get {type}[{id}]: {route}", typeof(TEntity).Name, id is not null ? id.ToString() : "_", route); var message = new HttpRequestMessage(HttpMethod.Get, route); @@ -132,15 +135,23 @@ public CommunicatorRestEntityContext(HttpClient httpClient, CommunicatorRestServ EntityOptions = entityOptions; } - public override Task GetAsync(object? id) => GetAsync((TKey?)id); + public override Task GetAsync(object? id, params object[]? parameters) => GetAsync((TKey?)id, parameters); - public async Task GetAsync(TKey? id) + public async Task GetAsync(TKey? id, params object[]? parameters) { string idEndpoint; - if (EntityOptions.GetIdEndpointAction is not null) idEndpoint = EntityOptions.GetIdEndpointAction(id); - else idEndpoint = EntityOptions.Endpoint is not null ? Path.Combine(EntityOptions.Endpoint, id!.ToString()!) : id!.ToString()!; - var route = GetFullPath(idEndpoint); + bool handleParameters = false; + if (EntityOptions.GetIdEndpointAction is not null) + { + idEndpoint = EntityOptions.GetIdEndpointAction(id, parameters); + } + else + { + idEndpoint = EntityOptions.Endpoint is not null ? Path.Combine(EntityOptions.Endpoint, id!.ToString()!) : id!.ToString()!; + handleParameters = true; + } + var route = GetFullPath(idEndpoint, handleParameters, parameters); _logger.LogInformation("Get {type}[{id}]: {route}", typeof(TEntity).Name, id!.ToString(), route); diff --git a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityOptions.cs b/src/Flex.Net.REST/Models/CommunicatorRestEntityOptions.cs similarity index 64% rename from src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityOptions.cs rename to src/Flex.Net.REST/Models/CommunicatorRestEntityOptions.cs index 1696d78..2490ee8 100644 --- a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityOptions.cs +++ b/src/Flex.Net.REST/Models/CommunicatorRestEntityOptions.cs @@ -1,11 +1,11 @@ -namespace BitzArt.Communicator; +namespace Flex; public class CommunicatorRestEntityOptions where TEntity : class { public string? Endpoint { get; set; } - protected Func? _getIdEndpointAction; - public Func? GetIdEndpointAction + protected Func? _getIdEndpointAction; + public Func? GetIdEndpointAction { get => _getIdEndpointAction; set => _getIdEndpointAction = value; @@ -20,12 +20,12 @@ public CommunicatorRestEntityOptions() public class CommunicatorRestEntityOptions : CommunicatorRestEntityOptions where TEntity : class { - public new Func? GetIdEndpointAction + public new Func? GetIdEndpointAction { get { if (_getIdEndpointAction is null) return null; - return (key) => _getIdEndpointAction!(key!); + return (key, parameters) => _getIdEndpointAction!(key!, parameters); } set { @@ -34,7 +34,7 @@ public class CommunicatorRestEntityOptions : CommunicatorRestEnti _getIdEndpointAction = null; return; } - _getIdEndpointAction = (key) => value!((TKey?)key); + _getIdEndpointAction = (key, parameters) => value!((TKey?)key, parameters); } } diff --git a/src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceBuilder.cs b/src/Flex.Net.REST/Models/CommunicatorRestServiceBuilder.cs similarity index 96% rename from src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceBuilder.cs rename to src/Flex.Net.REST/Models/CommunicatorRestServiceBuilder.cs index 981b805..6df0502 100644 --- a/src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceBuilder.cs +++ b/src/Flex.Net.REST/Models/CommunicatorRestServiceBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicatorRestServiceBuilder : ICommunicatorRestServiceBuilder { diff --git a/src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceOptions.cs b/src/Flex.Net.REST/Models/CommunicatorRestServiceOptions.cs similarity index 90% rename from src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceOptions.cs rename to src/Flex.Net.REST/Models/CommunicatorRestServiceOptions.cs index 35decaa..5f2dc31 100644 --- a/src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceOptions.cs +++ b/src/Flex.Net.REST/Models/CommunicatorRestServiceOptions.cs @@ -1,6 +1,6 @@ using System.Text.Json; -namespace BitzArt.Communicator; +namespace Flex; public class CommunicatorRestServiceOptions { diff --git a/src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceProvider.cs b/src/Flex.Net.REST/Models/CommunicatorRestServiceProvider.cs similarity index 98% rename from src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceProvider.cs rename to src/Flex.Net.REST/Models/CommunicatorRestServiceProvider.cs index 59d99ca..5e08acb 100644 --- a/src/BitzArt.Communicator.REST/Models/CommunicatorRestServiceProvider.cs +++ b/src/Flex.Net.REST/Models/CommunicatorRestServiceProvider.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicatorRestServiceProvider : ICommunicatorServiceProvider { diff --git a/src/Flex.Net.REST/Utility/RequestParameterParsingUtility.cs b/src/Flex.Net.REST/Utility/RequestParameterParsingUtility.cs new file mode 100644 index 0000000..e51644c --- /dev/null +++ b/src/Flex.Net.REST/Utility/RequestParameterParsingUtility.cs @@ -0,0 +1,52 @@ +using Microsoft.Extensions.Logging; +using System.Text; +using System.Text.RegularExpressions; + +namespace Flex; + +internal partial class RequestParameterParsingUtility +{ + public static string ParseRequestUrl(ILogger logger, string path, object[]? parameters) + { + var logBuilder = new StringBuilder(); + + var matches = ParameterRegex().Matches(path); + if (!matches.Any()) return path; + + if (parameters is null) throw new ParametersNotFoundException(); + + var requiredCount = matches.Count; + var foundCount = parameters.Length; + + if (requiredCount != foundCount) throw new ParameterCountDidNotMatchException(foundCount, requiredCount); + + var result = path; + + for (int counter = 0; counter < requiredCount; counter++) + { + var match = matches[counter]; + var paramName = match.Groups[1].Value; + var value = parameters[counter].ToString(); + result = result.Replace(match.Value, value); + } + + return result; + } + + [GeneratedRegex("{(.*?)}")] + private static partial Regex ParameterRegex(); +} + +file class ParametersNotFoundException : Exception +{ + public ParametersNotFoundException() + : base("Parameters are specified in endpoint configuration but not found in the request.") + { } +} + +file class ParameterCountDidNotMatchException : Exception +{ + public ParameterCountDidNotMatchException(int found, int required) + : base($"Number of parameters in a request ({found}) did not match number of required parameters ({required}) for this endpoint.") + { } +} diff --git a/src/BitzArt.Communicator/Extensions/AddCommunicatorExtension.cs b/src/Flex.Net/Extensions/AddCommunicatorExtension.cs similarity index 86% rename from src/BitzArt.Communicator/Extensions/AddCommunicatorExtension.cs rename to src/Flex.Net/Extensions/AddCommunicatorExtension.cs index 3a4e0a2..b4c1a3b 100644 --- a/src/BitzArt.Communicator/Extensions/AddCommunicatorExtension.cs +++ b/src/Flex.Net/Extensions/AddCommunicatorExtension.cs @@ -1,8 +1,6 @@ -using BitzArt.Communicator; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.DependencyInjection; -namespace BitzArt; +namespace Flex; public static class AddCommunicatorExtension { diff --git a/src/BitzArt.Communicator/Extensions/AddServiceExtension.cs b/src/Flex.Net/Extensions/AddServiceExtension.cs similarity index 84% rename from src/BitzArt.Communicator/Extensions/AddServiceExtension.cs rename to src/Flex.Net/Extensions/AddServiceExtension.cs index fdf619b..f4ddc6b 100644 --- a/src/BitzArt.Communicator/Extensions/AddServiceExtension.cs +++ b/src/Flex.Net/Extensions/AddServiceExtension.cs @@ -1,6 +1,4 @@ -using BitzArt.Communicator; - -namespace BitzArt; +namespace Flex; public static class AddServiceExtension { diff --git a/src/BitzArt.Communicator/BitzArt.Communicator.csproj b/src/Flex.Net/Flex.Net.csproj similarity index 69% rename from src/BitzArt.Communicator/BitzArt.Communicator.csproj rename to src/Flex.Net/Flex.Net.csproj index e3bfd85..42ed279 100644 --- a/src/BitzArt.Communicator/BitzArt.Communicator.csproj +++ b/src/Flex.Net/Flex.Net.csproj @@ -4,15 +4,15 @@ net7.0 enable enable - BitzArt.Communicator + Flex - BitzArt.Communicator + Flex.Net BitzArt - A package that allows communicating with external services easily + A universal WebApi client MIT git - https://github.com/BitzArt/Communicator - https://github.com/BitzArt/Communicator + https://github.com/BitzArt/Flex.Net + https://github.com/BitzArt/Flex.Net README.md @@ -32,13 +32,13 @@ - <_Parameter1>BitzArt.Communicator.Tests + <_Parameter1>Flex.Net.Tests - <_Parameter1>BitzArt.Communicator.REST + <_Parameter1>Flex.Net.REST - <_Parameter1>BitzArt.Communicator.REST.Tests + <_Parameter1>Flex.Net.REST.Tests diff --git a/src/BitzArt.Communicator/Interfaces/ICommunicationContext.cs b/src/Flex.Net/Interfaces/ICommunicationContext.cs similarity index 63% rename from src/BitzArt.Communicator/Interfaces/ICommunicationContext.cs rename to src/Flex.Net/Interfaces/ICommunicationContext.cs index 3bf8f8b..1f2a284 100644 --- a/src/BitzArt.Communicator/Interfaces/ICommunicationContext.cs +++ b/src/Flex.Net/Interfaces/ICommunicationContext.cs @@ -1,6 +1,6 @@ using BitzArt.Pagination; -namespace BitzArt.Communicator; +namespace Flex; public interface ICommunicationContext { @@ -11,14 +11,14 @@ public interface ICommunicationContext public interface ICommunicationContext where TEntity : class { - public Task> GetAllAsync(); - public Task> GetPageAsync(int offset, int limit); - public Task> GetPageAsync(PageRequest pageRequest); - public Task GetAsync(object? id); + public Task> GetAllAsync(params object[]? parameters); + public Task> GetPageAsync(int offset, int limit, params object[]? parameters); + public Task> GetPageAsync(PageRequest pageRequest, params object[]? parameters); + public Task GetAsync(object? id, params object[]? parameters); } public interface ICommunicationContext : ICommunicationContext where TEntity : class { - public Task GetAsync(TKey? id); + public Task GetAsync(TKey? id, params object[]? parameters); } \ No newline at end of file diff --git a/src/BitzArt.Communicator/Interfaces/ICommunicatorBuilder.cs b/src/Flex.Net/Interfaces/ICommunicatorBuilder.cs similarity index 86% rename from src/BitzArt.Communicator/Interfaces/ICommunicatorBuilder.cs rename to src/Flex.Net/Interfaces/ICommunicatorBuilder.cs index 98e397b..9c73698 100644 --- a/src/BitzArt.Communicator/Interfaces/ICommunicatorBuilder.cs +++ b/src/Flex.Net/Interfaces/ICommunicatorBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; public interface ICommunicatorBuilder { diff --git a/src/BitzArt.Communicator/Interfaces/ICommunicatorEntityBuilder.cs b/src/Flex.Net/Interfaces/ICommunicatorEntityBuilder.cs similarity index 69% rename from src/BitzArt.Communicator/Interfaces/ICommunicatorEntityBuilder.cs rename to src/Flex.Net/Interfaces/ICommunicatorEntityBuilder.cs index 97c8564..b695b94 100644 --- a/src/BitzArt.Communicator/Interfaces/ICommunicatorEntityBuilder.cs +++ b/src/Flex.Net/Interfaces/ICommunicatorEntityBuilder.cs @@ -1,4 +1,4 @@ -namespace BitzArt.Communicator; +namespace Flex; public interface ICommunicatorEntityBuilder : ICommunicatorServiceBuilder { diff --git a/src/BitzArt.Communicator/Interfaces/ICommunicatorServiceBuilder.cs b/src/Flex.Net/Interfaces/ICommunicatorServiceBuilder.cs similarity index 89% rename from src/BitzArt.Communicator/Interfaces/ICommunicatorServiceBuilder.cs rename to src/Flex.Net/Interfaces/ICommunicatorServiceBuilder.cs index 528429d..d259939 100644 --- a/src/BitzArt.Communicator/Interfaces/ICommunicatorServiceBuilder.cs +++ b/src/Flex.Net/Interfaces/ICommunicatorServiceBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; public interface ICommunicatorServiceBuilder { diff --git a/src/BitzArt.Communicator/Interfaces/ICommunicatorServiceFactory.cs b/src/Flex.Net/Interfaces/ICommunicatorServiceFactory.cs similarity index 92% rename from src/BitzArt.Communicator/Interfaces/ICommunicatorServiceFactory.cs rename to src/Flex.Net/Interfaces/ICommunicatorServiceFactory.cs index 11eb855..8afda96 100644 --- a/src/BitzArt.Communicator/Interfaces/ICommunicatorServiceFactory.cs +++ b/src/Flex.Net/Interfaces/ICommunicatorServiceFactory.cs @@ -1,4 +1,4 @@ -namespace BitzArt.Communicator; +namespace Flex; internal interface ICommunicatorServiceFactory { diff --git a/src/BitzArt.Communicator/Interfaces/ICommunicatorServicePreBuilder.cs b/src/Flex.Net/Interfaces/ICommunicatorServicePreBuilder.cs similarity index 88% rename from src/BitzArt.Communicator/Interfaces/ICommunicatorServicePreBuilder.cs rename to src/Flex.Net/Interfaces/ICommunicatorServicePreBuilder.cs index 223783c..91aa92b 100644 --- a/src/BitzArt.Communicator/Interfaces/ICommunicatorServicePreBuilder.cs +++ b/src/Flex.Net/Interfaces/ICommunicatorServicePreBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; public interface ICommunicatorServicePreBuilder { diff --git a/src/BitzArt.Communicator/Interfaces/ICommunicatorServiceProvider.cs b/src/Flex.Net/Interfaces/ICommunicatorServiceProvider.cs similarity index 94% rename from src/BitzArt.Communicator/Interfaces/ICommunicatorServiceProvider.cs rename to src/Flex.Net/Interfaces/ICommunicatorServiceProvider.cs index 109a548..6aa4dad 100644 --- a/src/BitzArt.Communicator/Interfaces/ICommunicatorServiceProvider.cs +++ b/src/Flex.Net/Interfaces/ICommunicatorServiceProvider.cs @@ -1,4 +1,4 @@ -namespace BitzArt.Communicator; +namespace Flex; internal interface ICommunicatorServiceProvider { diff --git a/src/BitzArt.Communicator/Models/CommunicationContext.cs b/src/Flex.Net/Models/CommunicationContext.cs similarity index 95% rename from src/BitzArt.Communicator/Models/CommunicationContext.cs rename to src/Flex.Net/Models/CommunicationContext.cs index 2b5a95b..4405fdd 100644 --- a/src/BitzArt.Communicator/Models/CommunicationContext.cs +++ b/src/Flex.Net/Models/CommunicationContext.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicationContext : ICommunicationContext { diff --git a/src/BitzArt.Communicator/Models/CommunicatorBuilder.cs b/src/Flex.Net/Models/CommunicatorBuilder.cs similarity index 92% rename from src/BitzArt.Communicator/Models/CommunicatorBuilder.cs rename to src/Flex.Net/Models/CommunicatorBuilder.cs index a3c0879..e9bb02b 100644 --- a/src/BitzArt.Communicator/Models/CommunicatorBuilder.cs +++ b/src/Flex.Net/Models/CommunicatorBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicatorBuilder : ICommunicatorBuilder { diff --git a/src/BitzArt.Communicator/Models/CommunicatorEntitySignature.cs b/src/Flex.Net/Models/CommunicatorEntitySignature.cs similarity index 70% rename from src/BitzArt.Communicator/Models/CommunicatorEntitySignature.cs rename to src/Flex.Net/Models/CommunicatorEntitySignature.cs index 5106ef8..46bc0bd 100644 --- a/src/BitzArt.Communicator/Models/CommunicatorEntitySignature.cs +++ b/src/Flex.Net/Models/CommunicatorEntitySignature.cs @@ -1,3 +1,3 @@ -namespace BitzArt.Communicator; +namespace Flex; internal record CommunicatorEntitySignature(Type EntityType, Type? KeyType = null); \ No newline at end of file diff --git a/src/BitzArt.Communicator/Models/CommunicatorServiceFactory.cs b/src/Flex.Net/Models/CommunicatorServiceFactory.cs similarity index 97% rename from src/BitzArt.Communicator/Models/CommunicatorServiceFactory.cs rename to src/Flex.Net/Models/CommunicatorServiceFactory.cs index 17505e1..1b84ba9 100644 --- a/src/BitzArt.Communicator/Models/CommunicatorServiceFactory.cs +++ b/src/Flex.Net/Models/CommunicatorServiceFactory.cs @@ -1,4 +1,4 @@ -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicatorServiceFactory : ICommunicatorServiceFactory { diff --git a/src/BitzArt.Communicator/Models/CommunicatorServicePreBuilder.cs b/src/Flex.Net/Models/CommunicatorServicePreBuilder.cs similarity index 93% rename from src/BitzArt.Communicator/Models/CommunicatorServicePreBuilder.cs rename to src/Flex.Net/Models/CommunicatorServicePreBuilder.cs index 3a8572f..0d400e5 100644 --- a/src/BitzArt.Communicator/Models/CommunicatorServicePreBuilder.cs +++ b/src/Flex.Net/Models/CommunicatorServicePreBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace BitzArt.Communicator; +namespace Flex; internal class CommunicatorServicePreBuilder : ICommunicatorServicePreBuilder { diff --git a/tests/BitzArt.Communicator.REST.Tests/BitzArt.Communicator.REST.Tests.csproj b/tests/Flex.Net.REST.Tests/Flex.Net.REST.Tests.csproj similarity index 87% rename from tests/BitzArt.Communicator.REST.Tests/BitzArt.Communicator.REST.Tests.csproj rename to tests/Flex.Net.REST.Tests/Flex.Net.REST.Tests.csproj index cbc6688..e81359c 100644 --- a/tests/BitzArt.Communicator.REST.Tests/BitzArt.Communicator.REST.Tests.csproj +++ b/tests/Flex.Net.REST.Tests/Flex.Net.REST.Tests.csproj @@ -4,7 +4,7 @@ net7.0 enable enable - BitzArt.Communicator + Flex false @@ -25,7 +25,7 @@ - + diff --git a/tests/BitzArt.Communicator.REST.Tests/MockedRestServiceTests.cs b/tests/Flex.Net.REST.Tests/MockedRestServiceTests.cs similarity index 63% rename from tests/BitzArt.Communicator.REST.Tests/MockedRestServiceTests.cs rename to tests/Flex.Net.REST.Tests/MockedRestServiceTests.cs index fab9e3f..2269c14 100644 --- a/tests/BitzArt.Communicator.REST.Tests/MockedRestServiceTests.cs +++ b/tests/Flex.Net.REST.Tests/MockedRestServiceTests.cs @@ -2,7 +2,7 @@ using System.Net.Http.Json; using System.Net; -namespace BitzArt.Communicator; +namespace Flex; public class MockedRestServiceTests { @@ -110,11 +110,67 @@ public async Task GetAsync_CustomIdEndpointLogic_ReturnsEntity(string baseUrl) }); ((CommunicatorRestEntityContext)entityContext) - .EntityOptions.GetIdEndpointAction = (key) => "entity/specific"; + .EntityOptions.GetIdEndpointAction = (key, parameters) => "entity/specific"; var result = await entityContext.GetAsync(1); Assert.NotNull(result); Assert.Equal(1, result.Id); } + + [Fact] + public async Task GetAsyncWithParameters_MockedHttpClient_Returns() + { + var baseUrl = "https://mocked.service"; + var id = 1; + + var database = TestEntity.GetAll(100); + var changedName = "Changed Name"; + var defaultEntity = database.First(x => x.Id == id); + var defaultName = defaultEntity.Name; + var changedEntity = new TestEntity() { Id = id, Name = changedName }; + + var entityContext = (CommunicatorRestEntityContext) + TestEntityContext.GetTestEntityContext(baseUrl, x => + { + x.When($"{baseUrl.TrimEnd('/')}/entity/{id}?changeName=False") + .Respond(HttpStatusCode.OK, + JsonContent.Create(defaultEntity)); + + x.When($"{baseUrl.TrimEnd('/')}/entity/{id}?changeName=True") + .Respond(HttpStatusCode.OK, + JsonContent.Create(changedEntity)); + }); + + entityContext.EntityOptions.GetIdEndpointAction = (id, parameters) => + { + return $"entity/{id}?changeName={parameters!.First()}"; + }; + + var resultWithParameterFalse = await entityContext.GetAsync(id, false); + Assert.Equal(defaultName, resultWithParameterFalse.Name); + + var resultWithParameterTrue = await entityContext.GetAsync(id, true); + Assert.Equal(changedName, resultWithParameterTrue.Name); + } + + [Fact] + public async Task GetPageAsyncWithParameters_MockedHttpClient_Returns() + { + var baseUrl = "https://mocked.service"; + + var entityContext = (CommunicatorRestEntityContext) + TestEntityContext.GetTestEntityContext(baseUrl, x => + { + x.When($"{baseUrl.TrimEnd('/')}/test-1?offset=0&limit=10") + .Respond(HttpStatusCode.OK, + JsonContent.Create(TestEntity.GetPage(100, 0, 10))); + }); + + entityContext.EntityOptions.Endpoint = "test-{number}"; + + var result = await entityContext.GetPageAsync(0, 10, 1); + Assert.NotNull(result); + Assert.True(result.Data!.Count() == 10); + } } \ No newline at end of file diff --git a/tests/BitzArt.Communicator.REST.Tests/MockedService/MockedService.cs b/tests/Flex.Net.REST.Tests/MockedService/MockedService.cs similarity index 86% rename from tests/BitzArt.Communicator.REST.Tests/MockedService/MockedService.cs rename to tests/Flex.Net.REST.Tests/MockedService/MockedService.cs index d552284..12ee7ca 100644 --- a/tests/BitzArt.Communicator.REST.Tests/MockedService/MockedService.cs +++ b/tests/Flex.Net.REST.Tests/MockedService/MockedService.cs @@ -1,8 +1,6 @@ using RichardSzalay.MockHttp; -using System.Net.Http.Json; -using System.Net; -namespace BitzArt.Communicator; +namespace Flex; internal class MockedService { diff --git a/tests/BitzArt.Communicator.REST.Tests/MockedService/TestEntity.cs b/tests/Flex.Net.REST.Tests/MockedService/TestEntity.cs similarity index 95% rename from tests/BitzArt.Communicator.REST.Tests/MockedService/TestEntity.cs rename to tests/Flex.Net.REST.Tests/MockedService/TestEntity.cs index e439820..bec85d4 100644 --- a/tests/BitzArt.Communicator.REST.Tests/MockedService/TestEntity.cs +++ b/tests/Flex.Net.REST.Tests/MockedService/TestEntity.cs @@ -1,7 +1,7 @@ using BitzArt.Pagination; using System.Text.Json.Serialization; -namespace BitzArt.Communicator; +namespace Flex; internal class TestEntity { diff --git a/tests/BitzArt.Communicator.REST.Tests/MockedService/TestEntityContext.cs b/tests/Flex.Net.REST.Tests/MockedService/TestEntityContext.cs similarity index 95% rename from tests/BitzArt.Communicator.REST.Tests/MockedService/TestEntityContext.cs rename to tests/Flex.Net.REST.Tests/MockedService/TestEntityContext.cs index 210b8b9..db8706d 100644 --- a/tests/BitzArt.Communicator.REST.Tests/MockedService/TestEntityContext.cs +++ b/tests/Flex.Net.REST.Tests/MockedService/TestEntityContext.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using RichardSzalay.MockHttp; -namespace BitzArt.Communicator; +namespace Flex; internal static class TestEntityContext { diff --git a/tests/BitzArt.Communicator.REST.Tests/ServiceRegistrationTests.cs b/tests/Flex.Net.REST.Tests/ServiceRegistrationTests.cs similarity index 99% rename from tests/BitzArt.Communicator.REST.Tests/ServiceRegistrationTests.cs rename to tests/Flex.Net.REST.Tests/ServiceRegistrationTests.cs index 7ed37cd..32e2a39 100644 --- a/tests/BitzArt.Communicator.REST.Tests/ServiceRegistrationTests.cs +++ b/tests/Flex.Net.REST.Tests/ServiceRegistrationTests.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using System.Text.Json.Serialization; -namespace BitzArt.Communicator; +namespace Flex; file class TestEntity { diff --git a/tests/BitzArt.Communicator.Tests/BitzArt.Communicator.Tests.csproj b/tests/Flex.Net.Tests/Flex.Net.Tests.csproj similarity index 87% rename from tests/BitzArt.Communicator.Tests/BitzArt.Communicator.Tests.csproj rename to tests/Flex.Net.Tests/Flex.Net.Tests.csproj index 28b8c33..9b95481 100644 --- a/tests/BitzArt.Communicator.Tests/BitzArt.Communicator.Tests.csproj +++ b/tests/Flex.Net.Tests/Flex.Net.Tests.csproj @@ -4,7 +4,7 @@ net7.0 enable enable - BitzArt.Communicator + Flex false @@ -24,7 +24,7 @@ - + diff --git a/tests/BitzArt.Communicator.Tests/ServiceRegistrationTests.cs b/tests/Flex.Net.Tests/ServiceRegistrationTests.cs similarity index 95% rename from tests/BitzArt.Communicator.Tests/ServiceRegistrationTests.cs rename to tests/Flex.Net.Tests/ServiceRegistrationTests.cs index d7c5afa..3473731 100644 --- a/tests/BitzArt.Communicator.Tests/ServiceRegistrationTests.cs +++ b/tests/Flex.Net.Tests/ServiceRegistrationTests.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -using System.Text.Json.Serialization; -namespace BitzArt.Communicator; +namespace Flex; public class ServiceRegistrationTests {