-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathManageTests.cs
172 lines (152 loc) · 5.83 KB
/
ManageTests.cs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Reinforced.Samples.ToyFactory.Logic.Channels;
using Reinforced.Samples.ToyFactory.Logic.Channels.Queries;
using Reinforced.Samples.ToyFactory.Logic.Entities;
using Reinforced.Samples.ToyFactory.Logic.Warehouse.Dto;
using Reinforced.Samples.ToyFactory.Logic.Warehouse.Entities;
using Reinforced.Samples.ToyFactory.Logic.Warehouse.Entities.Suppliement;
using Reinforced.Samples.ToyFactory.Logic.Warehouse.Services;
using Reinforced.Samples.ToyFactory.Tests.Infrastructure;
//using Reinforced.Samples.ToyFactory.Tests.WarehouseTests.CreateMeasurementUnit;
using Reinforced.Samples.ToyFactory.Tests.WarehouseTests.RenameMeasurementUnit;
using Reinforced.Samples.ToyFactory.Tests.WarehouseTests.SupplyCreationPipeline;
//using Reinforced.Samples.ToyFactory.Tests.WarehouseTests.RenameMeasurementUnit;
//using Reinforced.Samples.ToyFactory.Tests.WarehouseTests.TestAnonymousQuery;
using Reinforced.Tecture;
using Reinforced.Tecture.Aspects.DirectSql.Queries;
using Reinforced.Tecture.Aspects.Orm.Queries;
using Reinforced.Tecture.Aspects.Time.Queries;
using Reinforced.Tecture.Testing;
using Xunit;
using Xunit.Abstractions;
namespace Reinforced.Samples.ToyFactory.Tests.WarehouseTests
{
class TestClassB
{
public string Name { get; set; }
}
class TestClassA
{
public TestClassA()
{
TestField = new Dictionary<Guid, TestClassB>();
TestField[Guid.NewGuid()] = new TestClassB() { Name = "AAA" };
TestField[Guid.NewGuid()] = new TestClassB() { Name = "BBB" };
TestField[Guid.NewGuid()] = new TestClassB() { Name = "CCC" };
}
public Dictionary<Guid,TestClassB> TestField { get; set; }
}
public class ManageTests : TectureTestBase
{
[Fact]
public async Task CreateMeasurementUnit()
{
// using var c = Case
// // <CreateMeasurementUnit_TestData>
// (out ITecture ctx);
// var instance = new TestClassA();
// var test = ctx.From<Logic.Channels.System>()
// .Date().Test2(instance);
//
// Output.WriteLine(c.Text());
//
//c.Validate<CreateMeasurementUnit_Validation>();
}
[Fact]
public void RenameMeasurementUnit()
{
using var c = Case
<RenameMeasurementUnit_TestData>
(out ITecture ctx);
var a = ctx.Do<Manage>().CreateMeasurementUnit("Kilograms", "kG");
ctx.Save();
var mu = ctx.From<Db>().Key(a);
ctx.Let<Manage>().RenameMeasurementUnit(mu,"Kilo","kg");
ctx.Save();
ctx.Do<Manage>().DeleteMeasurementUnit(mu);
ctx.Save();
Output.WriteLine(c.Text());
c.Validate<RenameMeasurementUnit_Validation>();
}
class IdName
{
public IdName(int id, string name)
{
Id = id;
Name = name;
}
public int Id { get; set; }
public string Name { get; set; }
}
[Fact]
public void SupplyCreationPipeline()
{
using var c = Case
//<SupplyCreationPipeline_TestData>
(out ITecture ctx);
try
{
var m = ctx.Do<Manage>();
var unit = m.CreateMeasurementUnit("Kilograms", "kG");
ctx.Save();
var res1 = m.CreateResource("resource1", "kG");
var res2 = m.CreateResource("resource2", "kG");
var res3 = m.CreateResource("resource3", "kG");
ctx.Save();
var id = ctx.From<Db>().Key(res2);
var supply = ctx.Do<Supply>();
var supp = supply.CreateResourceSupply("Supply1", new[]
{
new ResourceItemDto()
{
Name = "resource1", Quantity = 10
},
new ResourceItemDto()
{
Id = id, Quantity = 10
},
new ResourceItemDto()
{
Name = "resource3", Quantity = 10
},
});
ctx.Save();
var supplyId = ctx.From<Db>().Key(supp);
supply.FinishResourceSupply(supplyId);
ctx.Save();
}
catch(Exception ex)
{
var text = c.Text();
Output.WriteLine(c.Text());
//c.Validate<SupplyCreationPipeline_Validation>();
}
}
[Fact]
public void TestAnonymousQuery()
{
using var c = Case
//<TestAnonymousQuery_TestData>
(out ITecture ctx);
var re = ctx.From<Db>().Get<Resource>().ById(183, x => new {x.Name, x.StockQuantity});
//c.Validate<TestAnonymousQuery_Validation>();
Output.WriteLine(c.Text());
}
[Fact(Skip = "For debug purposes")]
public void TestNestedSQLQuery()
{
using var c = Case(out ITecture ctx);
var re = ctx.From<Db>()
.SqlQuery<ResourceSupplyItem>
(r=>$"SELECT {r.Resource.Name}, {r.ResourceSupply.ItemsCount} FROM {r} WHERE {r.ResourceSupplyId>10}")
.As<Resource>();
Output.WriteLine(c.Text());
}
public ManageTests(ITestOutputHelper output) : base(output)
{
}
}
}