From 8fbc266fb9bf204b9fc9757a135fe41608ae354b Mon Sep 17 00:00:00 2001 From: ericuss Date: Thu, 1 Aug 2019 09:49:08 +0200 Subject: [PATCH] Migrated --- src/Services/Basket/Basket.API/Startup.cs | 13 ++++++++----- .../Base/BasketTestStartup.cs | 13 ++++++++++++- .../Basket.FunctionalTests.csproj | 3 +-- .../Basket/Basket.FunctionalTests/appsettings.json | 3 ++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 098428ad9..2533f31e5 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -15,6 +15,7 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; +using Microsoft.eShopOnContainers.Services.Basket.API.Controllers; using Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories; using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling; using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events; @@ -44,16 +45,18 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. - public IServiceProvider ConfigureServices(IServiceCollection services) + public virtual IServiceProvider ConfigureServices(IServiceCollection services) { RegisterAppInsights(services); services.AddControllers(options => - { - options.Filters.Add(typeof(HttpGlobalExceptionFilter)); - options.Filters.Add(typeof(ValidateModelStateFilter)); + { + options.Filters.Add(typeof(HttpGlobalExceptionFilter)); + options.Filters.Add(typeof(ValidateModelStateFilter)); - }).AddNewtonsoftJson(); + }) // Added for functional tests + .AddApplicationPart(typeof(BasketController).Assembly) + .AddNewtonsoftJson(); services.AddSwaggerGen(options => { diff --git a/src/Services/Basket/Basket.FunctionalTests/Base/BasketTestStartup.cs b/src/Services/Basket/Basket.FunctionalTests/Base/BasketTestStartup.cs index 4d77f6dc5..cb8ec8641 100644 --- a/src/Services/Basket/Basket.FunctionalTests/Base/BasketTestStartup.cs +++ b/src/Services/Basket/Basket.FunctionalTests/Base/BasketTestStartup.cs @@ -1,6 +1,9 @@ -using Microsoft.AspNetCore.Builder; +using System; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Routing; using Microsoft.eShopOnContainers.Services.Basket.API; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace Basket.FunctionalTests.Base { @@ -10,6 +13,14 @@ namespace Basket.FunctionalTests.Base { } + public override IServiceProvider ConfigureServices(IServiceCollection services) + { + // Added to avoid the Authorize data annotation in test environment. + // Property "SuppressCheckForUnhandledSecurityMetadata" in appsettings.json + services.Configure(Configuration); + return base.ConfigureServices(services); + } + protected override void ConfigureAuth(IApplicationBuilder app) { if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant()) diff --git a/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj b/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj index 168176aaf..269a133f2 100644 --- a/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj +++ b/src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj @@ -16,8 +16,7 @@ - - + diff --git a/src/Services/Basket/Basket.FunctionalTests/appsettings.json b/src/Services/Basket/Basket.FunctionalTests/appsettings.json index 5e8dbc02e..3f882d1bc 100644 --- a/src/Services/Basket/Basket.FunctionalTests/appsettings.json +++ b/src/Services/Basket/Basket.FunctionalTests/appsettings.json @@ -11,5 +11,6 @@ "ConnectionString": "127.0.0.1", "isTest": "true", "EventBusConnection": "localhost", - "SubscriptionClientName": "Basket" + "SubscriptionClientName": "Basket", + "SuppressCheckForUnhandledSecurityMetadata":true }