diff --git a/docker-compose-external.override.yml b/docker-compose-external.override.yml index 60764ca54..e20d2d949 100644 --- a/docker-compose-external.override.yml +++ b/docker-compose-external.override.yml @@ -1,9 +1,14 @@ -version: '2' +version: '3' services: sql.data: environment: - MSSQL_SA_PASSWORD=Pass@word - ACCEPT_EULA=Y + - MSSQL_PID=Developer ports: - - "5433:1433" \ No newline at end of file + - "5433:1433" + + nosql.data: + ports: + - "27017:27017" \ No newline at end of file diff --git a/docker-compose-external.yml b/docker-compose-external.yml index 8d8e0e760..9570696d2 100644 --- a/docker-compose-external.yml +++ b/docker-compose-external.yml @@ -13,3 +13,6 @@ services: image: rabbitmq ports: - "5672:5672" + + nosql.data: + image: mongo diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs index a6d482c26..a16acb0f3 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs @@ -28,6 +28,11 @@ namespace Ordering.API.Application.Commands public async Task Handle(CancelOrderCommand command) { var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber); + if(orderToUpdate == null) + { + return false; + } + orderToUpdate.SetCancelledStatus(); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs index d1fa6a71b..7755dae32 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs @@ -25,6 +25,11 @@ namespace Ordering.API.Application.Commands public async Task Handle(ShipOrderCommand command) { var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber); + if(orderToUpdate == null) + { + return false; + } + orderToUpdate.SetShippedStatus(); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } diff --git a/test/Services/FunctionalTests/Services/Basket/appsettings.json b/test/Services/FunctionalTests/Services/Basket/appsettings.json index 0d84f580e..f83d4de4b 100644 --- a/test/Services/FunctionalTests/Services/Basket/appsettings.json +++ b/test/Services/FunctionalTests/Services/Basket/appsettings.json @@ -10,7 +10,8 @@ "IdentityUrl": "http://localhost:5105", "ConnectionString": "127.0.0.1", "isTest": "true", - "EventBusConnection": "localhost" + "EventBusConnection": "localhost", + "SubscriptionClientName": "Basket" } diff --git a/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs b/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs index f5714afac..2d5daff6d 100644 --- a/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs +++ b/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs @@ -1,13 +1,13 @@ -using FunctionalTests.Middleware; -using Microsoft.AspNetCore; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; +using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; using Microsoft.eShopOnContainers.Services.Catalog.API; -using Microsoft.Extensions.Configuration; -using System; -using System.Collections.Generic; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System.IO; -using System.Text; namespace FunctionalTests.Services.Catalog { @@ -18,8 +18,23 @@ namespace FunctionalTests.Services.Catalog var webHostBuilder = WebHost.CreateDefaultBuilder(); webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory() + "\\Services\\Catalog"); webHostBuilder.UseStartup(); - - return new TestServer(webHostBuilder); + + var testServer = new TestServer(webHostBuilder); + + testServer.Host + .MigrateDbContext((context, services) => + { + var env = services.GetService(); + var settings = services.GetService>(); + var logger = services.GetService>(); + + new CatalogContextSeed() + .SeedAsync(context, env, settings, logger) + .Wait(); + }) + .MigrateDbContext((_, __) => { }); + + return testServer; } public static class Get diff --git a/test/Services/FunctionalTests/Services/Catalog/appsettings.json b/test/Services/FunctionalTests/Services/Catalog/appsettings.json index c814821c0..0cd61e36b 100644 --- a/test/Services/FunctionalTests/Services/Catalog/appsettings.json +++ b/test/Services/FunctionalTests/Services/Catalog/appsettings.json @@ -4,5 +4,6 @@ "IdentityUrl": "http://localhost:5105", "isTest": "true", "EventBusConnection": "localhost", - "PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/" + "PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/", + "SubscriptionClientName": "Catalog" } diff --git a/test/Services/FunctionalTests/Services/Location/appsettings.json b/test/Services/FunctionalTests/Services/Location/appsettings.json index 9769fb65a..977401adc 100644 --- a/test/Services/FunctionalTests/Services/Location/appsettings.json +++ b/test/Services/FunctionalTests/Services/Location/appsettings.json @@ -4,5 +4,6 @@ "ExternalCatalogBaseUrl": "http://localhost:5101", "IdentityUrl": "http://localhost:5105", "isTest": "true", - "EventBusConnection": "localhost" + "EventBusConnection": "localhost", + "SubscriptionClientName": "Location" } diff --git a/test/Services/FunctionalTests/Services/Marketing/MarketingScenariosBase.cs b/test/Services/FunctionalTests/Services/Marketing/MarketingScenariosBase.cs index 2920485f7..fe4f6c0cd 100644 --- a/test/Services/FunctionalTests/Services/Marketing/MarketingScenariosBase.cs +++ b/test/Services/FunctionalTests/Services/Marketing/MarketingScenariosBase.cs @@ -3,7 +3,9 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; - using Microsoft.Extensions.Configuration; + using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Logging; using System.IO; public class MarketingScenariosBase @@ -14,9 +16,21 @@ { var webHostBuilder = WebHost.CreateDefaultBuilder(); webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory() + "\\Services\\Marketing"); - webHostBuilder.UseStartup(); + webHostBuilder.UseStartup(); - return new TestServer(webHostBuilder); + var testServer = new TestServer(webHostBuilder); + + testServer.Host + .MigrateDbContext((context, services) => + { + var logger = services.GetService>(); + + new MarketingContextSeed() + .SeedAsync(context, logger) + .Wait(); + }); + + return testServer; } } } \ No newline at end of file diff --git a/test/Services/FunctionalTests/Services/Marketing/appsettings.json b/test/Services/FunctionalTests/Services/Marketing/appsettings.json index eae81073f..2aa46abe6 100644 --- a/test/Services/FunctionalTests/Services/Marketing/appsettings.json +++ b/test/Services/FunctionalTests/Services/Marketing/appsettings.json @@ -7,5 +7,6 @@ "EventBusConnection": "localhost", "AzureServiceBusEnabled": false, "SubscriptionClientName": "Marketing", - "PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/" + "PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/", + "SubscriptionClientName": "Marketing" } diff --git a/test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs b/test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs index d2a2dcfd9..b41f66fb9 100644 --- a/test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs +++ b/test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs @@ -1,11 +1,15 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; +using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; +using Microsoft.eShopOnContainers.Services.Ordering.API; +using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure; +using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; using Microsoft.Extensions.Configuration; -using System; -using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System.IO; -using System.Text; namespace FunctionalTests.Services.Ordering { @@ -21,8 +25,22 @@ namespace FunctionalTests.Services.Ordering config.AddJsonFile("settings.json"); }); + var testServer = new TestServer(webHostBuilder); - return new TestServer(webHostBuilder); + testServer.Host + .MigrateDbContext((context, services) => + { + var env = services.GetService(); + var settings = services.GetService>(); + var logger = services.GetService>(); + + new OrderingContextSeed() + .SeedAsync(context, env, settings, logger) + .Wait(); + }) + .MigrateDbContext((_, __) => { }); + + return testServer; } public static class Get diff --git a/test/Services/FunctionalTests/Services/Ordering/settings.json b/test/Services/FunctionalTests/Services/Ordering/settings.json index 072612e0f..70f1af3c0 100644 --- a/test/Services/FunctionalTests/Services/Ordering/settings.json +++ b/test/Services/FunctionalTests/Services/Ordering/settings.json @@ -5,5 +5,6 @@ "isTest": "true", "EventBusConnection": "localhost", "CheckUpdateTime": "30000", - "GracePeriodTime": "1" + "GracePeriodTime": "1", + "SubscriptionClientName": "Ordering" } diff --git a/test/Services/IntegrationTests/Services/Basket/appsettings.json b/test/Services/IntegrationTests/Services/Basket/appsettings.json index 0d84f580e..f83d4de4b 100644 --- a/test/Services/IntegrationTests/Services/Basket/appsettings.json +++ b/test/Services/IntegrationTests/Services/Basket/appsettings.json @@ -10,7 +10,8 @@ "IdentityUrl": "http://localhost:5105", "ConnectionString": "127.0.0.1", "isTest": "true", - "EventBusConnection": "localhost" + "EventBusConnection": "localhost", + "SubscriptionClientName": "Basket" } diff --git a/test/Services/IntegrationTests/Services/Catalog/CatalogScenarioBase.cs b/test/Services/IntegrationTests/Services/Catalog/CatalogScenarioBase.cs index fe1030a73..57d8c6ef1 100644 --- a/test/Services/IntegrationTests/Services/Catalog/CatalogScenarioBase.cs +++ b/test/Services/IntegrationTests/Services/Catalog/CatalogScenarioBase.cs @@ -3,7 +3,12 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; + using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; using Microsoft.eShopOnContainers.Services.Catalog.API; + using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; using System.IO; public class CatalogScenarioBase @@ -14,7 +19,22 @@ webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory() + "\\Services\\Catalog"); webHostBuilder.UseStartup(); - return new TestServer(webHostBuilder); + var testServer = new TestServer(webHostBuilder); + + testServer.Host + .MigrateDbContext((context, services) => + { + var env = services.GetService(); + var settings = services.GetService>(); + var logger = services.GetService>(); + + new CatalogContextSeed() + .SeedAsync(context, env, settings, logger) + .Wait(); + }) + .MigrateDbContext((_, __) => { }); + + return testServer; } public static class Get diff --git a/test/Services/IntegrationTests/Services/Catalog/appsettings.json b/test/Services/IntegrationTests/Services/Catalog/appsettings.json index c814821c0..0cd61e36b 100644 --- a/test/Services/IntegrationTests/Services/Catalog/appsettings.json +++ b/test/Services/IntegrationTests/Services/Catalog/appsettings.json @@ -4,5 +4,6 @@ "IdentityUrl": "http://localhost:5105", "isTest": "true", "EventBusConnection": "localhost", - "PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/" + "PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/", + "SubscriptionClientName": "Catalog" } diff --git a/test/Services/IntegrationTests/Services/Locations/appsettings.json b/test/Services/IntegrationTests/Services/Locations/appsettings.json index 9769fb65a..ee763ba96 100644 --- a/test/Services/IntegrationTests/Services/Locations/appsettings.json +++ b/test/Services/IntegrationTests/Services/Locations/appsettings.json @@ -4,5 +4,6 @@ "ExternalCatalogBaseUrl": "http://localhost:5101", "IdentityUrl": "http://localhost:5105", "isTest": "true", - "EventBusConnection": "localhost" + "EventBusConnection": "localhost", + "SubscriptionClientName": "Locations" } diff --git a/test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs b/test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs index 965d8772c..7d0bf784e 100644 --- a/test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs +++ b/test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs @@ -3,6 +3,9 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; + using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.DependencyInjection; using System.IO; public class MarketingScenarioBase @@ -15,7 +18,20 @@ webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory() + "\\Services\\Marketing"); webHostBuilder.UseStartup(); - return new TestServer(webHostBuilder); + var testServer = new TestServer(webHostBuilder); + + testServer.Host + .MigrateDbContext((context, services) => + { + var logger = services.GetService>(); + + new MarketingContextSeed() + .SeedAsync(context, logger) + .Wait(); + + }); + + return testServer; } } } \ No newline at end of file diff --git a/test/Services/IntegrationTests/Services/Marketing/appsettings.json b/test/Services/IntegrationTests/Services/Marketing/appsettings.json index 59ef38d0a..4a57bb0f5 100644 --- a/test/Services/IntegrationTests/Services/Marketing/appsettings.json +++ b/test/Services/IntegrationTests/Services/Marketing/appsettings.json @@ -5,5 +5,6 @@ "IdentityUrl": "http://localhost:5105", "isTest": "true", "EventBusConnection": "localhost", - "PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/" + "PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/", + "SubscriptionClientName": "Marketing" } diff --git a/test/Services/IntegrationTests/Services/Ordering/OrderingScenarioBase.cs b/test/Services/IntegrationTests/Services/Ordering/OrderingScenarioBase.cs index c59144e36..082ad4cd9 100644 --- a/test/Services/IntegrationTests/Services/Ordering/OrderingScenarioBase.cs +++ b/test/Services/IntegrationTests/Services/Ordering/OrderingScenarioBase.cs @@ -4,8 +4,14 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; using Microsoft.eShopOnContainers.Services.Ordering.API; + using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure; + using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; using System.IO; + using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; public class OrderingScenarioBase { @@ -19,7 +25,22 @@ config.AddJsonFile("settings.json"); }); - return new TestServer(webHostBuilder); + var testServer = new TestServer(webHostBuilder); + + testServer.Host + .MigrateDbContext((context, services) => + { + var env = services.GetService(); + var settings = services.GetService>(); + var logger = services.GetService>(); + + new OrderingContextSeed() + .SeedAsync(context, env, settings, logger) + .Wait(); + }) + .MigrateDbContext((_, __) => { }); + + return testServer; } public static class Get diff --git a/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs b/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs index afcdf99c3..2d87e8395 100644 --- a/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs +++ b/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs @@ -25,7 +25,7 @@ } [Fact] - public async Task Cancel_order_no_order_created_response_500_status_code() + public async Task Cancel_order_no_order_created_bad_request_response() { using (var server = CreateServer()) { @@ -33,12 +33,12 @@ var response = await server.CreateIdempotentClient() .PutAsync(Put.CancelOrder, content); - Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } } [Fact] - public async Task Ship_order_no_order_created_response_500_status_code() + public async Task Ship_order_no_order_created_bad_request_response() { using (var server = CreateServer()) { @@ -46,7 +46,7 @@ var response = await server.CreateIdempotentClient() .PutAsync(Put.ShipOrder, content); - Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } } diff --git a/test/Services/IntegrationTests/Services/Ordering/settings.json b/test/Services/IntegrationTests/Services/Ordering/settings.json index 072612e0f..70f1af3c0 100644 --- a/test/Services/IntegrationTests/Services/Ordering/settings.json +++ b/test/Services/IntegrationTests/Services/Ordering/settings.json @@ -5,5 +5,6 @@ "isTest": "true", "EventBusConnection": "localhost", "CheckUpdateTime": "30000", - "GracePeriodTime": "1" + "GracePeriodTime": "1", + "SubscriptionClientName": "Ordering" }