From c053b871cb70344f348f4016641c555b39e3ac12 Mon Sep 17 00:00:00 2001 From: Ricardo Rocha Date: Mon, 13 Nov 2023 17:02:07 +0000 Subject: [PATCH] setup odata and Api custom endpoints to use route prefix defined in Nox.Solution --- .../CountriesController.g.cs | 16 +- .../CurrenciesController.g.cs | 16 +- .../EmployeesController.g.cs | 8 +- .../ODataServiceCollectionExtensions.g.cs | 2 +- schemas/infrastructure.json | 6 +- .../.nox/design/clientapi.solution.nox.yaml | 3 + .../.nox/docs/IntegrationEvents.md | 24 +- .../Controllers/CountriesController.cs | 9 +- .../CountriesController.g.cs | 10 +- .../CountriesController/Enumerations.g.cs | 2 +- .../ODataServiceCollectionExtensions.g.cs | 2 +- .../StoresController/Enumerations.g.cs | 2 +- .../ServiceMetadata/oDataMetadata.xml | 643 ------------------ .../CreateCountryCommandHandlerTests.cs | 11 +- .../IntegrationEventsStagingEnvTests.cs | 16 +- .../Messaging/IntegrationEventsTests.cs | 24 +- .../GetCountryByIdQueryValidatorTests.cs | 11 +- ...ountryQualityOfLifeIndexControllerTests.cs | 10 +- .../Tests/Controllers/Endpoints.cs | 19 +- .../EntityController.Enumerations.template.cs | 2 +- .../Api/OData/EntityControllerGenerator.cs | 17 +- ...ataServiceCollectionExtensions.template.cs | 2 +- .../Presentation/Api/OData/ODataApi.cs | 16 + .../Infrastructure/Endpoints/Endpoints.cs | 19 +- ...ntation.Api.OData.CountriesController.g.cs | 4 +- .../ODataServiceCollectionExtensions.g.cs | 2 +- .../Enumerations.g.cs | 2 +- ...wnedRelationshipExactlyOnesController.g.cs | 2 +- ...wnedRelationshipOneOrManiesController.g.cs | 8 +- ...nedRelationshipZeroOrManiesController.g.cs | 8 +- ...OwnedRelationshipZeroOrOnesController.g.cs | 2 +- .../Presentation/Api/OData/ODataApiTests.cs | 18 + .../Endpoints/EndPointsTests.cs | 28 +- ...endpoints.no.routeprefix.solution.nox.yaml | 5 +- ...dpoints.root.routeprefix.solution.nox.yaml | 21 + ...ts.routeprefix.sanitized.solution.nox.yaml | 2 +- .../endpoints.routeprefix.solution.nox.yaml | 2 +- 37 files changed, 210 insertions(+), 784 deletions(-) create mode 100644 src/Nox.Lib/Presentation/Api/OData/ODataApi.cs create mode 100644 tests/Nox.Lib.Tests/Presentation/Api/OData/ODataApiTests.cs create mode 100644 tests/Nox.Solution.Tests/files/endpoints.root.routeprefix.solution.nox.yaml diff --git a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs index f53b035d37..045d21c6bc 100644 --- a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs +++ b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs @@ -46,7 +46,7 @@ public virtual async Task>> GetCount } [EnableQuery] - [HttpGet("api/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] + [HttpGet("/api/v1/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] public virtual async Task> GetCountryOwnedTimeZonesNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -85,7 +85,7 @@ public virtual async Task PostToCountryOwnedTimeZones([FromRoute] return Created(child); } - [HttpPut("api/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] + [HttpPut("/api/v1/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] public virtual async Task> PutToCountryTimeZonesNonConventional(System.String key, System.Int64 relatedKey, [FromBody] CountryTimeZoneUpdateDto countryTimeZone) { if (!ModelState.IsValid) @@ -109,7 +109,7 @@ public virtual async Task> PutToCountryTimeZone return Ok(child); } - [HttpPatch("api/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] + [HttpPatch("/api/v1/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] public virtual async Task PatchToCountryTimeZonesNonConventional(System.String key, System.Int64 relatedKey, [FromBody] Delta countryTimeZone) { if (!ModelState.IsValid) @@ -142,7 +142,7 @@ public virtual async Task PatchToCountryTimeZonesNonConventional(S return Ok(child); } - [HttpDelete("api/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] + [HttpDelete("/api/v1/Countries/{key}/CountryOwnedTimeZones/{relatedKey}")] public virtual async Task DeleteCountryTimeZoneNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -182,7 +182,7 @@ public virtual async Task>> GetCountryOwnedH } [EnableQuery] - [HttpGet("api/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] + [HttpGet("/api/v1/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] public virtual async Task> GetCountryOwnedHolidaysNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -221,7 +221,7 @@ public virtual async Task PostToCountryOwnedHolidays([FromRoute] S return Created(child); } - [HttpPut("api/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] + [HttpPut("/api/v1/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] public virtual async Task> PutToHolidaysNonConventional(System.String key, System.Int64 relatedKey, [FromBody] HolidayUpdateDto holiday) { if (!ModelState.IsValid) @@ -245,7 +245,7 @@ public virtual async Task> PutToHolidaysNonConventional return Ok(child); } - [HttpPatch("api/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] + [HttpPatch("/api/v1/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] public virtual async Task PatchToHolidaysNonConventional(System.String key, System.Int64 relatedKey, [FromBody] Delta holiday) { if (!ModelState.IsValid) @@ -278,7 +278,7 @@ public virtual async Task PatchToHolidaysNonConventional(System.St return Ok(child); } - [HttpDelete("api/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] + [HttpDelete("/api/v1/Countries/{key}/CountryOwnedHolidays/{relatedKey}")] public virtual async Task DeleteHolidayNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) diff --git a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CurrenciesController.g.cs b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CurrenciesController.g.cs index 5c6a1bd2ee..8c20d30a32 100644 --- a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CurrenciesController.g.cs +++ b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CurrenciesController.g.cs @@ -46,7 +46,7 @@ public virtual async Task>> GetCurrencyComm } [EnableQuery] - [HttpGet("api/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] + [HttpGet("/api/v1/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] public virtual async Task> GetCurrencyCommonBankNotesNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -85,7 +85,7 @@ public virtual async Task PostToCurrencyCommonBankNotes([FromRoute return Created(child); } - [HttpPut("api/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] + [HttpPut("/api/v1/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] public virtual async Task> PutToBankNotesNonConventional(System.String key, System.Int64 relatedKey, [FromBody] BankNoteUpdateDto bankNote) { if (!ModelState.IsValid) @@ -109,7 +109,7 @@ public virtual async Task> PutToBankNotesNonConvention return Ok(child); } - [HttpPatch("api/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] + [HttpPatch("/api/v1/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] public virtual async Task PatchToBankNotesNonConventional(System.String key, System.Int64 relatedKey, [FromBody] Delta bankNote) { if (!ModelState.IsValid) @@ -142,7 +142,7 @@ public virtual async Task PatchToBankNotesNonConventional(System.S return Ok(child); } - [HttpDelete("api/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] + [HttpDelete("/api/v1/Currencies/{key}/CurrencyCommonBankNotes/{relatedKey}")] public virtual async Task DeleteBankNoteNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -182,7 +182,7 @@ public virtual async Task>> GetCurrency } [EnableQuery] - [HttpGet("api/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] + [HttpGet("/api/v1/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] public virtual async Task> GetCurrencyExchangedFromRatesNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -221,7 +221,7 @@ public virtual async Task PostToCurrencyExchangedFromRates([FromRo return Created(child); } - [HttpPut("api/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] + [HttpPut("/api/v1/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] public virtual async Task> PutToExchangeRatesNonConventional(System.String key, System.Int64 relatedKey, [FromBody] ExchangeRateUpdateDto exchangeRate) { if (!ModelState.IsValid) @@ -245,7 +245,7 @@ public virtual async Task> PutToExchangeRatesNonCo return Ok(child); } - [HttpPatch("api/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] + [HttpPatch("/api/v1/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] public virtual async Task PatchToExchangeRatesNonConventional(System.String key, System.Int64 relatedKey, [FromBody] Delta exchangeRate) { if (!ModelState.IsValid) @@ -278,7 +278,7 @@ public virtual async Task PatchToExchangeRatesNonConventional(Syst return Ok(child); } - [HttpDelete("api/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] + [HttpDelete("/api/v1/Currencies/{key}/CurrencyExchangedFromRates/{relatedKey}")] public virtual async Task DeleteExchangeRateNonConventional(System.String key, System.Int64 relatedKey) { if (!ModelState.IsValid) diff --git a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/EmployeesController.g.cs b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/EmployeesController.g.cs index 366eb8fb56..e9f2cfcfc9 100644 --- a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/EmployeesController.g.cs +++ b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/EmployeesController.g.cs @@ -46,7 +46,7 @@ public virtual async Task>> GetE } [EnableQuery] - [HttpGet("api/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] + [HttpGet("/api/v1/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] public virtual async Task> GetEmployeeContactPhoneNumbersNonConventional(System.Int64 key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -85,7 +85,7 @@ public virtual async Task PostToEmployeeContactPhoneNumbers([FromR return Created(child); } - [HttpPut("api/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] + [HttpPut("/api/v1/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] public virtual async Task> PutToEmployeePhoneNumbersNonConventional(System.Int64 key, System.Int64 relatedKey, [FromBody] EmployeePhoneNumberUpdateDto employeePhoneNumber) { if (!ModelState.IsValid) @@ -109,7 +109,7 @@ public virtual async Task> PutToEmployeePho return Ok(child); } - [HttpPatch("api/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] + [HttpPatch("/api/v1/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] public virtual async Task PatchToEmployeePhoneNumbersNonConventional(System.Int64 key, System.Int64 relatedKey, [FromBody] Delta employeePhoneNumber) { if (!ModelState.IsValid) @@ -142,7 +142,7 @@ public virtual async Task PatchToEmployeePhoneNumbersNonConvention return Ok(child); } - [HttpDelete("api/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] + [HttpDelete("/api/v1/Employees/{key}/EmployeeContactPhoneNumbers/{relatedKey}")] public virtual async Task DeleteEmployeePhoneNumberNonConventional(System.Int64 key, System.Int64 relatedKey) { if (!ModelState.IsValid) diff --git a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs index 366260f2a8..b5f8f67d68 100644 --- a/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs +++ b/samples/Cryptocash.Api/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs @@ -173,7 +173,7 @@ public static void AddNoxOdata(this IServiceCollection services, Action service .AddSingleton()) .RouteOptions; diff --git a/schemas/infrastructure.json b/schemas/infrastructure.json index 08bea622b6..cbcf797b2f 100644 --- a/schemas/infrastructure.json +++ b/schemas/infrastructure.json @@ -71,9 +71,9 @@ } ], "properties": { - "apiRootPrefix": { - "title": "The api route prefix, defaults to api/v1 or to api/vMajor({Solution.Version}) if Version is set in the root of the yaml.", - "description": "Defines the prefix for all routes OData end points. Do not start by \"/\", all will be Sanitized", + "apiRoutePrefix": { + "title": "The api route prefix, defaults to api/v1 or to api/vMajor({Solution.Version}) if Version is set in the root of the Solution.", + "description": "Defines the prefix for all Api routes end points.", "oneOf": [ { "type": "string" diff --git a/src/Nox.ClientApi.Tests/.nox/design/clientapi.solution.nox.yaml b/src/Nox.ClientApi.Tests/.nox/design/clientapi.solution.nox.yaml index 5853d0189a..d26b250a61 100644 --- a/src/Nox.ClientApi.Tests/.nox/design/clientapi.solution.nox.yaml +++ b/src/Nox.ClientApi.Tests/.nox/design/clientapi.solution.nox.yaml @@ -7,10 +7,13 @@ # name: ClientApi + platformId: Nox-Tests description: Project for Nox System Testing +version: "1.0" + domain: entities: diff --git a/src/Nox.ClientApi.Tests/.nox/docs/IntegrationEvents.md b/src/Nox.ClientApi.Tests/.nox/docs/IntegrationEvents.md index 3ad77b2790..342e4eaf86 100644 --- a/src/Nox.ClientApi.Tests/.nox/docs/IntegrationEvents.md +++ b/src/Nox.ClientApi.Tests/.nox/docs/IntegrationEvents.md @@ -34,9 +34,9 @@ Attribute|Type|Example specversion|SemanticVersion|1.0 id|Guid|0d02bba1-dbf3-4ba4-93c1-2e416ec0c88d source|https://{ENVIRONMENT}.{Solution.PlatformId}.com/{Solution.Name}|https://Nox-Tests.com/ClientApi -type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Country.v1.0.CountryCreated +type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Country.v1.0.0.CountryCreated datacontenttype|ContentType|application/json -dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Country/v1.0/CountryCreated.json +dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Country/v1.0.0/CountryCreated.json time|DateTimeUtc|2023-10-10T12:11:10.5312500Z xtenantid|Text|b22ee68e-327f-4550-a077-8fb8426071f5 xuserid|Text|e945e9f9-b0ba-435d-bfe7-8966abeb8763 @@ -62,9 +62,9 @@ Attribute|Type|Example specversion|SemanticVersion|1.0 id|Guid|0d02bba1-dbf3-4ba4-93c1-2e416ec0c88d source|https://{ENVIRONMENT}.{Solution.PlatformId}.com/{Solution.Name}|https://Nox-Tests.com/ClientApi -type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Country.v1.0.CountryUpdated +type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Country.v1.0.0.CountryUpdated datacontenttype|ContentType|application/json -dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Country/v1.0/CountryUpdated.json +dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Country/v1.0.0/CountryUpdated.json time|DateTimeUtc|2023-10-10T12:11:10.5312500Z xtenantid|Text|b22ee68e-327f-4550-a077-8fb8426071f5 xuserid|Text|e945e9f9-b0ba-435d-bfe7-8966abeb8763 @@ -90,9 +90,9 @@ Attribute|Type|Example specversion|SemanticVersion|1.0 id|Guid|0d02bba1-dbf3-4ba4-93c1-2e416ec0c88d source|https://{ENVIRONMENT}.{Solution.PlatformId}.com/{Solution.Name}|https://Nox-Tests.com/ClientApi -type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Country.v1.0.CountryDeleted +type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Country.v1.0.0.CountryDeleted datacontenttype|ContentType|application/json -dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Country/v1.0/CountryDeleted.json +dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Country/v1.0.0/CountryDeleted.json time|DateTimeUtc|2023-10-10T12:11:10.5312500Z xtenantid|Text|b22ee68e-327f-4550-a077-8fb8426071f5 xuserid|Text|e945e9f9-b0ba-435d-bfe7-8966abeb8763 @@ -138,9 +138,9 @@ Attribute|Type|Example specversion|SemanticVersion|1.0 id|Guid|0d02bba1-dbf3-4ba4-93c1-2e416ec0c88d source|https://{ENVIRONMENT}.{Solution.PlatformId}.com/{Solution.Name}|https://Nox-Tests.com/ClientApi -type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Workplace.v1.0.WorkplaceDeleted +type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.Workplace.v1.0.0.WorkplaceDeleted datacontenttype|ContentType|application/json -dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Workplace/v1.0/WorkplaceDeleted.json +dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/Workplace/v1.0.0/WorkplaceDeleted.json time|DateTimeUtc|2023-10-10T12:11:10.5312500Z xtenantid|Text|b22ee68e-327f-4550-a077-8fb8426071f5 xuserid|Text|e945e9f9-b0ba-435d-bfe7-8966abeb8763 @@ -179,9 +179,9 @@ Attribute|Type|Example specversion|SemanticVersion|1.0 id|Guid|0d02bba1-dbf3-4ba4-93c1-2e416ec0c88d source|https://{ENVIRONMENT}.{Solution.PlatformId}.com/{Solution.Name}|https://Nox-Tests.com/ClientApi -type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.StoreOwner.v1.0.StoreOwnerCreated +type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi.StoreOwner.v1.0.0.StoreOwnerCreated datacontenttype|ContentType|application/json -dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/StoreOwner/v1.0/StoreOwnerCreated.json +dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/StoreOwner/v1.0.0/StoreOwnerCreated.json time|DateTimeUtc|2023-10-10T12:11:10.5312500Z xtenantid|Text|b22ee68e-327f-4550-a077-8fb8426071f5 xuserid|Text|e945e9f9-b0ba-435d-bfe7-8966abeb8763 @@ -226,9 +226,9 @@ Attribute|Type|Example specversion|SemanticVersion|1.0 id|Guid|0d02bba1-dbf3-4ba4-93c1-2e416ec0c88d source|https://{ENVIRONMENT}.{Solution.PlatformId}.com/{Solution.Name}|https://Nox-Tests.com/ClientApi -type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi..v1.0.CountryPopulationHigherThan100M +type|{Solution.PlatformId}.{Solution.Name}.{Trait}.v{Solution.Version}.{eventName}|Nox-Tests.ClientApi..v1.0.0.CountryPopulationHigherThan100M datacontenttype|ContentType|application/json -dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/TBD/v1.0/CountryPopulationHigherThan100M.json +dataschema|https://{ENVIRONMENT}.{Solution.PlatformId}.com/schemas/{Solution.Name}/{Trait}/v{Solution.Version}/{eventName}.json|https://Nox-Tests.com/schemas/ClientApi/TBD/v1.0.0/CountryPopulationHigherThan100M.json time|DateTimeUtc|2023-10-10T12:11:10.5312500Z xtenantid|Text|b22ee68e-327f-4550-a077-8fb8426071f5 xuserid|Text|e945e9f9-b0ba-435d-bfe7-8966abeb8763 diff --git a/src/Nox.ClientApi.Tests/Controllers/CountriesController.cs b/src/Nox.ClientApi.Tests/Controllers/CountriesController.cs index e961cd2600..f4794a76a1 100644 --- a/src/Nox.ClientApi.Tests/Controllers/CountriesController.cs +++ b/src/Nox.ClientApi.Tests/Controllers/CountriesController.cs @@ -16,6 +16,7 @@ using ClientApi.Domain; using ClientApi.Infrastructure.Persistence; using Nox.Types; +using ClientApi.Tests.Controllers; namespace ClientApi.Presentation.Api.OData; @@ -59,7 +60,7 @@ public override async Task PostToCountryShortNames([FromRoute] lon /// /// Prefer using Nox Solution Entity Definition (yaml) to register custom function [EnableQuery] - [HttpGet("api/CountriesWithDebt")] + [HttpGet($"{Endpoints.RoutePrefix}/CountriesWithDebt")] public ActionResult> CountriesWithDebt() { return Ok(new List() { @@ -75,7 +76,7 @@ public override async Task PostToCountryShortNames([FromRoute] lon /// And Nox Solution Entity Definition (yaml) to register custom function /// /// - [HttpGet("api/[controller]/[action]")] + [HttpGet($"{Endpoints.RoutePrefix}/[controller]/[action]")] public ActionResult> CountriesWithDebt2() { return Ok(new List() { @@ -90,7 +91,7 @@ public override async Task PostToCountryShortNames([FromRoute] lon /// Example of a non OData end point that returns Created StatusCode /// /// - [HttpPost("api/[controller]/[action]")] + [HttpPost($"{Endpoints.RoutePrefix}/[controller]/[action]")] public IResult CustomCreateCountry([FromBody] Application.Dto.CountryCreateDto country) { var createdCountry = new Application.Dto.CountryDto() @@ -100,7 +101,7 @@ public IResult CustomCreateCountry([FromBody] Application.Dto.CountryCreateDto c }; var routeValues = new { key = createdCountry.Id }; - return Results.Created($"api/Countries/{createdCountry.Id}", routeValues); + return Results.Created($"{Endpoints.RoutePrefix}/Countries/{createdCountry.Id}", routeValues); } } diff --git a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs index 5218a662bf..0647a8aa79 100644 --- a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs +++ b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController.g.cs @@ -46,7 +46,7 @@ public virtual async Task>> GetCoun } [EnableQuery] - [HttpGet("api/Countries/{key}/CountryShortNames/{relatedKey}")] + [HttpGet("/api/v1/Countries/{key}/CountryShortNames/{relatedKey}")] public virtual async Task> GetCountryShortNamesNonConventional(System.Int64 key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -85,7 +85,7 @@ public virtual async Task PostToCountryShortNames([FromRoute] Syst return Created(child); } - [HttpPut("api/Countries/{key}/CountryShortNames/{relatedKey}")] + [HttpPut("/api/v1/Countries/{key}/CountryShortNames/{relatedKey}")] public virtual async Task> PutToCountryLocalNamesNonConventional(System.Int64 key, System.Int64 relatedKey, [FromBody] CountryLocalNameUpdateDto countryLocalName) { if (!ModelState.IsValid) @@ -109,7 +109,7 @@ public virtual async Task> PutToCountryLocalNa return Ok(child); } - [HttpPatch("api/Countries/{key}/CountryShortNames/{relatedKey}")] + [HttpPatch("/api/v1/Countries/{key}/CountryShortNames/{relatedKey}")] public virtual async Task PatchToCountryLocalNamesNonConventional(System.Int64 key, System.Int64 relatedKey, [FromBody] Delta countryLocalName) { if (!ModelState.IsValid) @@ -142,7 +142,7 @@ public virtual async Task PatchToCountryLocalNamesNonConventional( return Ok(child); } - [HttpDelete("api/Countries/{key}/CountryShortNames/{relatedKey}")] + [HttpDelete("/api/v1/Countries/{key}/CountryShortNames/{relatedKey}")] public virtual async Task DeleteCountryLocalNameNonConventional(System.Int64 key, System.Int64 relatedKey) { if (!ModelState.IsValid) @@ -259,7 +259,7 @@ public virtual async Task PatchToCountryBarCode(System.Int64 key, return Ok(child); } - [HttpDelete("api/Countries/{key}/CountryBarCode")] + [HttpDelete("/api/v1/Countries/{key}/CountryBarCode")] public virtual async Task DeleteCountryBarCodeNonConventional(System.Int64 key) { if (!ModelState.IsValid) diff --git a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController/Enumerations.g.cs b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController/Enumerations.g.cs index 4938c88a0d..94d60ebc51 100644 --- a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController/Enumerations.g.cs +++ b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/CountriesController/Enumerations.g.cs @@ -10,7 +10,7 @@ namespace ClientApi.Presentation.Api.OData; public abstract partial class CountriesControllerBase { - [HttpGet("api/Countries/CountryContinents")] + [HttpGet("/api/v1/Countries/CountryContinents")] public virtual async Task>> GetContinentsNonConventional() { var result = await _mediator.Send(new ApplicationQueriesNameSpace.GetCountriesContinentsQuery()); diff --git a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs index d12ccc01e0..3aa3391704 100644 --- a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs +++ b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs @@ -119,7 +119,7 @@ public static void AddNoxOdata(this IServiceCollection services, Action service .AddSingleton()) .RouteOptions; diff --git a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/StoresController/Enumerations.g.cs b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/StoresController/Enumerations.g.cs index f9de25e69e..50a86e7080 100644 --- a/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/StoresController/Enumerations.g.cs +++ b/src/Nox.ClientApi.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/StoresController/Enumerations.g.cs @@ -10,7 +10,7 @@ namespace ClientApi.Presentation.Api.OData; public abstract partial class StoresControllerBase { - [HttpGet("api/Stores/StoreStatuses")] + [HttpGet("/api/v1/Stores/StoreStatuses")] public virtual async Task>> GetStatusesNonConventional() { var result = await _mediator.Send(new ApplicationQueriesNameSpace.GetStoresStatusesQuery()); diff --git a/src/Nox.ClientApi.Tests/ServiceMetadata/oDataMetadata.xml b/src/Nox.ClientApi.Tests/ServiceMetadata/oDataMetadata.xml index 567489ac75..e69de29bb2 100644 --- a/src/Nox.ClientApi.Tests/ServiceMetadata/oDataMetadata.xml +++ b/src/Nox.ClientApi.Tests/ServiceMetadata/oDataMetadata.xml @@ -1,643 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Nox.ClientApi.Tests/Tests/Application/CommandHandlers/CreateCountryCommandHandlerTests.cs b/src/Nox.ClientApi.Tests/Tests/Application/CommandHandlers/CreateCountryCommandHandlerTests.cs index 2e74e412ab..b0b8fd7f26 100644 --- a/src/Nox.ClientApi.Tests/Tests/Application/CommandHandlers/CreateCountryCommandHandlerTests.cs +++ b/src/Nox.ClientApi.Tests/Tests/Application/CommandHandlers/CreateCountryCommandHandlerTests.cs @@ -1,14 +1,13 @@ using FluentAssertions; -using ClientApi.Application.Dto; using Xunit.Abstractions; +using ClientApi.Tests.Controllers; +using ClientApi.Application.Dto; namespace ClientApi.Tests.Application.CommandHandlers; [Collection("CreateCountryCommandHandlerTests")] public class CreateCountryCommandHandlerTests : NoxWebApiTestBase { - private const string CountryControllerName = "api/countries"; - public CreateCountryCommandHandlerTests( ITestOutputHelper testOutputHelper, TestDatabaseContainerService containerService) : base(testOutputHelper, containerService) @@ -36,9 +35,9 @@ public async Task Put_PopulationNegative_ShouldUpdateTo0() }; // Act - var postResult = await PostAsync(CountryControllerName, countryDto); + var postResult = await PostAsync(Endpoints.CountriesUrl, countryDto); var headers = CreateEtagHeader(postResult?.Etag); - var putResult = await PutAsync($"{CountryControllerName}/{postResult!.Id}", countryUpdateDto, headers); + var putResult = await PutAsync($"{Endpoints.CountriesUrl}/{postResult!.Id}", countryUpdateDto, headers); //Assert @@ -63,7 +62,7 @@ public async Task Put_Name_ShouldEnsureTitelize() }; // Act - var result = await PostAsync(CountryControllerName, countryDto); + var result = await PostAsync(Endpoints.CountriesUrl, countryDto); //Assert result.Should().NotBeNull(); diff --git a/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsStagingEnvTests.cs b/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsStagingEnvTests.cs index 1847836bbd..94880a0059 100644 --- a/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsStagingEnvTests.cs +++ b/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsStagingEnvTests.cs @@ -1,18 +1,18 @@ using AutoFixture; -using ClientApi.Application.Dto; -using ClientApi.Application.IntegrationEvents; using FluentAssertions; using MassTransit.Testing; -using Nox.Infrastructure.Messaging; using Xunit.Abstractions; +using Nox.Infrastructure.Messaging; +using ClientApi.Tests.Controllers; +using ClientApi.Application.Dto; +using ClientApi.Application.IntegrationEvents; + namespace ClientApi.Tests.Application.Messaging { [Collection("Sequential")] public class IntegrationEventsStagingEnvTests : NoxWebApiTestBase - { - private const string CountriesControllerName = "api/countries"; - + { public IntegrationEventsStagingEnvTests( ITestOutputHelper testOutput, TestDatabaseContainerService containerService) @@ -30,7 +30,7 @@ public async Task Put_Country_WithDevelopmentEnvironment_SetsEnvelopValuesProper Population = 99_999_999, }; - var createResult = await PostAsync(CountriesControllerName, createDto); + var createResult = await PostAsync(Endpoints.CountriesUrl, createDto); var updateDto = new CountryUpdateDto { @@ -40,7 +40,7 @@ public async Task Put_Country_WithDevelopmentEnvironment_SetsEnvelopValuesProper // Act var headers = CreateEtagHeader(createResult?.Etag); - var updateResult = await PutAsync($"{CountriesControllerName}/{createResult!.Id}", updateDto, headers); + var updateResult = await PutAsync($"{Endpoints.CountriesUrl}/{createResult!.Id}", updateDto, headers); //Assert updateResult.Should().NotBeNull(); diff --git a/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsTests.cs b/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsTests.cs index 38d37e46e0..ecbf0aada7 100644 --- a/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsTests.cs +++ b/src/Nox.ClientApi.Tests/Tests/Application/Messaging/IntegrationEventsTests.cs @@ -13,10 +13,6 @@ namespace ClientApi.Tests.Application.Messaging [Collection("Sequential")] public class IntegrationEventsTests : NoxWebApiTestBase { - private const string StoreOwnersControllerName = "api/storeowners"; - private const string CountriesControllerName = "api/countries"; - private const string WorkplacesControllerName = "api/workplaces"; - public IntegrationEventsTests( ITestOutputHelper testOutput, TestDatabaseContainerService containerService @@ -41,7 +37,7 @@ public async Task Post_StoreOwner_SendsCustomIntegrationEvent() }; // Act - var result = await PostAsync(StoreOwnersControllerName, createDto); + var result = await PostAsync(Endpoints.StoreOwnersUrl, createDto); //Assert result.Should().NotBeNull(); @@ -60,7 +56,7 @@ public async Task Post_Country_SendsIntegrationEvents() }; // Act - var result = await PostAsync(CountriesControllerName, createDto); + var result = await PostAsync(Endpoints.CountriesUrl, createDto); //Assert result.Should().NotBeNull(); @@ -78,7 +74,7 @@ public async Task Put_Country_SendsIntegrationEvents() Population = 99_999_999, }; - var createResult = await PostAsync(CountriesControllerName, createDto); + var createResult = await PostAsync(Endpoints.CountriesUrl, createDto); var updateDto = new CountryUpdateDto { @@ -88,7 +84,7 @@ public async Task Put_Country_SendsIntegrationEvents() // Act var headers = CreateEtagHeader(createResult?.Etag); - var updateResult = await PutAsync($"{CountriesControllerName}/{createResult!.Id}", updateDto, headers); + var updateResult = await PutAsync($"{Endpoints.CountriesUrl}/{createResult!.Id}", updateDto, headers); //Assert updateResult.Should().NotBeNull(); @@ -107,11 +103,11 @@ public async Task Delete_Country_SendsIntegrationEvents() Population = 99_999_999, }; - var createResult = await PostAsync(CountriesControllerName, createDto); + var createResult = await PostAsync(Endpoints.CountriesUrl, createDto); // Act var headers = CreateEtagHeader(createResult?.Etag); - var deleteResult = await DeleteAsync($"{CountriesControllerName}/{createResult!.Id}", headers); + var deleteResult = await DeleteAsync($"{Endpoints.CountriesUrl}/{createResult!.Id}", headers); //Assert deleteResult.Should().NotBeNull(); @@ -138,11 +134,11 @@ public async Task Delete_Workplace_SendsIntegrationEvents() CountryId = countryId, }; - var createResult = await PostAsync(WorkplacesControllerName, createDto); + var createResult = await PostAsync(Endpoints.WorkplacesUrl, createDto); // Act var headers = CreateEtagHeader(createResult?.Etag); - var deleteResult = await DeleteAsync($"{WorkplacesControllerName}/{createResult!.Id}", headers); + var deleteResult = await DeleteAsync($"{Endpoints.WorkplacesUrl}/{createResult!.Id}", headers); //Assert deleteResult.Should().NotBeNull(); @@ -161,7 +157,7 @@ public async Task Put_Country_SetsMessageValuesProperly() Population = 99_999_999, }; - var createResult = await PostAsync(CountriesControllerName, createDto); + var createResult = await PostAsync(Endpoints.CountriesUrl, createDto); var updateDto = new CountryUpdateDto { @@ -171,7 +167,7 @@ public async Task Put_Country_SetsMessageValuesProperly() // Act var headers = CreateEtagHeader(createResult?.Etag); - var updateResult = await PutAsync($"{CountriesControllerName}/{createResult!.Id}", updateDto, headers); + var updateResult = await PutAsync($"{Endpoints.CountriesUrl}/{createResult!.Id}", updateDto, headers); //Assert updateResult.Should().NotBeNull(); diff --git a/src/Nox.ClientApi.Tests/Tests/Application/Query/GetCountryByIdQueryValidatorTests.cs b/src/Nox.ClientApi.Tests/Tests/Application/Query/GetCountryByIdQueryValidatorTests.cs index 88c400f2b1..f1a96f80da 100644 --- a/src/Nox.ClientApi.Tests/Tests/Application/Query/GetCountryByIdQueryValidatorTests.cs +++ b/src/Nox.ClientApi.Tests/Tests/Application/Query/GetCountryByIdQueryValidatorTests.cs @@ -4,14 +4,13 @@ using System.Net; using ClientApi.Tests.Tests.Models; using Xunit.Abstractions; +using ClientApi.Tests.Controllers; namespace ClientApi.Tests.Tests.Controllers { [Collection("Sequential")] public class GetCountryByIdQueryValidatorTests : NoxWebApiTestBase - { - private const string CountryControllerName = "api/countries"; - + { public GetCountryByIdQueryValidatorTests( ITestOutputHelper testOutputHelper, TestDatabaseContainerService containerService) @@ -26,7 +25,7 @@ public GetCountryByIdQueryValidatorTests( public async Task Get_CountriesWithKeyGreaterThen300_ShouldFailSecurityValidation() { // Act - var result = await GetAsync($"{CountryControllerName}/301"); + var result = await GetAsync($"{Endpoints.CountriesUrl}/301"); var response = await result.Content.ReadFromJsonAsync(); // Assert response!.StatusCode.Should().Be(HttpStatusCode.BadRequest); @@ -50,11 +49,11 @@ public async Task Get_AllCountries_ShouldReturnAllWithKeysLowerThen300() Name = _fixture.Create(), Population = i * 1000000 }; - await PostAsync(CountryControllerName, countryDto); + await PostAsync(Endpoints.CountriesUrl, countryDto); } // Act - var result = await GetODataCollectionResponseAsync>(CountryControllerName); + var result = await GetODataCollectionResponseAsync>(Endpoints.CountriesUrl); //Assert result!.Should().HaveCount(expectedCount); diff --git a/src/Nox.ClientApi.Tests/Tests/Controllers/CountryQualityOfLifeIndexControllerTests.cs b/src/Nox.ClientApi.Tests/Tests/Controllers/CountryQualityOfLifeIndexControllerTests.cs index 053b46d582..139cfdde47 100644 --- a/src/Nox.ClientApi.Tests/Tests/Controllers/CountryQualityOfLifeIndexControllerTests.cs +++ b/src/Nox.ClientApi.Tests/Tests/Controllers/CountryQualityOfLifeIndexControllerTests.cs @@ -4,6 +4,7 @@ using Nox.Types; using System.Net; using Xunit.Abstractions; +using ClientApi.Tests.Controllers; namespace ClientApi.Tests.Tests.Controllers { @@ -11,8 +12,7 @@ namespace ClientApi.Tests.Tests.Controllers public class CountryQualityOfLifeIndexControllerTests : NoxWebApiTestBase { private const string EntityPluralName = "CountryQualityOfLifeIndices"; - private const string EntityUrl = $"api/{EntityPluralName}"; - private const string CountriesUrl = $"api/countries"; + private const string EntityUrl = $"En/{EntityPluralName}"; public CountryQualityOfLifeIndexControllerTests(ITestOutputHelper testOutput, TestDatabaseContainerService containerService) : base(testOutput, containerService) @@ -31,7 +31,7 @@ public async Task Post_CountryQualityOfLifeIndex_Success() Population = 1_000_000 }; - var countryResponse = await PostAsync(CountriesUrl, countryDto); + var countryResponse = await PostAsync(Endpoints.CountriesUrl, countryDto); var indexDto = new CountryQualityOfLifeIndexCreateDto { @@ -40,7 +40,7 @@ public async Task Post_CountryQualityOfLifeIndex_Success() }; // Act - var indexResponse = await PostAsync(EntityUrl, indexDto); + var indexResponse = await PostAsync(Endpoints.CountryQualityOfLifeIndicesUrl, indexDto); //Assert indexResponse.Should().NotBeNull(); @@ -59,7 +59,7 @@ public async Task Post_IndexWithInvalidCountryId_Fails() }; // Act - var result = await PostAsync(EntityUrl, indexDto); + var result = await PostAsync(Endpoints.CountryQualityOfLifeIndicesUrl, indexDto); //Assert result.StatusCode.Should().Be(HttpStatusCode.InternalServerError); diff --git a/src/Nox.ClientApi.Tests/Tests/Controllers/Endpoints.cs b/src/Nox.ClientApi.Tests/Tests/Controllers/Endpoints.cs index 452001ed9e..a457d12a8f 100644 --- a/src/Nox.ClientApi.Tests/Tests/Controllers/Endpoints.cs +++ b/src/Nox.ClientApi.Tests/Tests/Controllers/Endpoints.cs @@ -2,13 +2,16 @@ { public static class Endpoints { - public const string CountriesUrl = $"api/countries"; - public const string StoreLicensesUrl = "api/storelicenses"; - public const string StoreOwnersUrl = "api/storeowners"; - public const string StoresUrl = "api/stores"; - public const string WorkplacesUrl = $"api/workplaces"; - public const string RatingProgramsUrl = $"api/ratingprograms"; - public const string CurrenciesUrl = $"api/currencies"; - public const string TeanantUrl = $"api/tenants"; + public const string RoutePrefix = "/api/v1"; + public const string CountriesUrl = $"{RoutePrefix}/countries"; + public const string StoreLicensesUrl = $"{RoutePrefix}/storelicenses"; + public const string StoreOwnersUrl = $"{RoutePrefix}/storeowners"; + public const string StoresUrl = $"{RoutePrefix}/stores"; + public const string WorkplacesUrl = $"{RoutePrefix}/workplaces"; + public const string RatingProgramsUrl = $"{RoutePrefix}/ratingprograms"; + public const string CurrenciesUrl = $"{RoutePrefix}/currencies"; + public const string TeanantUrl = $"{RoutePrefix}/tenants"; + public const string CountryQualityOfLifeIndicesUrl = $"{RoutePrefix}/CountryQualityOfLifeIndices"; + } } diff --git a/src/Nox.Generator/Presentation/Api/OData/EntityController.Enumerations.template.cs b/src/Nox.Generator/Presentation/Api/OData/EntityController.Enumerations.template.cs index a95ffc4997..92f88db175 100644 --- a/src/Nox.Generator/Presentation/Api/OData/EntityController.Enumerations.template.cs +++ b/src/Nox.Generator/Presentation/Api/OData/EntityController.Enumerations.template.cs @@ -11,7 +11,7 @@ namespace {{ codeGeneratorState.ODataNameSpace }}; public abstract partial class {{ entity.PluralName }}ControllerBase { {{- for enumAtt in enumerationAttributes }} - [HttpGet("api/{{entity.PluralName}}/{{entity.Name}}{{Pluralize (enumAtt.Attribute.Name)}}")] + [HttpGet("{{solution.Infrastructure.Endpoints.ApiRoutePrefix}}/{{entity.PluralName}}/{{entity.Name}}{{Pluralize (enumAtt.Attribute.Name)}}")] public virtual async Task>> Get{{Pluralize (enumAtt.Attribute.Name)}}NonConventional() { var result = await _mediator.Send(new ApplicationQueriesNameSpace.Get{{(entity.PluralName)}}{{Pluralize (enumAtt.Attribute.Name)}}Query()); diff --git a/src/Nox.Generator/Presentation/Api/OData/EntityControllerGenerator.cs b/src/Nox.Generator/Presentation/Api/OData/EntityControllerGenerator.cs index f6329858ec..9dacbcf590 100644 --- a/src/Nox.Generator/Presentation/Api/OData/EntityControllerGenerator.cs +++ b/src/Nox.Generator/Presentation/Api/OData/EntityControllerGenerator.cs @@ -1,11 +1,8 @@ -using Humanizer; -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; using Nox.Generator.Common; using Nox.Solution; using Nox.Solution.Extensions; -using Nox.Types.Extensions; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using static Nox.Generator.Common.BaseGenerator; @@ -200,7 +197,7 @@ private static void GeneratePrivateChildrenGetById(NoxSolution solution, EntityR private static void GenerateChildrenGetById(NoxSolution solution, EntityRelationship relationship, Entity child, Entity parent, CodeBuilder code) { code.AppendLine($"[EnableQuery]"); - code.AppendLine($"[HttpGet(\"api/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); + code.AppendLine($"[HttpGet(\"{solution.Infrastructure.Endpoints.ApiRoutePrefix}/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); code.AppendLine($"public virtual async Task> Get{relationship.Name}NonConventional(" + $"{GetPrimaryKeysRoute(parent, solution, attributePrefix: "")}, " + $"{GetPrimaryKeysRoute(child, solution, "relatedKey", "")})"); @@ -309,7 +306,7 @@ private static void GenerateChildrenPut(NoxSolution solution, EntityRelationship } else { - code.AppendLine($"[HttpPut(\"api/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); + code.AppendLine($"[HttpPut(\"{solution.Infrastructure.Endpoints.ApiRoutePrefix}/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); code.AppendLine($"public virtual async Task> PutTo{child.PluralName}NonConventional(" + $"{GetPrimaryKeysRoute(parent, solution, attributePrefix: "")}, " + $"{GetPrimaryKeysRoute(child, solution, "relatedKey", "")}, " + @@ -372,7 +369,7 @@ private static void GenerateChildrenPatch(NoxSolution solution, EntityRelationsh } else { - code.AppendLine($"[HttpPatch(\"api/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); + code.AppendLine($"[HttpPatch(\"{solution.Infrastructure.Endpoints.ApiRoutePrefix}/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); code.AppendLine($"public virtual async Task PatchTo{child.PluralName}NonConventional(" + $"{GetPrimaryKeysRoute(parent, solution, attributePrefix: "")}, " + $"{GetPrimaryKeysRoute(child, solution, "relatedKey", "")}, " + @@ -439,13 +436,13 @@ private static void GenerateChildrenDelete(NoxSolution solution, EntityRelations if (isSingleRelationship) { - code.AppendLine($"[HttpDelete(\"api/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}\")]"); + code.AppendLine($"[HttpDelete(\"{solution.Infrastructure.Endpoints.ApiRoutePrefix}/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}\")]"); code.AppendLine($"public virtual async Task Delete{child.Name}NonConventional(" + $"{GetPrimaryKeysRoute(parent, solution, attributePrefix: "")})"); } else { - code.AppendLine($"[HttpDelete(\"api/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); + code.AppendLine($"[HttpDelete(\"{solution.Infrastructure.Endpoints.ApiRoutePrefix}/{parent.PluralName}/{PrimaryKeysAttribute(parent)}/{relationship.Name}/{PrimaryKeysAttribute(child, "relatedKey")}\")]"); code.AppendLine($"public virtual async Task Delete{child.Name}NonConventional(" + $"{GetPrimaryKeysRoute(parent, solution, attributePrefix: "")}, " + $"{GetPrimaryKeysRoute(child, solution, "relatedKey", "")})"); @@ -684,7 +681,7 @@ private static void GenerateRelatedPut(NoxSolution solution, EntityRelationship } else { - code.AppendLine($"[HttpPut(\"api/{entity.PluralName}/{PrimaryKeysAttribute(entity)}/{relationshipName}/{PrimaryKeysAttribute(relatedEntity, "relatedKey")}\")]"); + code.AppendLine($"[HttpPut(\"{solution.Infrastructure.Endpoints.ApiRoutePrefix}/{entity.PluralName}/{PrimaryKeysAttribute(entity)}/{relationshipName}/{PrimaryKeysAttribute(relatedEntity, "relatedKey")}\")]"); code.AppendLine($"public virtual async Task> PutTo{relationshipName}NonConventional(" + $"{GetPrimaryKeysRoute(entity, solution, attributePrefix: "")}, " + $"{GetPrimaryKeysRoute(relatedEntity, solution, "relatedKey", "")}, " + diff --git a/src/Nox.Generator/Presentation/Api/OData/ODataServiceCollectionExtensions.template.cs b/src/Nox.Generator/Presentation/Api/OData/ODataServiceCollectionExtensions.template.cs index 41828bda2d..1a633d6abb 100644 --- a/src/Nox.Generator/Presentation/Api/OData/ODataServiceCollectionExtensions.template.cs +++ b/src/Nox.Generator/Presentation/Api/OData/ODataServiceCollectionExtensions.template.cs @@ -84,7 +84,7 @@ public static void AddNoxOdata(this IServiceCollection services, Action service .AddSingleton()) .RouteOptions; diff --git a/src/Nox.Lib/Presentation/Api/OData/ODataApi.cs b/src/Nox.Lib/Presentation/Api/OData/ODataApi.cs new file mode 100644 index 0000000000..72d74b465b --- /dev/null +++ b/src/Nox.Lib/Presentation/Api/OData/ODataApi.cs @@ -0,0 +1,16 @@ + +using Nox.Solution; + +namespace Nox.Presentation.Api.OData +{ + public static class ODataApi + { + /// + /// Transform the route prefix defined in NoxSolution to a valid OData API route. + /// + public static string GetRoutePrefix(string apiRoutePrefix) + { + return apiRoutePrefix.TrimStart('/'); + } + } +} diff --git a/src/Nox.Solution/Models/Infrastructure/Endpoints/Endpoints.cs b/src/Nox.Solution/Models/Infrastructure/Endpoints/Endpoints.cs index 6b859f4be5..65ac74c965 100644 --- a/src/Nox.Solution/Models/Infrastructure/Endpoints/Endpoints.cs +++ b/src/Nox.Solution/Models/Infrastructure/Endpoints/Endpoints.cs @@ -11,20 +11,20 @@ public class Endpoints { [Title("The api route prefix, defaults to api/v1 or to api/vMajor({Solution.Version}) if Version is set in the root of the Solution.")] [Description(@"Defines the prefix for all Api routes end points.")] - public string ApiRootPrefix { get; internal set; } = null!; + public string ApiRoutePrefix { get; internal set; } = null!; public ApiServer? ApiServer { get; internal set; } public BffServer? BffServer { get; internal set; } public void ApplyDefaults(string solutionVersion) { - if (ApiRootPrefix is null || string.IsNullOrEmpty(ApiRootPrefix)) + if (ApiRoutePrefix is null || string.IsNullOrEmpty(ApiRoutePrefix)) { - ApiRootPrefix = "/api/v" + new Version(solutionVersion).Major; + ApiRoutePrefix = "/api/v" + new Version(solutionVersion).Major; return; } else { - ApiRootPrefix = SanitizeRoutePrefix(ApiRootPrefix); + ApiRoutePrefix = SanitizeRoutePrefix(ApiRoutePrefix); } } /// @@ -35,8 +35,15 @@ public void ApplyDefaults(string solutionVersion) private static string SanitizeRoutePrefix(string routePrefix) { Debug.Assert(routePrefix != null); - - if(!routePrefix!.StartsWith("/")) + if(string.IsNullOrEmpty(routePrefix)) + { + return "/"; + } + if (routePrefix == "/") + { + return routePrefix; + } + if (!routePrefix!.StartsWith("/")) { routePrefix = "/" + routePrefix; } diff --git a/tests/Nox.Generator.Tests/ExpectedGeneratedFiles/Presentation.Api.OData.CountriesController.g.cs b/tests/Nox.Generator.Tests/ExpectedGeneratedFiles/Presentation.Api.OData.CountriesController.g.cs index cd61a94082..336c659db6 100644 --- a/tests/Nox.Generator.Tests/ExpectedGeneratedFiles/Presentation.Api.OData.CountriesController.g.cs +++ b/tests/Nox.Generator.Tests/ExpectedGeneratedFiles/Presentation.Api.OData.CountriesController.g.cs @@ -51,7 +51,7 @@ public virtual async Task>> GetCoun } [EnableQuery] - [HttpGet("api/Countries/{key}/CountryLocalNames/{relatedKey}")] + [HttpGet("/api/v1/Countries/{key}/CountryLocalNames/{relatedKey}")] public virtual async Task> GetCountryLocalNamesNonConventional(System.String key, System.String relatedKey) { if (!ModelState.IsValid) @@ -90,7 +90,7 @@ public virtual async Task PostToCountryLocalNames([FromRoute] Syst return Created(child); } - [HttpDelete("api/Countries/{key}/CountryLocalNames/{relatedKey}")] + [HttpDelete("/api/v1/Countries/{key}/CountryLocalNames/{relatedKey}")] public virtual async Task DeleteCountryLocalNameNonConventional(System.String key, System.String relatedKey) { if (!ModelState.IsValid) diff --git a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs index 6adbe6117e..af7968801f 100644 --- a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs +++ b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/ODataServiceCollectionExtensions.g.cs @@ -321,7 +321,7 @@ public static void AddNoxOdata(this IServiceCollection services, Action service .AddSingleton()) .RouteOptions; diff --git a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityForTypesController/Enumerations.g.cs b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityForTypesController/Enumerations.g.cs index fa4599d099..8408e88a87 100644 --- a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityForTypesController/Enumerations.g.cs +++ b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityForTypesController/Enumerations.g.cs @@ -10,7 +10,7 @@ namespace TestWebApp.Presentation.Api.OData; public abstract partial class TestEntityForTypesControllerBase { - [HttpGet("api/TestEntityForTypes/TestEntityForTypesEnumerationTestFields")] + [HttpGet("/api/v1/TestEntityForTypes/TestEntityForTypesEnumerationTestFields")] public virtual async Task>> GetEnumerationTestFieldsNonConventional() { var result = await _mediator.Send(new ApplicationQueriesNameSpace.GetTestEntityForTypesEnumerationTestFieldsQuery()); diff --git a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipExactlyOnesController.g.cs b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipExactlyOnesController.g.cs index 36dc9fb28d..fabf97e7b1 100644 --- a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipExactlyOnesController.g.cs +++ b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipExactlyOnesController.g.cs @@ -123,7 +123,7 @@ public virtual async Task PatchToSecondTestEntityOwnedRelationship return Ok(child); } - [HttpDelete("api/TestEntityOwnedRelationshipExactlyOnes/{key}/SecondTestEntityOwnedRelationshipExactlyOne")] + [HttpDelete("/api/v1/TestEntityOwnedRelationshipExactlyOnes/{key}/SecondTestEntityOwnedRelationshipExactlyOne")] public virtual async Task DeleteSecondTestEntityOwnedRelationshipExactlyOneNonConventional(System.String key) { if (!ModelState.IsValid) diff --git a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipOneOrManiesController.g.cs b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipOneOrManiesController.g.cs index b9428c838b..1f3af23b14 100644 --- a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipOneOrManiesController.g.cs +++ b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipOneOrManiesController.g.cs @@ -46,7 +46,7 @@ public virtual async Task> GetSecondTestEntityOwnedRelationshipOneOrManyNonConventional(System.String key, System.String relatedKey) { if (!ModelState.IsValid) @@ -85,7 +85,7 @@ public virtual async Task PostToSecondTestEntityOwnedRelationshipO return Created(child); } - [HttpPut("api/TestEntityOwnedRelationshipOneOrManies/{key}/SecondTestEntityOwnedRelationshipOneOrMany/{relatedKey}")] + [HttpPut("/api/v1/TestEntityOwnedRelationshipOneOrManies/{key}/SecondTestEntityOwnedRelationshipOneOrMany/{relatedKey}")] public virtual async Task> PutToSecondTestEntityOwnedRelationshipOneOrManiesNonConventional(System.String key, System.String relatedKey, [FromBody] SecondTestEntityOwnedRelationshipOneOrManyUpdateDto secondTestEntityOwnedRelationshipOneOrMany) { if (!ModelState.IsValid) @@ -109,7 +109,7 @@ public virtual async Task PatchToSecondTestEntityOwnedRelationshipOneOrManiesNonConventional(System.String key, System.String relatedKey, [FromBody] Delta secondTestEntityOwnedRelationshipOneOrMany) { if (!ModelState.IsValid) @@ -142,7 +142,7 @@ public virtual async Task PatchToSecondTestEntityOwnedRelationship return Ok(child); } - [HttpDelete("api/TestEntityOwnedRelationshipOneOrManies/{key}/SecondTestEntityOwnedRelationshipOneOrMany/{relatedKey}")] + [HttpDelete("/api/v1/TestEntityOwnedRelationshipOneOrManies/{key}/SecondTestEntityOwnedRelationshipOneOrMany/{relatedKey}")] public virtual async Task DeleteSecondTestEntityOwnedRelationshipOneOrManyNonConventional(System.String key, System.String relatedKey) { if (!ModelState.IsValid) diff --git a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrManiesController.g.cs b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrManiesController.g.cs index 62a8dcbd2a..1f7d11c7b2 100644 --- a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrManiesController.g.cs +++ b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrManiesController.g.cs @@ -46,7 +46,7 @@ public virtual async Task> GetSecondTestEntityOwnedRelationshipZeroOrManyNonConventional(System.String key, System.String relatedKey) { if (!ModelState.IsValid) @@ -85,7 +85,7 @@ public virtual async Task PostToSecondTestEntityOwnedRelationshipZ return Created(child); } - [HttpPut("api/TestEntityOwnedRelationshipZeroOrManies/{key}/SecondTestEntityOwnedRelationshipZeroOrMany/{relatedKey}")] + [HttpPut("/api/v1/TestEntityOwnedRelationshipZeroOrManies/{key}/SecondTestEntityOwnedRelationshipZeroOrMany/{relatedKey}")] public virtual async Task> PutToSecondTestEntityOwnedRelationshipZeroOrManiesNonConventional(System.String key, System.String relatedKey, [FromBody] SecondTestEntityOwnedRelationshipZeroOrManyUpdateDto secondTestEntityOwnedRelationshipZeroOrMany) { if (!ModelState.IsValid) @@ -109,7 +109,7 @@ public virtual async Task PatchToSecondTestEntityOwnedRelationshipZeroOrManiesNonConventional(System.String key, System.String relatedKey, [FromBody] Delta secondTestEntityOwnedRelationshipZeroOrMany) { if (!ModelState.IsValid) @@ -142,7 +142,7 @@ public virtual async Task PatchToSecondTestEntityOwnedRelationship return Ok(child); } - [HttpDelete("api/TestEntityOwnedRelationshipZeroOrManies/{key}/SecondTestEntityOwnedRelationshipZeroOrMany/{relatedKey}")] + [HttpDelete("/api/v1/TestEntityOwnedRelationshipZeroOrManies/{key}/SecondTestEntityOwnedRelationshipZeroOrMany/{relatedKey}")] public virtual async Task DeleteSecondTestEntityOwnedRelationshipZeroOrManyNonConventional(System.String key, System.String relatedKey) { if (!ModelState.IsValid) diff --git a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrOnesController.g.cs b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrOnesController.g.cs index daa764743d..2bb7cb944a 100644 --- a/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrOnesController.g.cs +++ b/tests/Nox.Integration.Tests/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Presentation.Api.OData/TestEntityOwnedRelationshipZeroOrOnesController.g.cs @@ -123,7 +123,7 @@ public virtual async Task PatchToSecondTestEntityOwnedRelationship return Ok(child); } - [HttpDelete("api/TestEntityOwnedRelationshipZeroOrOnes/{key}/SecondTestEntityOwnedRelationshipZeroOrOne")] + [HttpDelete("/api/v1/TestEntityOwnedRelationshipZeroOrOnes/{key}/SecondTestEntityOwnedRelationshipZeroOrOne")] public virtual async Task DeleteSecondTestEntityOwnedRelationshipZeroOrOneNonConventional(System.String key) { if (!ModelState.IsValid) diff --git a/tests/Nox.Lib.Tests/Presentation/Api/OData/ODataApiTests.cs b/tests/Nox.Lib.Tests/Presentation/Api/OData/ODataApiTests.cs new file mode 100644 index 0000000000..5812e0a03d --- /dev/null +++ b/tests/Nox.Lib.Tests/Presentation/Api/OData/ODataApiTests.cs @@ -0,0 +1,18 @@ +using FluentAssertions; +using Nox.Presentation.Api.OData; + +namespace Nox.Lib.Tests.Presentation.Api.OData +{ + public class ODataApiTests + { + [Theory] + [InlineData("/odata", "odata")] + [InlineData("odata", "odata")] + [InlineData("/odata/v1", "odata/v1")] + [InlineData("odata/v1", "odata/v1")] + public void WhenRoutePrefixStartBySlash_ShouldRemoveIt(string routePrefix, string expectedODataRoutePrefix) + { + ODataApi.GetRoutePrefix(routePrefix).Should().Be(expectedODataRoutePrefix); + } + } +} \ No newline at end of file diff --git a/tests/Nox.Solution.Tests/Models/Infrastructure/Endpoints/EndPointsTests.cs b/tests/Nox.Solution.Tests/Models/Infrastructure/Endpoints/EndPointsTests.cs index 9ea26c7dce..47bc39aea1 100644 --- a/tests/Nox.Solution.Tests/Models/Infrastructure/Endpoints/EndPointsTests.cs +++ b/tests/Nox.Solution.Tests/Models/Infrastructure/Endpoints/EndPointsTests.cs @@ -13,7 +13,7 @@ public void WhenNoEndPointOrVersionIsDefined_ShouldApplyDefaultsV1() .Build(); solution.Infrastructure.Endpoints.Should().NotBeNull(); - solution.Infrastructure.Endpoints.ApiRootPrefix.Should().Be("/api/v1"); + solution.Infrastructure.Endpoints.ApiRoutePrefix.Should().Be("/api/v1"); } [Fact] public void WhenNoEndPointWithVersion2Defined_ShouldApplyDefaultsV2() @@ -24,11 +24,11 @@ public void WhenNoEndPointWithVersion2Defined_ShouldApplyDefaultsV2() .Build(); solution.Infrastructure.Endpoints.Should().NotBeNull(); - solution.Infrastructure.Endpoints.ApiRootPrefix.Should().Be("/api/v2"); + solution.Infrastructure.Endpoints.ApiRoutePrefix.Should().Be("/api/v2"); } [Fact] - public void WhenApiRootPrefixSet_ShouldReturnIt() + public void WhenApiRoutePrefixSet_ShouldReturnIt() { var solution = new NoxSolutionBuilder() .UseYamlFile("./files/endpoints.routeprefix.solution.nox.yaml") @@ -36,10 +36,10 @@ public void WhenApiRootPrefixSet_ShouldReturnIt() .Build(); solution.Infrastructure.Endpoints.Should().NotBeNull(); - solution.Infrastructure.Endpoints.ApiRootPrefix.Should().Be("/testapi"); + solution.Infrastructure.Endpoints.ApiRoutePrefix.Should().Be("/testapi"); } [Fact] - public void WhenApiRootPrefixSet_ShouldSanitizeIt() + public void WhenApiRoutePrefixSet_ShouldSanitizeIt() { var solution = new NoxSolutionBuilder() .UseYamlFile("./files/endpoints.routeprefix.sanitized.solution.nox.yaml") @@ -47,10 +47,22 @@ public void WhenApiRootPrefixSet_ShouldSanitizeIt() .Build(); solution.Infrastructure.Endpoints.Should().NotBeNull(); - solution.Infrastructure.Endpoints.ApiRootPrefix.Should().Be("/testapi"); + solution.Infrastructure.Endpoints.ApiRoutePrefix.Should().Be("/testapi"); } [Fact] - public void WhenApiRootNoPrefix_ShouldBeEmpty() + public void WhenApiRoutePrefixRoot_ShouldBeRoot() + { + var solution = new NoxSolutionBuilder() + .UseYamlFile("./files/endpoints.root.routeprefix.solution.nox.yaml") + .AllowMissingSolutionYaml() + .Build(); + + solution.Infrastructure.Endpoints.Should().NotBeNull(); + solution.Infrastructure.Endpoints.ApiRoutePrefix.Should().Be("/"); + } + + [Fact] + public void WhenApiRouteNoPrefix_ShouldBeDefault() { var solution = new NoxSolutionBuilder() .UseYamlFile("./files/endpoints.no.routeprefix.solution.nox.yaml") @@ -58,7 +70,7 @@ public void WhenApiRootNoPrefix_ShouldBeEmpty() .Build(); solution.Infrastructure.Endpoints.Should().NotBeNull(); - solution.Infrastructure.Endpoints.ApiRootPrefix.Should().BeEmpty("/"); + solution.Infrastructure.Endpoints.ApiRoutePrefix.Should().Be("/api/v1"); } } } diff --git a/tests/Nox.Solution.Tests/files/endpoints.no.routeprefix.solution.nox.yaml b/tests/Nox.Solution.Tests/files/endpoints.no.routeprefix.solution.nox.yaml index 21f02611f2..fc1d86a8d8 100644 --- a/tests/Nox.Solution.Tests/files/endpoints.no.routeprefix.solution.nox.yaml +++ b/tests/Nox.Solution.Tests/files/endpoints.no.routeprefix.solution.nox.yaml @@ -9,13 +9,10 @@ name: SampleService platformId: "Nox" -version: "2.0" - description: Sample Nox solution yaml configuration - infrastructure: endpoints: - apiRootPrefix: / \ No newline at end of file + apiRoutePrefix: \ No newline at end of file diff --git a/tests/Nox.Solution.Tests/files/endpoints.root.routeprefix.solution.nox.yaml b/tests/Nox.Solution.Tests/files/endpoints.root.routeprefix.solution.nox.yaml new file mode 100644 index 0000000000..731c628cd2 --- /dev/null +++ b/tests/Nox.Solution.Tests/files/endpoints.root.routeprefix.solution.nox.yaml @@ -0,0 +1,21 @@ +# +# workplace.solution.nox.yaml +# +# yaml-language-server: $schema=../../../schemas/solution.json +# + + +name: SampleService + +platformId: "Nox" + +version: "2.0" + +description: Sample Nox solution yaml configuration + + +infrastructure: + + endpoints: + + apiRoutePrefix: / \ No newline at end of file diff --git a/tests/Nox.Solution.Tests/files/endpoints.routeprefix.sanitized.solution.nox.yaml b/tests/Nox.Solution.Tests/files/endpoints.routeprefix.sanitized.solution.nox.yaml index fc177ea780..32550d6908 100644 --- a/tests/Nox.Solution.Tests/files/endpoints.routeprefix.sanitized.solution.nox.yaml +++ b/tests/Nox.Solution.Tests/files/endpoints.routeprefix.sanitized.solution.nox.yaml @@ -18,4 +18,4 @@ infrastructure: endpoints: - apiRootPrefix: /testapi/ \ No newline at end of file + apiRoutePrefix: /testapi/ \ No newline at end of file diff --git a/tests/Nox.Solution.Tests/files/endpoints.routeprefix.solution.nox.yaml b/tests/Nox.Solution.Tests/files/endpoints.routeprefix.solution.nox.yaml index 304e854a35..991d73c1fe 100644 --- a/tests/Nox.Solution.Tests/files/endpoints.routeprefix.solution.nox.yaml +++ b/tests/Nox.Solution.Tests/files/endpoints.routeprefix.solution.nox.yaml @@ -18,4 +18,4 @@ infrastructure: endpoints: - apiRootPrefix: testapi \ No newline at end of file + apiRoutePrefix: testapi \ No newline at end of file