forked from dotnet-architecture/eShopOnContainers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (60 loc) · 3 KB
/
Copy pathProgram.cs
File metadata and controls
71 lines (60 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Linq;
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 eShopConsole
{
public class Program
{
public static void Main(string[] args)
{
// 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);
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();
string cityName = orders.First<Order>().ShippingAddress.City;
Console.WriteLine("City name retreived from SQL Server: "+cityName);
}
}
}
}