From 339ea43f49dcef47630a3736b50d6130110dbf4f Mon Sep 17 00:00:00 2001 From: Unai Date: Thu, 24 Nov 2016 16:26:59 +0100 Subject: [PATCH] Added functional Tests for catalog and ordering --- eShopOnContainers.sln | 87 +++++++++------ global.json | 3 +- .../Properties/launchSettings.json | 2 + .../Catalog/Catalog.API/settings.json | 2 +- .../Filters/HttpGlobalExceptionFilter.cs | 29 +++-- .../Ordering/Ordering.API/project.json | 2 +- .../FunctionalTests/FunctionalTests.xproj | 7 +- .../Services/Catalog/CatalogScenarioBase.cs | 40 +++++++ .../Services/Catalog/CatalogScenarios.cs | 69 ++++++++++++ .../Services/Ordering/OrderingScenarioBase.cs | 34 ++++++ .../Services/Ordering/OrderingScenarios.cs | 102 ++++++++++++++++++ test/Services/FunctionalTests/project.json | 23 +++- test/Services/FunctionalTests/settings.json | 3 + 13 files changed, 351 insertions(+), 52 deletions(-) create mode 100644 test/Services/FunctionalTests/Services/Catalog/CatalogScenarioBase.cs create mode 100644 test/Services/FunctionalTests/Services/Catalog/CatalogScenarios.cs create mode 100644 test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs create mode 100644 test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs create mode 100644 test/Services/FunctionalTests/settings.json diff --git a/eShopOnContainers.sln b/eShopOnContainers.sln index 7d03f4822..9c6df0610 100644 --- a/eShopOnContainers.sln +++ b/eShopOnContainers.sln @@ -36,8 +36,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A857AD10-4 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{EF0337F2-ED00-4643-89FD-EE10863F1870}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Test", "test\Services\Ordering.Test\Ordering.Test.xproj", "{A0AFC432-3846-4B4E-BD8E-3C8C896F4967}" -EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "eShopOnContainers.WebMVC", "src\Web\WebMVC\eShopOnContainers.WebMVC.xproj", "{F0333D8E-0B27-42B7-B2C6-78F3657624E2}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eShopOnContainers.Core", "src\Mobile\eShopOnContainers\eShopOnContainers.Core\eShopOnContainers.Core.csproj", "{65116D1C-145B-4693-ABDA-F0FB6F425191}" @@ -63,10 +61,13 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eShopOnContainers.TestRunner.Windows", "src\Mobile\eShopOnContainers\eShopOnContainers.TestRunner.Windows\eShopOnContainers.TestRunner.Windows.csproj", "{02680C26-CA1D-4D9D-A7E3-D66AF5BE6F2F}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eShopOnContainers.TestRunner.iOS", "src\Mobile\eShopOnContainers\eShopOnContainers.TestRunner.iOS\eShopOnContainers.TestRunner.iOS.csproj", "{B68C2B56-7581-46AE-B55D-D25DDFD3BFE3}" +EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Application", "src\Services\Ordering\Ordering.Application\Ordering.Application.xproj", "{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Infrastructure", "src\Services\Ordering\Ordering.Infrastructure\Ordering.Infrastructure.xproj", "{95F1F07C-4D92-4742-BD07-E5B805AAB651}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FunctionalTests", "test\Services\FunctionalTests\FunctionalTests.xproj", "{621E7211-58D0-45FD-9600-1CB490BD930E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -199,32 +200,6 @@ Global {F5598DCB-6DDE-4661-AD9D-A55612DA7E76}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {F5598DCB-6DDE-4661-AD9D-A55612DA7E76}.Release|x64.ActiveCfg = Release|Any CPU {F5598DCB-6DDE-4661-AD9D-A55612DA7E76}.Release|x86.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.AppStore|Any CPU.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.AppStore|ARM.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.AppStore|x64.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.AppStore|x86.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|ARM.ActiveCfg = Debug|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|x64.ActiveCfg = Debug|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Debug|x86.ActiveCfg = Debug|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|Any CPU.Build.0 = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|ARM.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|iPhone.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|x64.ActiveCfg = Release|Any CPU - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967}.Release|x86.ActiveCfg = Release|Any CPU {F0333D8E-0B27-42B7-B2C6-78F3657624E2}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU {F0333D8E-0B27-42B7-B2C6-78F3657624E2}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU {F0333D8E-0B27-42B7-B2C6-78F3657624E2}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU @@ -513,7 +488,6 @@ Global {9842DB3A-1391-48C7-A49C-2FABD0A18AC2}.Release|x64.Build.0 = Release|Any CPU {9842DB3A-1391-48C7-A49C-2FABD0A18AC2}.Release|x86.ActiveCfg = Release|Any CPU {9842DB3A-1391-48C7-A49C-2FABD0A18AC2}.Release|x86.Build.0 = Release|Any CPU -<<<<<<< HEAD {F7B6A162-BC4D-4924-B16A-713F9B0344E7}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU {F7B6A162-BC4D-4924-B16A-713F9B0344E7}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU {F7B6A162-BC4D-4924-B16A-713F9B0344E7}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU @@ -728,7 +702,6 @@ Global {B68C2B56-7581-46AE-B55D-D25DDFD3BFE3}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator {B68C2B56-7581-46AE-B55D-D25DDFD3BFE3}.Release|x64.ActiveCfg = Release|iPhone {B68C2B56-7581-46AE-B55D-D25DDFD3BFE3}.Release|x86.ActiveCfg = Release|iPhone -======= {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU @@ -825,7 +798,54 @@ Global {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|x64.Build.0 = Release|Any CPU {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|x86.ActiveCfg = Release|Any CPU {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|x86.Build.0 = Release|Any CPU ->>>>>>> OrderingRefactoring + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|x64.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Ad-Hoc|x86.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|ARM.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|ARM.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|iPhone.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|x64.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|x64.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|x86.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.AppStore|x86.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|ARM.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|ARM.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|iPhone.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|x64.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|x64.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|x86.ActiveCfg = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Debug|x86.Build.0 = Debug|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|Any CPU.Build.0 = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|ARM.ActiveCfg = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|ARM.Build.0 = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|iPhone.ActiveCfg = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|iPhone.Build.0 = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|x64.ActiveCfg = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|x64.Build.0 = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|x86.ActiveCfg = Release|Any CPU + {621E7211-58D0-45FD-9600-1CB490BD930E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -842,7 +862,6 @@ Global {231226CE-690B-4979-8870-9A79D80928E2} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} {F5598DCB-6DDE-4661-AD9D-A55612DA7E76} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} {EF0337F2-ED00-4643-89FD-EE10863F1870} = {A857AD10-40FF-4303-BEC2-FF1C58D5735E} - {A0AFC432-3846-4B4E-BD8E-3C8C896F4967} = {EF0337F2-ED00-4643-89FD-EE10863F1870} {F0333D8E-0B27-42B7-B2C6-78F3657624E2} = {E279BF0F-7F66-4F3A-A3AB-2CDA66C1CD04} {65116D1C-145B-4693-ABDA-F0FB6F425191} = {778289CA-31F7-4464-8C2A-612EE846F8A7} {62DBB163-9CA9-4818-B48B-13233DF37C24} = {9CC7814B-72A6-465B-A61C-57B512DEE303} @@ -851,15 +870,13 @@ Global {778289CA-31F7-4464-8C2A-612EE846F8A7} = {F61357CE-1CC2-410E-8776-B16EEBC98EB8} {9CC7814B-72A6-465B-A61C-57B512DEE303} = {F61357CE-1CC2-410E-8776-B16EEBC98EB8} {9842DB3A-1391-48C7-A49C-2FABD0A18AC2} = {E279BF0F-7F66-4F3A-A3AB-2CDA66C1CD04} -<<<<<<< HEAD {B7B1D395-4E06-4036-BE86-C216756B9367} = {A857AD10-40FF-4303-BEC2-FF1C58D5735E} {F7B6A162-BC4D-4924-B16A-713F9B0344E7} = {B7B1D395-4E06-4036-BE86-C216756B9367} {A289A7F0-ACD8-42AE-87B6-AB1AFD310BF1} = {B7B1D395-4E06-4036-BE86-C216756B9367} {02680C26-CA1D-4D9D-A7E3-D66AF5BE6F2F} = {B7B1D395-4E06-4036-BE86-C216756B9367} {B68C2B56-7581-46AE-B55D-D25DDFD3BFE3} = {B7B1D395-4E06-4036-BE86-C216756B9367} -======= {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} {95F1F07C-4D92-4742-BD07-E5B805AAB651} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} ->>>>>>> OrderingRefactoring + {621E7211-58D0-45FD-9600-1CB490BD930E} = {EF0337F2-ED00-4643-89FD-EE10863F1870} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index c5112dcd4..1fe3e7546 100644 --- a/global.json +++ b/global.json @@ -3,7 +3,8 @@ "src", "test", "src/Services/Ordering", - "src/Web" + "src/Web", + "src/Services/Catalog" ], "sdk": { diff --git a/src/Services/Catalog/Catalog.API/Properties/launchSettings.json b/src/Services/Catalog/Catalog.API/Properties/launchSettings.json index 9c71e8a45..9bc4c1eb0 100644 --- a/src/Services/Catalog/Catalog.API/Properties/launchSettings.json +++ b/src/Services/Catalog/Catalog.API/Properties/launchSettings.json @@ -10,6 +10,8 @@ "profiles": { "IIS Express": { "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "/swagger/ui", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/src/Services/Catalog/Catalog.API/settings.json b/src/Services/Catalog/Catalog.API/settings.json index f7b554148..bac26f3b5 100644 --- a/src/Services/Catalog/Catalog.API/settings.json +++ b/src/Services/Catalog/Catalog.API/settings.json @@ -1,5 +1,5 @@ { - "ConnectionString": "Server=tcp:127.0.0.1,1433;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word", + "ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word", "Logging": { "IncludeScopes": false, "LogLevel": { diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs index 2125fcd7f..3d181cd0c 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs @@ -1,9 +1,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Filters { + using AspNetCore.Mvc; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.ActionResults; using Microsoft.Extensions.Logging; + using System; public class HttpGlobalExceptionFilter : IExceptionFilter { @@ -22,17 +24,30 @@ context.Exception, context.Exception.Message); - var json = new JsonErrorResponse + if (context.Exception.GetType() == typeof(ArgumentException)) //TODO:Select a common exception for application like EshopException { - Messages = new[] { "An error ocurr.Try it again." } - }; + var json = new JsonErrorResponse + { + Messages = new[] { context.Exception.Message } + }; - if (env.IsDevelopment()) - { - json.DeveloperMeesage = context.Exception; + context.Result = new BadRequestObjectResult(json); } + else + { + var json = new JsonErrorResponse + { + Messages = new[] { "An error ocurr.Try it again." } + }; - context.Result = new InternalServerErrorObjectResult(json); + if (env.IsDevelopment()) + { + json.DeveloperMeesage = context.Exception; + } + + context.Result = new InternalServerErrorObjectResult(json); + } + } private class JsonErrorResponse diff --git a/src/Services/Ordering/Ordering.API/project.json b/src/Services/Ordering/Ordering.API/project.json index f65f41ad6..4eeb12070 100644 --- a/src/Services/Ordering/Ordering.API/project.json +++ b/src/Services/Ordering/Ordering.API/project.json @@ -56,7 +56,7 @@ "wwwroot", "Views", "Areas/**/Views", - "appsettings.json", + "settings.json", "web.config", "docker-compose.yml", "docker-compose.debug.yml", diff --git a/test/Services/FunctionalTests/FunctionalTests.xproj b/test/Services/FunctionalTests/FunctionalTests.xproj index 4851c130c..f42aea110 100644 --- a/test/Services/FunctionalTests/FunctionalTests.xproj +++ b/test/Services/FunctionalTests/FunctionalTests.xproj @@ -4,7 +4,6 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 621e7211-58d0-45fd-9600-1cb490bd930e @@ -13,9 +12,11 @@ .\bin\ v4.5.1 - 2.0 + + + - + \ No newline at end of file diff --git a/test/Services/FunctionalTests/Services/Catalog/CatalogScenarioBase.cs b/test/Services/FunctionalTests/Services/Catalog/CatalogScenarioBase.cs new file mode 100644 index 000000000..2ecf8eff0 --- /dev/null +++ b/test/Services/FunctionalTests/Services/Catalog/CatalogScenarioBase.cs @@ -0,0 +1,40 @@ + + +namespace FunctionalTests.Services.Catalog +{ + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.TestHost; + using Microsoft.eShopOnContainers.Services.Catalog.API; + using System.IO; + + public class CatalogScenarioBase + { + public TestServer CreateServer() + { + var webHostBuilder = new WebHostBuilder(); + webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory()); + webHostBuilder.UseStartup(); + + return new TestServer(webHostBuilder); + } + + public static class Get + { + public static string Items = "api/v1/catalog/items"; + + public static string Types = "api/v1/catalog/catalogtypes"; + + public static string Brands = "api/v1/catalog/catalogbrands"; + + public static string Paginated(int pageIndex, int pageCount) + { + return $"api/v1/catalog/items?pageIndex={pageIndex}&pageSize={pageCount}"; + } + + public static string Filtered(int catalogTypeId,int catalogBrandId) + { + return $"api/v1/catalog/items/type/{catalogTypeId}/brand/{catalogBrandId}"; + } + } + } +} diff --git a/test/Services/FunctionalTests/Services/Catalog/CatalogScenarios.cs b/test/Services/FunctionalTests/Services/Catalog/CatalogScenarios.cs new file mode 100644 index 000000000..04482528e --- /dev/null +++ b/test/Services/FunctionalTests/Services/Catalog/CatalogScenarios.cs @@ -0,0 +1,69 @@ +namespace FunctionalTests.Services.Catalog +{ + using System.Threading.Tasks; + using Xunit; + + public class CatalogScenarios + :CatalogScenarioBase + { + [Fact] + public async Task Get_get_all_catalogitems_and_response_ok_status_code() + { + using (var server = CreateServer()) + { + var response = await server.CreateClient() + .GetAsync(Get.Items); + + response.EnsureSuccessStatusCode(); + } + } + + [Fact] + public async Task Get_get_paginated_catalog_items_and_response_ok_status_code() + { + using (var server = CreateServer()) + { + var response = await server.CreateClient() + .GetAsync(Get.Paginated(0,4)); + + response.EnsureSuccessStatusCode(); + } + } + + [Fact] + public async Task Get_get_filtered_catalog_items_and_response_ok_status_code() + { + using (var server = CreateServer()) + { + var response = await server.CreateClient() + .GetAsync(Get.Filtered(1, 1)); + + response.EnsureSuccessStatusCode(); + } + } + + [Fact] + public async Task Get_catalog_types_response_ok_status_code() + { + using (var server = CreateServer()) + { + var response = await server.CreateClient() + .GetAsync(Get.Types); + + response.EnsureSuccessStatusCode(); + } + } + + [Fact] + public async Task Get_catalog_brands_response_ok_status_code() + { + using (var server = CreateServer()) + { + var response = await server.CreateClient() + .GetAsync(Get.Brands); + + response.EnsureSuccessStatusCode(); + } + } + } +} diff --git a/test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs new file mode 100644 index 000000000..ee069ffc4 --- /dev/null +++ b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs @@ -0,0 +1,34 @@ +namespace FunctionalTests.Services.Ordering +{ + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.TestHost; + using Microsoft.eShopOnContainers.Services.Ordering.API; + using System.IO; + + public class OrderingScenarioBase + { + public TestServer CreateServer() + { + var webHostBuilder = new WebHostBuilder(); + webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory()); + webHostBuilder.UseStartup(); + + return new TestServer(webHostBuilder); + } + + public static class Get + { + public static string Orders = "api/v1/orders"; + + public static string OrderBy(int id) + { + return $"api/v1/orders/{id}"; + } + } + + public static class Post + { + public static string AddNewOrder = "api/v1/orders/new"; + } + } +} diff --git a/test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs new file mode 100644 index 000000000..cbbd6ea9d --- /dev/null +++ b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs @@ -0,0 +1,102 @@ +namespace FunctionalTests.Services.Ordering +{ + using Microsoft.AspNetCore.TestHost; + using Microsoft.eShopOnContainers.Services.Ordering.API.Models; + using Microsoft.eShopOnContainers.Services.Ordering.Domain; + using Newtonsoft.Json; + using System; + using System.Net.Http; + using System.Text; + using System.Threading.Tasks; + using Xunit; + + public class OrderingScenarios + : OrderingScenarioBase + { + [Fact] + public async Task Get_get_all_stored_orders_and_response_ok_status_code() + { + using (var server = CreateServer()) + { + var response = await server.CreateClient() + .GetAsync(Get.Orders); + + response.EnsureSuccessStatusCode(); + } + } + + [Fact] + public async Task Get_get_order_and_response_ok_status_code() + { + using (var server = CreateServer()) + { + var response = await server.CreateClient() + .GetAsync(Get.OrderBy(31)); + + response.EnsureSuccessStatusCode(); + } + } + + [Fact] + public async Task AddNewOrder_add_new_order_and_response_ok_status_code() + { + using (var server = CreateServer()) + { + var content = new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json"); + var response = await server.CreateClient() + .PostAsync(Post.AddNewOrder, content); + + response.EnsureSuccessStatusCode(); + } + } + + [Fact] + public async Task AddNewOrder_response_bad_request_if_card_expiration_is_invalid() + { + using (var server = CreateServer()) + { + var content = new StringContent(BuildOrderWithInvalidExperationTime(), UTF8Encoding.UTF8, "application/json"); + + var response = await server.CreateClient() + .PostAsync(Post.AddNewOrder,content); + + Assert.True(response.StatusCode == System.Net.HttpStatusCode.BadRequest); + } + } + + string BuildOrder() + { + var order = new NewOrderViewModel() + { + CardExpiration = DateTime.UtcNow.AddYears(1), + CardNumber = "5145-555-5555", + CardHolderName = "Jhon Senna", + CardSecurityNumber = "232", + CardType = "Amex", + ShippingCity = "Redmon", + ShippingCountry = "USA", + ShippingState = "WA", + ShippingStreet = "One way" + }; + + return JsonConvert.SerializeObject(order); + } + string BuildOrderWithInvalidExperationTime() + { + var order = new NewOrderViewModel() + { + CardExpiration = DateTime.UtcNow.AddYears(-1), + CardNumber = "5145-555-5555", + CardHolderName = "Jhon Senna", + CardSecurityNumber = "232", + CardType = "Amex", + ShippingCity = "Redmon", + ShippingCountry = "USA", + ShippingState = "WA", + ShippingStreet = "One way" + }; + + return JsonConvert.SerializeObject(order); + } + } +} diff --git a/test/Services/FunctionalTests/project.json b/test/Services/FunctionalTests/project.json index 864b9a5f3..875295517 100644 --- a/test/Services/FunctionalTests/project.json +++ b/test/Services/FunctionalTests/project.json @@ -2,12 +2,27 @@ "version": "1.0.0-*", "dependencies": { - "NETStandard.Library": "1.6.0" + "xunit": "2.2.0-beta2-build3300", + "Ordering.API": "1.0.0-*", + "Microsoft.AspNetCore.TestHost": "1.1.0", + "dotnet-test-xunit": "2.2.0-preview2-build1029", + "Catalog.API": "1.0.0-*" }, - + "testRunner": "xunit", "frameworks": { - "netstandard1.6": { - "imports": "dnxcore50" + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + } + } } + }, + "publishOptions": { + "include": [ + "settings.json", + "web.config" + ] } } diff --git a/test/Services/FunctionalTests/settings.json b/test/Services/FunctionalTests/settings.json new file mode 100644 index 000000000..a95b8262f --- /dev/null +++ b/test/Services/FunctionalTests/settings.json @@ -0,0 +1,3 @@ +{ + "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" +}