-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathXmlLedgerTests.cs
More file actions
114 lines (93 loc) · 2.38 KB
/
XmlLedgerTests.cs
File metadata and controls
114 lines (93 loc) · 2.38 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
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
using System.Text;
using Waher.Persistence.Files;
using Waher.Persistence.Serialization;
using Waher.Persistence.XmlLedger.Test.Classes;
using Waher.Runtime.Inventory;
namespace Waher.Persistence.XmlLedger.Test
{
[TestClass]
public class XmlLedgerTests
{
private static FilesProvider? provider;
private XmlFileLedger? ledger;
public TestContext TestContext { get; set; }
[AssemblyInitialize]
public static async Task AssemblyInitialize(TestContext _)
{
Types.Initialize(
typeof(Database).Assembly,
typeof(FilesProvider).Assembly,
typeof(ObjectSerializer).Assembly,
typeof(XmlLedgerTests).Assembly);
provider = await FilesProvider.CreateAsync("Data", "Default", 8192, 10000, 8192, Encoding.UTF8, 10000, true);
Database.Register(provider, false);
Assert.IsTrue(await Types.StartAllModules(10000));
Ledger.StartListeningToDatabaseEvents();
}
[AssemblyCleanup]
public static async Task AssemblyCleanup()
{
await Types.StopAllModules();
Ledger.StopListeningToDatabaseEvents();
}
[TestInitialize]
public async Task TestInitialize()
{
string FileName = Path.Combine("Data", (this.TestContext.TestName ?? "Test") + ".xml");
if (File.Exists(FileName))
File.Delete(FileName);
Ledger.Register(this.ledger = new XmlFileLedger(FileName, 7), false);
await this.ledger.Start();
}
[TestCleanup]
public async Task TestCleanup()
{
await Task.Delay(1000, CancellationToken.None);
if (this.ledger is not null)
await this.ledger.Stop();
}
[TestMethod]
public async Task Test_01_NewEntry()
{
await CreateNewObject();
}
private static async Task<SimpleObject> CreateNewObject()
{
SimpleObject Result = new()
{
Text = "Hello World",
Number1 = 10,
Number2 = 3.1415927,
Flag = true
};
await Database.Insert(Result);
return Result;
}
[TestMethod]
public async Task Test_02_UpdateEntry()
{
SimpleObject Obj = await CreateNewObject();
int i;
for (i = 0; i < 10; i++)
{
Obj.Text += "...";
Obj.Number1++;
Obj.Number2--;
Obj.Flag = !Obj.Flag;
await Database.Update(Obj);
}
}
[TestMethod]
public async Task Test_03_DeleteEntry()
{
SimpleObject Obj = await CreateNewObject();
await Database.Delete(Obj);
}
[TestMethod]
public async Task Test_04_ClearCollection()
{
await CreateNewObject();
await Database.Clear("Test");
}
}
}