From 1ae4d01f825d37755fa6edaeaa465a782717d374 Mon Sep 17 00:00:00 2001 From: Unai Date: Tue, 22 Nov 2016 18:40:47 +0100 Subject: [PATCH] More iteration on Ordering Refactoring --- eShopOnContainers.sln | 83 ++++-- global.json | 2 +- src/Console/eShopConsole/Program.cs | 88 +++--- src/Console/eShopConsole/project.json | 2 - src/Services/Catalog/Catalog.API/project.json | 3 +- .../20161122162602_initial.Designer.cs | 227 ++++++++++++++ .../Migrations/20161122162602_initial.cs | 282 ++++++++++++++++++ .../OrderingContextModelSnapshot.cs | 226 ++++++++++++++ .../Infrastructure/OrderingContextSeed.cs | 26 ++ src/Services/Ordering/Ordering.API/Startup.cs | 19 +- .../Ordering/Ordering.API/project.json | 24 +- .../Ordering/Ordering.API/settings.json | 2 +- .../Commands/NewOrderREquestHandler.cs | 2 +- .../Queries/OrderQueries.cs | 37 ++- .../Ordering.Application/project.json | 5 +- .../Ordering/Ordering.Domain/CardType.cs | 57 ++++ .../Ordering/Ordering.Domain/Order.cs | 10 +- .../Ordering/Ordering.Domain/Payment.cs | 27 ++ .../Ordering.Domain/SeedWork/ValueObject.cs | 126 -------- .../Ordering/Ordering.Domain/project.json | 4 +- .../Ordering.Infrastructure.xproj} | 6 +- .../OrderingContext.cs | 138 +++++++++ .../Properties/AssemblyInfo.cs | 4 +- .../Ordering.Infrastructure/project.json | 16 + .../UnitOfWork/DBContextUtil.cs | 50 ---- .../UnitOfWork/OrderingDbContext.cs | 82 ----- .../Ordering/Ordering.SqlData/project.json | 19 -- .../Ordering.Test/DataIntegrationTests.cs | 86 ------ test/Services/Ordering.Test/project.json | 8 +- 29 files changed, 1172 insertions(+), 489 deletions(-) create mode 100644 src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.Designer.cs create mode 100644 src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.cs create mode 100644 src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs create mode 100644 src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs create mode 100644 src/Services/Ordering/Ordering.Domain/CardType.cs create mode 100644 src/Services/Ordering/Ordering.Domain/Payment.cs delete mode 100644 src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs rename src/Services/Ordering/{Ordering.SqlData/Ordering.SqlData.xproj => Ordering.Infrastructure/Ordering.Infrastructure.xproj} (85%) create mode 100644 src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs rename src/Services/Ordering/{Ordering.SqlData => Ordering.Infrastructure}/Properties/AssemblyInfo.cs (82%) create mode 100644 src/Services/Ordering/Ordering.Infrastructure/project.json delete mode 100644 src/Services/Ordering/Ordering.SqlData/UnitOfWork/DBContextUtil.cs delete mode 100644 src/Services/Ordering/Ordering.SqlData/UnitOfWork/OrderingDbContext.cs delete mode 100644 src/Services/Ordering/Ordering.SqlData/project.json delete mode 100644 test/Services/Ordering.Test/DataIntegrationTests.cs diff --git a/eShopOnContainers.sln b/eShopOnContainers.sln index f21b21491..1097f51d2 100644 --- a/eShopOnContainers.sln +++ b/eShopOnContainers.sln @@ -38,10 +38,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{EF EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Test", "test\Services\Ordering.Test\Ordering.Test.xproj", "{A0AFC432-3846-4B4E-BD8E-3C8C896F4967}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Console App", "Console App", "{48FC45C5-223F-4B59-AC77-6CBB1C561E85}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "eShopConsole", "src\Console\eShopConsole\eShopConsole.xproj", "{C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}" -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}" @@ -60,6 +56,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "eShopOnContainers.WebSPA", 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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -218,32 +216,6 @@ Global {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 - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.AppStore|Any CPU.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.AppStore|ARM.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.AppStore|iPhone.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.AppStore|x64.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.AppStore|x86.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Debug|ARM.ActiveCfg = Debug|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Debug|x64.ActiveCfg = Debug|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Debug|x86.ActiveCfg = Debug|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Release|Any CPU.Build.0 = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Release|ARM.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Release|iPhone.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.Release|x64.ActiveCfg = Release|Any CPU - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7}.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 @@ -578,6 +550,54 @@ Global {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x64.Build.0 = Release|Any CPU {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x86.ActiveCfg = Release|Any CPU {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x86.Build.0 = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|x64.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Ad-Hoc|x86.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|ARM.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|ARM.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|iPhone.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|x64.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|x64.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|x86.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.AppStore|x86.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|ARM.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|ARM.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|iPhone.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|x64.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|x64.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|x86.ActiveCfg = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Debug|x86.Build.0 = Debug|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|Any CPU.Build.0 = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|ARM.ActiveCfg = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|ARM.Build.0 = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|iPhone.ActiveCfg = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|iPhone.Build.0 = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {95F1F07C-4D92-4742-BD07-E5B805AAB651}.Release|x64.ActiveCfg = Release|Any CPU + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -595,8 +615,6 @@ Global {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} - {48FC45C5-223F-4B59-AC77-6CBB1C561E85} = {932D8224-11F6-4D07-B109-DA28AD288A63} - {C10C7B69-CE4F-4167-928E-33B7FA1DFFC7} = {48FC45C5-223F-4B59-AC77-6CBB1C561E85} {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} @@ -606,5 +624,6 @@ Global {9CC7814B-72A6-465B-A61C-57B512DEE303} = {F61357CE-1CC2-410E-8776-B16EEBC98EB8} {9842DB3A-1391-48C7-A49C-2FABD0A18AC2} = {E279BF0F-7F66-4F3A-A3AB-2CDA66C1CD04} {4193CAA3-A1C3-4818-A06F-A2D85FDE77E7} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} + {95F1F07C-4D92-4742-BD07-E5B805AAB651} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index bf6ec0487..c5112dcd4 100644 --- a/global.json +++ b/global.json @@ -7,6 +7,6 @@ ], "sdk": { - "version": "1.0.0-preview2-003121" + "version": "1.0.0-preview2-003131" } } diff --git a/src/Console/eShopConsole/Program.cs b/src/Console/eShopConsole/Program.cs index 7a97661a0..f647bc2d5 100644 --- a/src/Console/eShopConsole/Program.cs +++ b/src/Console/eShopConsole/Program.cs @@ -12,60 +12,60 @@ namespace eShopConsole { public static void Main(string[] args) { - // All contexts that share the same service provider will share the same database + //// All contexts that share the same service provider will share the same database - //Using InMemory DB - //var options = DbContextUtil.CreateNewContextOptionsForInMemoryDB(); + ////Using InMemory DB + ////var options = DbContextUtil.CreateNewContextOptionsForInMemoryDB(); - //Using Sql Server - var options = DbContextUtil.CreateNewContextOptionsForSqlDb(); + ////Using Sql Server + //var options = DbContextUtil.CreateNewContextOptionsForSqlDb(); - // Run the test against one instance of the context - using (var context = new OrderingDbContext(options)) - { - IOrderRepository orderRepository = new OrderRepository(context); + //// Run the test against one instance of the context + //using (var context = new OrderingDbContext(options)) + //{ + // IOrderRepository orderRepository = new OrderRepository(context); - //Create generic Address ValueObject - Address sampleAddress = new Address("15703 NE 61st Ct.", - "Redmond", - "Washington", - "WA", - "United States", - "US", - "98052", - 47.661492, - -122.131309 - ); - //Create sample Orders - Order order1 = new Order(Guid.NewGuid(), sampleAddress, sampleAddress); + // //Create generic Address ValueObject + // Address sampleAddress = new Address("15703 NE 61st Ct.", + // "Redmond", + // "Washington", + // "WA", + // "United States", + // "US", + // "98052", + // 47.661492, + // -122.131309 + // ); + // //Create sample Orders + // Order order1 = new Order(Guid.NewGuid(), sampleAddress, sampleAddress); - //Add a few OrderItems - order1.AddNewOrderItem(Guid.NewGuid(), 2, 25, 30); - order1.AddNewOrderItem(Guid.NewGuid(), 1, 58, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 1, 60, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 3, 12, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 5, 3, 0); + // //Add a few OrderItems + // order1.AddNewOrderItem(Guid.NewGuid(), 2, 25, 30); + // order1.AddNewOrderItem(Guid.NewGuid(), 1, 58, 0); + // order1.AddNewOrderItem(Guid.NewGuid(), 1, 60, 0); + // order1.AddNewOrderItem(Guid.NewGuid(), 3, 12, 0); + // order1.AddNewOrderItem(Guid.NewGuid(), 5, 3, 0); - orderRepository.Add(order1); - orderRepository.UnitOfWork.CommitAsync(); + // orderRepository.Add(order1); + // orderRepository.UnitOfWork.CommitAsync(); - //With no Async Repository - //context.Orders.Add(order1); - //context.SaveChanges(); + // //With no Async Repository + // //context.Orders.Add(order1); + // //context.SaveChanges(); - } + //} - //// Use a separate instance of the context to verify correct data was saved to database - using (var context = new OrderingDbContext(options)) - { - var orders = context.Orders - .Include(o => o.ShippingAddress) - .Include(o => o.BillingAddress) - .ToList(); + ////// Use a separate instance of the context to verify correct data was saved to database + //using (var context = new OrderingDbContext(options)) + //{ + // var orders = context.Orders + // .Include(o => o.ShippingAddress) + // .Include(o => o.BillingAddress) + // .ToList(); - string cityName = orders.First().ShippingAddress.City; - Console.WriteLine("City name retreived from SQL Server: "+cityName); - } + // string cityName = orders.First().ShippingAddress.City; + // Console.WriteLine("City name retreived from SQL Server: "+cityName); + //} } } } diff --git a/src/Console/eShopConsole/project.json b/src/Console/eShopConsole/project.json index 1b299277a..f953c60fe 100644 --- a/src/Console/eShopConsole/project.json +++ b/src/Console/eShopConsole/project.json @@ -10,9 +10,7 @@ "type": "platform", "version": "1.0.0" }, - "Ordering.API": "1.0.0-*", "Ordering.Domain": "1.0.0-*", - "Ordering.SqlData": "1.0.0-*" }, "frameworks": { "netcoreapp1.0": { diff --git a/src/Services/Catalog/Catalog.API/project.json b/src/Services/Catalog/Catalog.API/project.json index d7e16be9e..8297fb35b 100644 --- a/src/Services/Catalog/Catalog.API/project.json +++ b/src/Services/Catalog/Catalog.API/project.json @@ -54,5 +54,6 @@ "Dockerfile" ] }, - "scripts": {} + "scripts": {}, + "userSecretsId": "aspnet-Catalog.API-20161122013618" } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.Designer.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.Designer.cs new file mode 100644 index 000000000..bc974dd75 --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.Designer.cs @@ -0,0 +1,227 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; + +namespace Ordering.API.Infrastructure.Migrations +{ + [DbContext(typeof(OrderingContext))] + [Migration("20161122162602_initial")] + partial class initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.1") + .HasAnnotation("SqlServer:Sequence:ordering.buyerseq", "'buyerseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:ordering.orderseq", "'orderseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("City"); + + b.Property("Country"); + + b.Property("CountryCode"); + + b.Property("Latitude"); + + b.Property("Longitude"); + + b.Property("State"); + + b.Property("StateCode"); + + b.Property("Street"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.ToTable("address","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq") + .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("FullName") + .IsRequired() + .HasAnnotation("MaxLength", 200); + + b.HasKey("Id"); + + b.ToTable("buyers","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("cardtypes","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "orderseq") + .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("BillingAddressId"); + + b.Property("BuyerId"); + + b.Property("OrderDate"); + + b.Property("PaymentId"); + + b.Property("ShippingAddressId"); + + b.Property("StatusId"); + + b.HasKey("Id"); + + b.HasIndex("BillingAddressId"); + + b.HasIndex("BuyerId"); + + b.HasIndex("PaymentId"); + + b.HasIndex("ShippingAddressId"); + + b.HasIndex("StatusId"); + + b.ToTable("orders","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Discount"); + + b.Property("OrderId"); + + b.Property("ProductId"); + + b.Property("ProductName") + .IsRequired(); + + b.Property("UnitPrice"); + + b.Property("Units") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:DefaultValue", 1); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("orderItems","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("orderstatus","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq") + .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CardHolderName") + .IsRequired() + .HasAnnotation("MaxLength", 200); + + b.Property("CardNumber") + .IsRequired() + .HasAnnotation("MaxLength", 25); + + b.Property("CardTypeId"); + + b.Property("Expiration"); + + b.Property("SecurityNumber"); + + b.HasKey("Id"); + + b.HasIndex("CardTypeId"); + + b.ToTable("payments","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "BillingAddress") + .WithMany() + .HasForeignKey("BillingAddressId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer") + .WithMany() + .HasForeignKey("BuyerId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment") + .WithMany() + .HasForeignKey("PaymentId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress") + .WithMany() + .HasForeignKey("ShippingAddressId"); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", "Status") + .WithMany() + .HasForeignKey("StatusId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order") + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType") + .WithMany() + .HasForeignKey("CardTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.cs new file mode 100644 index 000000000..b64a9b570 --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20161122162602_initial.cs @@ -0,0 +1,282 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace Ordering.API.Infrastructure.Migrations +{ + public partial class initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "ordering"); + + migrationBuilder.CreateSequence( + name: "buyerseq", + schema: "ordering", + incrementBy: 10); + + migrationBuilder.CreateSequence( + name: "orderseq", + schema: "ordering", + incrementBy: 10); + + migrationBuilder.CreateSequence( + name: "paymentseq", + schema: "ordering", + incrementBy: 10); + + migrationBuilder.CreateTable( + name: "address", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + City = table.Column(nullable: true), + Country = table.Column(nullable: true), + CountryCode = table.Column(nullable: true), + Latitude = table.Column(nullable: false), + Longitude = table.Column(nullable: false), + State = table.Column(nullable: true), + StateCode = table.Column(nullable: true), + Street = table.Column(nullable: true), + ZipCode = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_address", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "buyers", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false), + FullName = table.Column(maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_buyers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "cardtypes", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_cardtypes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "orderstatus", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_orderstatus", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "payments", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false), + CardHolderName = table.Column(maxLength: 200, nullable: false), + CardNumber = table.Column(maxLength: 25, nullable: false), + CardTypeId = table.Column(nullable: false), + Expiration = table.Column(nullable: false), + SecurityNumber = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_payments", x => x.Id); + table.ForeignKey( + name: "FK_payments_cardtypes_CardTypeId", + column: x => x.CardTypeId, + principalSchema: "ordering", + principalTable: "cardtypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "orders", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false), + BillingAddressId = table.Column(nullable: true), + BuyerId = table.Column(nullable: false), + OrderDate = table.Column(nullable: false), + PaymentId = table.Column(nullable: false), + ShippingAddressId = table.Column(nullable: true), + StatusId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_orders", x => x.Id); + table.ForeignKey( + name: "FK_orders_address_BillingAddressId", + column: x => x.BillingAddressId, + principalSchema: "ordering", + principalTable: "address", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + table.ForeignKey( + name: "FK_orders_buyers_BuyerId", + column: x => x.BuyerId, + principalSchema: "ordering", + principalTable: "buyers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_orders_payments_PaymentId", + column: x => x.PaymentId, + principalSchema: "ordering", + principalTable: "payments", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_orders_address_ShippingAddressId", + column: x => x.ShippingAddressId, + principalSchema: "ordering", + principalTable: "address", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_orders_orderstatus_StatusId", + column: x => x.StatusId, + principalSchema: "ordering", + principalTable: "orderstatus", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "orderItems", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Discount = table.Column(nullable: false), + OrderId = table.Column(nullable: false), + ProductId = table.Column(nullable: false), + ProductName = table.Column(nullable: false), + UnitPrice = table.Column(nullable: false), + Units = table.Column(nullable: false, defaultValue: 1) + }, + constraints: table => + { + table.PrimaryKey("PK_orderItems", x => x.Id); + table.ForeignKey( + name: "FK_orderItems_orders_OrderId", + column: x => x.OrderId, + principalSchema: "ordering", + principalTable: "orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_orders_BillingAddressId", + schema: "ordering", + table: "orders", + column: "BillingAddressId"); + + migrationBuilder.CreateIndex( + name: "IX_orders_BuyerId", + schema: "ordering", + table: "orders", + column: "BuyerId"); + + migrationBuilder.CreateIndex( + name: "IX_orders_PaymentId", + schema: "ordering", + table: "orders", + column: "PaymentId"); + + migrationBuilder.CreateIndex( + name: "IX_orders_ShippingAddressId", + schema: "ordering", + table: "orders", + column: "ShippingAddressId"); + + migrationBuilder.CreateIndex( + name: "IX_orders_StatusId", + schema: "ordering", + table: "orders", + column: "StatusId"); + + migrationBuilder.CreateIndex( + name: "IX_orderItems_OrderId", + schema: "ordering", + table: "orderItems", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_payments_CardTypeId", + schema: "ordering", + table: "payments", + column: "CardTypeId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropSequence( + name: "buyerseq", + schema: "ordering"); + + migrationBuilder.DropSequence( + name: "orderseq", + schema: "ordering"); + + migrationBuilder.DropSequence( + name: "paymentseq", + schema: "ordering"); + + migrationBuilder.DropTable( + name: "orderItems", + schema: "ordering"); + + migrationBuilder.DropTable( + name: "orders", + schema: "ordering"); + + migrationBuilder.DropTable( + name: "address", + schema: "ordering"); + + migrationBuilder.DropTable( + name: "buyers", + schema: "ordering"); + + migrationBuilder.DropTable( + name: "payments", + schema: "ordering"); + + migrationBuilder.DropTable( + name: "orderstatus", + schema: "ordering"); + + migrationBuilder.DropTable( + name: "cardtypes", + schema: "ordering"); + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs new file mode 100644 index 000000000..ac998114d --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs @@ -0,0 +1,226 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; + +namespace Ordering.API.Infrastructure.Migrations +{ + [DbContext(typeof(OrderingContext))] + partial class OrderingContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.1") + .HasAnnotation("SqlServer:Sequence:ordering.buyerseq", "'buyerseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:ordering.orderseq", "'orderseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("City"); + + b.Property("Country"); + + b.Property("CountryCode"); + + b.Property("Latitude"); + + b.Property("Longitude"); + + b.Property("State"); + + b.Property("StateCode"); + + b.Property("Street"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.ToTable("address","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq") + .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("FullName") + .IsRequired() + .HasAnnotation("MaxLength", 200); + + b.HasKey("Id"); + + b.ToTable("buyers","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("cardtypes","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "orderseq") + .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("BillingAddressId"); + + b.Property("BuyerId"); + + b.Property("OrderDate"); + + b.Property("PaymentId"); + + b.Property("ShippingAddressId"); + + b.Property("StatusId"); + + b.HasKey("Id"); + + b.HasIndex("BillingAddressId"); + + b.HasIndex("BuyerId"); + + b.HasIndex("PaymentId"); + + b.HasIndex("ShippingAddressId"); + + b.HasIndex("StatusId"); + + b.ToTable("orders","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Discount"); + + b.Property("OrderId"); + + b.Property("ProductId"); + + b.Property("ProductName") + .IsRequired(); + + b.Property("UnitPrice"); + + b.Property("Units") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:DefaultValue", 1); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("orderItems","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("orderstatus","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq") + .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CardHolderName") + .IsRequired() + .HasAnnotation("MaxLength", 200); + + b.Property("CardNumber") + .IsRequired() + .HasAnnotation("MaxLength", 25); + + b.Property("CardTypeId"); + + b.Property("Expiration"); + + b.Property("SecurityNumber"); + + b.HasKey("Id"); + + b.HasIndex("CardTypeId"); + + b.ToTable("payments","ordering"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "BillingAddress") + .WithMany() + .HasForeignKey("BillingAddressId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer") + .WithMany() + .HasForeignKey("BuyerId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment") + .WithMany() + .HasForeignKey("PaymentId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress") + .WithMany() + .HasForeignKey("ShippingAddressId"); + + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", "Status") + .WithMany() + .HasForeignKey("StatusId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order") + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType") + .WithMany() + .HasForeignKey("CardTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs b/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs new file mode 100644 index 000000000..f16427b7a --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs @@ -0,0 +1,26 @@ + +namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure +{ + using AspNetCore.Builder; + using Microsoft.EntityFrameworkCore; + using Ordering.Infrastructure; + using System.Threading.Tasks; + + + public class OrderingContextSeed + { + public static async Task SeedAsync(IApplicationBuilder applicationBuilder) + { + var context = (OrderingContext)applicationBuilder + .ApplicationServices.GetService(typeof(OrderingContext)); + + using (context) + { + context.Database.Migrate(); + + await context.SaveChangesAsync(); + } + } + + } +} diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 4b5009663..fe8d01f6e 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -7,6 +7,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; + using Ordering.Infrastructure; + using System.Reflection; public class Startup { @@ -14,8 +16,8 @@ { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); + .AddJsonFile("settings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"settings.{env.EnvironmentName}.json", optional: true); if (env.IsDevelopment()) { @@ -34,12 +36,13 @@ // Add framework services. services.AddMvc(); - //services.AddEntityFrameworkSqlServer() - // .AddDbContext(options => - // { - // options.UseSqlServer(Configuration["ConnectionString"]); - // }); - + services.AddEntityFrameworkSqlServer() + .AddDbContext(options => + { + options.UseSqlServer(Configuration["ConnectionString"], + sqlop=>sqlop.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)); + }); + services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => { diff --git a/src/Services/Ordering/Ordering.API/project.json b/src/Services/Ordering/Ordering.API/project.json index 31217732b..46249899f 100644 --- a/src/Services/Ordering/Ordering.API/project.json +++ b/src/Services/Ordering/Ordering.API/project.json @@ -1,11 +1,10 @@ { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.0.1", "type": "platform" }, "MediatR.Extensions.Microsoft.DependencyInjection": "1.0.1", - "Microsoft.Extensions.DependencyInjection": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", @@ -13,20 +12,20 @@ "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", - "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", - "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", - "Microsoft.EntityFrameworkCore": "1.0.0", - "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0", - "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", + "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", + "Microsoft.EntityFrameworkCore": "1.0.1", + "Microsoft.EntityFrameworkCore.Design" : "1.0.0-preview2-final", + "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1", "Microsoft.AspNetCore.Diagnostics": "1.0.0", - "Ordering.Application": "1.0.0-*", - "Ordering.Domain": "1.0.0-*", - "Ordering.SqlData": "1.0.0-*", "Swashbuckle": "6.0.0-beta902", - "MediatR": "2.1.0" + "MediatR": "2.1.0", + "Ordering.Domain": "1.0.0-*", + "Ordering.Application": "1.0.0-*", + "Ordering.Infrastructure": "1.0.0-*", + "System.Reflection": "4.3.0" }, "tools": { "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", @@ -68,5 +67,6 @@ "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] - } + }, + "userSecretsId": "aspnet-Ordering.API-20161122013547" } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/settings.json b/src/Services/Ordering/Ordering.API/settings.json index da778d1c4..a95b8262f 100644 --- a/src/Services/Ordering/Ordering.API/settings.json +++ b/src/Services/Ordering/Ordering.API/settings.json @@ -1,3 +1,3 @@ { - "ConnectionString": "Server=127.0.0.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" + "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" } diff --git a/src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs b/src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs index fceb7ef41..466f42ac6 100644 --- a/src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs +++ b/src/Services/Ordering/Ordering.Application/Commands/NewOrderREquestHandler.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; - public class NewOrderREquestHandler + public class NewOrderRequestHandler : IAsyncRequestHandler { public Task Handle(NewOrderRequest message) diff --git a/src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs b/src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs index 3c2412ebc..0ab74090a 100644 --- a/src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs +++ b/src/Services/Ordering/Ordering.Application/Queries/OrderQueries.cs @@ -1,13 +1,38 @@ - - -namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Queries +namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Queries { - using System; - using System.Collections.Generic; - using System.Linq; + using Dapper; + using Microsoft.Extensions.Configuration; + using System.Data.SqlClient; using System.Threading.Tasks; public class OrderQueries + :IOrderQueries { + private string _connectionString = string.Empty; + + public OrderQueries(IConfiguration configuration) + { + _connectionString = configuration["ConnectionString"]; + } + + public async Task GetOrder(int id) + { + using (var connection = new SqlConnection(_connectionString)) + { + connection.Open(); + + return await connection.QueryAsync("SELECT * FROM ordering.Orders where Id=@id",new { id }); + } + } + + public async Task GetPendingOrders() + { + using (var connection = new SqlConnection(_connectionString)) + { + connection.Open(); + + return await connection.QueryAsync("SELECT * FROM ordering.Orders"); + } + } } } diff --git a/src/Services/Ordering/Ordering.Application/project.json b/src/Services/Ordering/Ordering.Application/project.json index 814573611..c6531feaf 100644 --- a/src/Services/Ordering/Ordering.Application/project.json +++ b/src/Services/Ordering/Ordering.Application/project.json @@ -4,8 +4,11 @@ "dependencies": { "NETStandard.Library": "1.6.0", "MediatR": "2.1.0", + "Dapper": "1.50.2", "System.Dynamic.Runtime": "4.0.11", - "Microsoft.CSharp": "4.0.1" + "Microsoft.CSharp": "4.0.1", + "Microsoft.Extensions.Configuration": "1.0.0", + "System.Data.SqlClient": "4.1.0" }, "frameworks": { diff --git a/src/Services/Ordering/Ordering.Domain/CardType.cs b/src/Services/Ordering/Ordering.Domain/CardType.cs new file mode 100644 index 000000000..ca875321c --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/CardType.cs @@ -0,0 +1,57 @@ + + +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain +{ + using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; + using System; + using System.Collections.Generic; + using System.Linq; + + public class CardType + : Entity + { + public static CardType Amex = new CardType(1, "Amex"); + public static CardType Visa = new CardType(1, "Visa"); + public static CardType MasterCard = new CardType(1, "MasterCard"); + + public string Name { get; private set; } + + protected CardType() { } + + public CardType(int id, string name) + { + Id = id; + Name = name; + } + + public static IEnumerable List() + { + return new[] { Amex, Visa, MasterCard }; + } + + public static CardType FromName(string name) + { + var state = List() + .SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); + + if (state == null) + { + throw new ArgumentException($"Possible values for CardType: {String.Join(",", List().Select(s => s.Name))}"); + } + + return state; + } + + public static CardType From(int id) + { + var state = List().SingleOrDefault(s => s.Id == id); + + if (state == null) + { + throw new ArgumentException($"Possible values for CardType: {String.Join(",", List().Select(s => s.Name))}"); + } + + return state; + } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/Order.cs b/src/Services/Ordering/Ordering.Domain/Order.cs index 547d44148..e7bbefce5 100644 --- a/src/Services/Ordering/Ordering.Domain/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/Order.cs @@ -13,18 +13,24 @@ public DateTime OrderDate { get; private set; } + public int StatusId { get; private set; } + public OrderStatus Status { get; private set; } public ICollection OrderItems { get; set; } - public int ShippingAddressId { get; private set; } + public int? ShippingAddressId { get; private set; } public Address ShippingAddress { get; private set; } - public int BillingAddressId { get; private set; } + public int? BillingAddressId { get; private set; } public Address BillingAddress { get; private set; } + public int PaymentId { get; private set; } + + public Payment Payment { get; private set; } + protected Order() { } } } diff --git a/src/Services/Ordering/Ordering.Domain/Payment.cs b/src/Services/Ordering/Ordering.Domain/Payment.cs new file mode 100644 index 000000000..ccf35e133 --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/Payment.cs @@ -0,0 +1,27 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain +{ + using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + + + public class Payment + : Entity, IAggregateRoot + { + public string CardNumber { get; private set; } + + public string SecurityNumber { get; private set; } + + public string CardHolderName { get; private set; } + + public int CardTypeId { get; private set; } + + public CardType CardType { get; private set; } + + public DateTime Expiration { get; private set; } + + protected Payment() { } + } +} diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs deleted file mode 100644 index 3dc5fc4cd..000000000 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs +++ /dev/null @@ -1,126 +0,0 @@ - -namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using System.Reflection; - - - public class ValueObject : IEquatable - where TValueObject : ValueObject - { - //A ValueObject doesn't have Identity, but we just need an Id/key so EF knows how to persist - //becuase in EF Core it still doesn't support ValueObjects or ComplexTypes - //This should be changed when EF Core supports any of those. - // https://github.com/aspnet/EntityFramework/issues/246 - public virtual Guid Id { get; protected set; } - - //IEquatable and Override Equals operators - - - public bool Equals(TValueObject other) - { - if ((object)other == null) - return false; - - if (Object.ReferenceEquals(this, other)) - return true; - - //compare all public properties - PropertyInfo[] publicProperties = this.GetType().GetProperties(); - - if ((object)publicProperties != null - && - publicProperties.Any()) - { - return publicProperties.All(p => - { - var left = p.GetValue(this, null); - var right = p.GetValue(other, null); - - - if (typeof(TValueObject).IsAssignableFrom(left.GetType())) - { - //check not self-references... - return Object.ReferenceEquals(left, right); - } - else - return left.Equals(right); - - - }); - } - else - return true; - } - - public override bool Equals(object obj) - { - if ((object)obj == null) - return false; - - if (Object.ReferenceEquals(this, obj)) - return true; - - ValueObject item = obj as ValueObject; - - if ((object)item != null) - return Equals((TValueObject)item); - else - return false; - - } - - public override int GetHashCode() - { - int hashCode = 31; - bool changeMultiplier = false; - int index = 1; - - //compare all public properties - PropertyInfo[] publicProperties = this.GetType().GetProperties(); - - - if ((object)publicProperties != null - && - publicProperties.Any()) - { - foreach (var item in publicProperties) - { - object value = item.GetValue(this, null); - - if ((object)value != null) - { - - hashCode = hashCode * ((changeMultiplier) ? 59 : 114) + value.GetHashCode(); - - changeMultiplier = !changeMultiplier; - } - else - hashCode = hashCode ^ (index * 13);//only for support {"a",null,null,"a"} <> {null,"a","a",null} - } - } - - return hashCode; - } - - public static bool operator ==(ValueObject left, ValueObject right) - { - if (Object.Equals(left, null)) - return (Object.Equals(right, null)) ? true : false; - else - return left.Equals(right); - - } - - public static bool operator !=(ValueObject left, ValueObject right) - { - return !(left == right); - } - - - } -} - diff --git a/src/Services/Ordering/Ordering.Domain/project.json b/src/Services/Ordering/Ordering.Domain/project.json index bcfd892ef..db56591f2 100644 --- a/src/Services/Ordering/Ordering.Domain/project.json +++ b/src/Services/Ordering/Ordering.Domain/project.json @@ -2,9 +2,7 @@ "version": "1.0.0-*", "dependencies": { - "NETStandard.Library": "1.6.0", - "System.Reflection.TypeExtensions": "4.1.0", - "System.Runtime.Serialization.Primitives": "4.1.1" + "NETStandard.Library": "1.6" }, "frameworks": { diff --git a/src/Services/Ordering/Ordering.SqlData/Ordering.SqlData.xproj b/src/Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.xproj similarity index 85% rename from src/Services/Ordering/Ordering.SqlData/Ordering.SqlData.xproj rename to src/Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.xproj index 5f9c67bd6..21d5cdd3f 100644 --- a/src/Services/Ordering/Ordering.SqlData/Ordering.SqlData.xproj +++ b/src/Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.xproj @@ -6,11 +6,11 @@ - 5da6ef13-c7e0-4ec4-8599-a61c6ac2628d - Microsoft.eShopOnContainers.Services.Ordering.SqlData + 95f1f07c-4d92-4742-bd07-e5b805aab651 + Microsoft.eShopOnContainers.Services.Ordering.Infrastructure .\obj .\bin\ - v4.6 + v4.5.1 2.0 diff --git a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs new file mode 100644 index 000000000..d766bd6d0 --- /dev/null +++ b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs @@ -0,0 +1,138 @@ +namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure +{ + using Microsoft.EntityFrameworkCore; + using Microsoft.EntityFrameworkCore.Metadata.Builders; + using Microsoft.eShopOnContainers.Services.Ordering.Domain; + + public class OrderingContext + : DbContext + + { + const string DEFAULT_SCHEMA = "ordering"; + + public DbSet Orders { get; set; } + + public DbSet OrderItems { get; set; } + + public DbSet Payments { get; set; } + + public DbSet Buyers { get; set; } + + public DbSet Cards { get; set; } + + public DbSet OrderStatus { get; set; } + + public DbSet
Addresses { get; set; } + + public OrderingContext(DbContextOptions options) : base(options) { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(ConfigureBuyer); + modelBuilder.Entity(ConfigurePayment); + modelBuilder.Entity(ConfigureOrder); + modelBuilder.Entity(ConfigureOrderItems); + + modelBuilder.Entity() + .ToTable("orderstatus", DEFAULT_SCHEMA); + + modelBuilder.Entity() + .ToTable("cardtypes", DEFAULT_SCHEMA); + + modelBuilder.Entity
() + .ToTable("address", DEFAULT_SCHEMA); + } + + void ConfigureBuyer(EntityTypeBuilder buyerConfiguration) + { + buyerConfiguration.ToTable("buyers", DEFAULT_SCHEMA); + + buyerConfiguration.HasKey(b => b.Id); + + buyerConfiguration.Property(b => b.Id) + .ForSqlServerUseSequenceHiLo("buyerseq", DEFAULT_SCHEMA); + + buyerConfiguration.Property(b => b.FullName) + .HasMaxLength(200) + .IsRequired(); + } + + void ConfigurePayment(EntityTypeBuilder paymentConfiguration) + { + paymentConfiguration.ToTable("payments", DEFAULT_SCHEMA); + + paymentConfiguration.HasKey(b => b.Id); + + paymentConfiguration.Property(b => b.Id) + .ForSqlServerUseSequenceHiLo("paymentseq", DEFAULT_SCHEMA); + + paymentConfiguration.Property(p => p.CardHolderName) + .HasMaxLength(200) + .IsRequired(); + + paymentConfiguration.Property(p => p.CardNumber) + .HasMaxLength(25) + .IsRequired(); + + paymentConfiguration.Property(p => p.Expiration) + .IsRequired(); + + paymentConfiguration.HasOne(p => p.CardType) + .WithMany() + .HasForeignKey(p => p.CardTypeId); + } + + void ConfigureOrder(EntityTypeBuilder orderConfiguration) + { + orderConfiguration.ToTable("orders", DEFAULT_SCHEMA); + + orderConfiguration.HasKey(o => o.Id); + + orderConfiguration.Property(o => o.Id) + .ForSqlServerUseSequenceHiLo("orderseq", DEFAULT_SCHEMA); + + orderConfiguration.Property(o => o.OrderDate) + .IsRequired(); + + orderConfiguration.HasOne(o => o.Payment) + .WithMany() + .HasForeignKey(o => o.PaymentId); + + orderConfiguration.HasOne(o => o.BillingAddress) + .WithMany() + .HasForeignKey(o => o.BillingAddressId) + .OnDelete(EntityFrameworkCore.Metadata.DeleteBehavior.SetNull); + + orderConfiguration.HasOne(o => o.Buyer) + .WithMany() + .HasForeignKey(o => o.BuyerId); + + orderConfiguration.HasOne(o => o.Status) + .WithMany() + .HasForeignKey(o => o.StatusId); + } + + void ConfigureOrderItems(EntityTypeBuilder orderItemConfiguration) + { + orderItemConfiguration.ToTable("orderItems", DEFAULT_SCHEMA); + + orderItemConfiguration.HasKey(o => o.Id); + + orderItemConfiguration.Property(o => o.Discount) + .IsRequired(); + + orderItemConfiguration.Property(o => o.ProductId) + .IsRequired(); + + orderItemConfiguration.Property(o => o.ProductName) + .IsRequired(); + + orderItemConfiguration.Property(o => o.UnitPrice) + .IsRequired(); + + orderItemConfiguration.Property(o => o.Units) + .ForSqlServerHasDefaultValue(1) + .IsRequired(); + } + } +} diff --git a/src/Services/Ordering/Ordering.SqlData/Properties/AssemblyInfo.cs b/src/Services/Ordering/Ordering.Infrastructure/Properties/AssemblyInfo.cs similarity index 82% rename from src/Services/Ordering/Ordering.SqlData/Properties/AssemblyInfo.cs rename to src/Services/Ordering/Ordering.Infrastructure/Properties/AssemblyInfo.cs index 322d94a72..00732b2ad 100644 --- a/src/Services/Ordering/Ordering.SqlData/Properties/AssemblyInfo.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Properties/AssemblyInfo.cs @@ -7,7 +7,7 @@ using System.Runtime.InteropServices; // associated with an assembly. [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Microsoft.eShopOnContainers.Services.Ordering.Infrastructure")] +[assembly: AssemblyProduct("Ordering.Infrastructure")] [assembly: AssemblyTrademark("")] // Setting ComVisible to false makes the types in this assembly not visible @@ -16,4 +16,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("5da6ef13-c7e0-4ec4-8599-a61c6ac2628d")] +[assembly: Guid("95f1f07c-4d92-4742-bd07-e5b805aab651")] diff --git a/src/Services/Ordering/Ordering.Infrastructure/project.json b/src/Services/Ordering/Ordering.Infrastructure/project.json new file mode 100644 index 000000000..03c2eeef4 --- /dev/null +++ b/src/Services/Ordering/Ordering.Infrastructure/project.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0-*", + + "dependencies": { + "NETStandard.Library": "1.6.0", + "Microsoft.EntityFrameworkCore": "1.0.1", + "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", + "Ordering.Domain": "1.0.0-*" + }, + + "frameworks": { + "netstandard1.6": { + "imports": "dnxcore50" + } + } +} diff --git a/src/Services/Ordering/Ordering.SqlData/UnitOfWork/DBContextUtil.cs b/src/Services/Ordering/Ordering.SqlData/UnitOfWork/DBContextUtil.cs deleted file mode 100644 index 3672653f2..000000000 --- a/src/Services/Ordering/Ordering.SqlData/UnitOfWork/DBContextUtil.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork -{ - public class DbContextUtil - { - public static DbContextOptions CreateNewContextOptionsForInMemoryDB() - { - // Create a fresh service provider, and therefore a fresh - // InMemory database instance. - var serviceProvider = new ServiceCollection() - .AddEntityFrameworkInMemoryDatabase() - .BuildServiceProvider(); - - // Create a new options instance telling the context to use an - // InMemory database and the new service provider. - var builder = new DbContextOptionsBuilder(); - builder.UseInMemoryDatabase() - .UseInternalServiceProvider(serviceProvider); - - return builder.Options; - } - - public static DbContextOptions CreateNewContextOptionsForSqlDb() - { - // Create a new options instance telling the context to use a Sql database - var builder = new DbContextOptionsBuilder(); - - //SQL LocalDB - //var connString = @"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; - - //SQL SERVER on-premises - - //(Integrated Security) var connString = @"Server=CESARDLBOOKVHD;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; - - //(SQL Server Authentication) - var connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"; - - //SQL LOCALDB - builder.UseSqlServer(connString); - - return builder.Options; - } - } -} diff --git a/src/Services/Ordering/Ordering.SqlData/UnitOfWork/OrderingDbContext.cs b/src/Services/Ordering/Ordering.SqlData/UnitOfWork/OrderingDbContext.cs deleted file mode 100644 index e35c3e540..000000000 --- a/src/Services/Ordering/Ordering.SqlData/UnitOfWork/OrderingDbContext.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; - -namespace Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork -{ - public class OrderingDbContext : DbContext, IUnitOfWork - { - public OrderingDbContext(DbContextOptions options) - : base(options) - { } - - public DbSet Orders { get; set; } - - //(CDLTLL) - /* - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - //If running from ASP.NET Core, config is done at StartUp.cs --> ConfigureServices() outside - //and injected through DI later on. The following config is used when running Tests or similar contexts - if (!optionsBuilder.IsConfigured) - { - //SQL LocalDB - //var connString = @"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; - - //SQL SERVER on-premises - - //(Integrated Security) - //var connString = @"Server=CESARDLBOOKVHD;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; - - //(SQL Server Authentication) - var connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"; - - //SQL LOCALDB - optionsBuilder.UseSqlServer(connString); - - } - } - */ - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - // Add your customizations after calling base.OnModelCreating(builder); - - //Sequence to be used as part of the OrderNumber - modelBuilder.HasSequence("OrderSequences", schema: "shared") - .StartsAt(1001) - .IncrementsBy(1); - - modelBuilder.Entity() - .Property(o => o.SequenceNumber) - .HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); - - } - - public async Task CommitAsync() - { - int changes = 0; - - try - { - //(CDLTLL) TBD - //RemoveOrphanedChilds(); - - changes = await base.SaveChangesAsync(); - } - catch (Exception ex) - { - //(CDLTLL) TBD - //RejectChanges(); - throw ex; - } - - return changes; - } - } -} diff --git a/src/Services/Ordering/Ordering.SqlData/project.json b/src/Services/Ordering/Ordering.SqlData/project.json deleted file mode 100644 index 8ede54bb4..000000000 --- a/src/Services/Ordering/Ordering.SqlData/project.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": "1.0.0-*", - - "dependencies": { - "Microsoft.EntityFrameworkCore": "1.0.0", - "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", - "NETStandard.Library": "1.6.0", - "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0", - "Ordering.Domain": "1.0.0-*", - "Microsoft.EntityFrameworkCore.InMemory": "1.0.0" - }, - - "frameworks": { - "netstandard1.6": { - "imports": [ "dnxcore50", "portable-net451+win8" ] - } - - } -} diff --git a/test/Services/Ordering.Test/DataIntegrationTests.cs b/test/Services/Ordering.Test/DataIntegrationTests.cs deleted file mode 100644 index ff0c93f65..000000000 --- a/test/Services/Ordering.Test/DataIntegrationTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Linq; -using Xunit; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; -using Microsoft.eShopOnContainers.Services.Ordering.Domain.Contracts; -using Microsoft.eShopOnContainers.Services.Ordering.SqlData.Repositories; -using Microsoft.EntityFrameworkCore; - -namespace DataIntegrationTests -{ - //Basic documentation for Testing EF Core classes - // http://ef.readthedocs.io/en/latest/miscellaneous/testing.html - public class Tests - { - [Fact] - public async void Add_order_to_data_model() - { - // All contexts that share the same service provider will share the same database - - //Using InMemory DB - //var options = DbContextUtil.CreateNewContextOptionsForInMemoryDB(); - - //Using Sql Server - var options = DbContextUtil.CreateNewContextOptionsForSqlDb(); - - // Run the test against one instance of the context - using (var context = new OrderingDbContext(options)) - { - IOrderRepository orderRepository = new OrderRepository(context); - - //Create generic Address ValueObject - Address sampleAddress = new Address("15703 NE 61st Ct.", - "Redmond", - "Washington", - "WA", - "United States", - "US", - "98052", - 47.661492, - -122.131309 - ); - //Create sample Orders - Order order1 = new Order(Guid.NewGuid(), sampleAddress, sampleAddress); - - //Add a few OrderItems - order1.AddNewOrderItem(Guid.NewGuid(), 2, 25, 30); - order1.AddNewOrderItem(Guid.NewGuid(), 1, 58, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 1, 60, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 3, 12, 0); - order1.AddNewOrderItem(Guid.NewGuid(), 5, 3, 0); - - orderRepository.Add(order1); - int numChanges = await orderRepository.UnitOfWork.CommitAsync(); - - //With no Async Repository - //context.Orders.Add(order1); - //context.SaveChanges(); - - } - - //// Use a separate instance of the context to verify correct data was saved to database - using (var context = new OrderingDbContext(options)) - { - var orders = context.Orders - .Include(o => o.ShippingAddress) - .Include(o => o.BillingAddress) - .ToList(); - //Could be using .Load() if you don't want to create a List - - //OTHER SAMPLE - //var company = context.Companies - // .Include(co => co.Employees).ThenInclude(emp => emp.Employee_Car) - // .Include(co => co.Employees).ThenInclude(emp => emp.Employee_Country) - // .FirstOrDefault(co => co.companyID == companyID); - - //Assert when running test with a clean In-Memory DB - //Assert.Equal(1, context.Orders.Count()); - - string cityName = orders.First().ShippingAddress.City; - Assert.Equal("Redmond", cityName); - } - } - - } -} diff --git a/test/Services/Ordering.Test/project.json b/test/Services/Ordering.Test/project.json index ab108e9cd..ca7f87942 100644 --- a/test/Services/Ordering.Test/project.json +++ b/test/Services/Ordering.Test/project.json @@ -4,13 +4,7 @@ "debugType": "portable" }, "dependencies": { - "System.Runtime.Serialization.Primitives": "4.1.1", - "xunit": "2.1.0", - "dotnet-test-xunit": "2.2.0-preview2-build1029", - "Ordering.Domain": "1.0.0-*", - "Ordering.SqlData": "1.0.0-*", - "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", - "Microsoft.EntityFrameworkCore.InMemory": "1.0.0" + }, "testRunner": "xunit", "frameworks": {