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
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR;
using Tango.PMR.Embroidery;
using Tango.DataStore;
using Tango.DataStore.Lite;
using Tango.Core.IO;
using Tango.DataStore.EF;
using Tango.PMR.Stubs;
using Tango.Transport;
using Tango.DataStore.Remote;
namespace Tango.UnitTesting.DataStore
{
[TestClass]
[TestCategory("DataStore")]
public class DataStore_TST
{
[TestMethod]
public void LiteDB_DataStore_Working()
{
var tempFile = TemporaryManager.Default.CreateImaginaryFile();
Run_Test(new LiteDBDataStoreManager(tempFile));
tempFile.Delete();
}
[TestMethod]
public void EF_DataStore_Working()
{
Run_Test(new EFDataStoreManager());
}
[TestMethod]
public void Remote_Data_Store_Working()
{
CalculateRequest calc = new CalculateRequest()
{
A = 10,
B = 15,
};
RemoteDataStoreGetResponse response = new RemoteDataStoreGetResponse();
response.ProtoObject = DataStoreProtoObject.FromMessage(calc);
byte[] data = GenericMessageSerializer.Serialize<RemoteDataStoreGetResponse>(response, PMR.Integration.GenericMessageProtocol.Bson);
RemoteDataStoreGetResponse des = GenericMessageSerializer.Deserialize<RemoteDataStoreGetResponse>(data, PMR.Integration.GenericMessageProtocol.Bson);
CalculateRequest cc = des.ProtoObject.Message as CalculateRequest;
Assert.AreEqual<CalculateRequest>(calc, cc);
}
private void Run_Test(IDataStoreManager manager)
{
IDataStoreCollection collection = manager.GetCollection("TEST");
{
collection.Put<int>("int", 10);
int value = collection.Get<int>("int");
Assert.AreEqual<int>(value, 10);
}
{
collection.Put<float>("float", 10f);
float value = collection.Get<float>("float");
Assert.AreEqual<float>(value, 10f);
}
{
collection.Put<double>("double", 10d);
double value = collection.Get<double>("double");
Assert.AreEqual<double>(value, 10d);
}
{
collection.Put<bool>("bool", true);
bool value = collection.Get<bool>("bool");
Assert.AreEqual<bool>(value, true);
}
{
collection.Put<string>("string", "some value");
string value = collection.Get<string>("string");
Assert.AreEqual<string>(value, "some value");
}
{
collection.Put<byte[]>("bytes", new byte[] { 255 });
byte[] value = collection.Get<byte[]>("bytes");
Assert.AreEqual<byte>(value[0], 255);
}
{
collection.Put<CalculateRequest>("calc", new CalculateRequest() { A = 10, B = 15 });
CalculateRequest value = collection.Get<CalculateRequest>("calc");
Assert.AreEqual<CalculateRequest>(value, new CalculateRequest() { A = 10, B = 15 });
}
Assert.IsTrue(collection.Count() == 7);
Assert.ThrowsException<NotSupportedException>(() => collection.Put<DataStore_TST>("somekey", this));
collection.Delete("int");
Assert.ThrowsException<KeyNotFoundException>(() => collection.Get<int>("int"));
collection.Delete("float");
Assert.ThrowsException<KeyNotFoundException>(() => collection.Get<float>("float"));
Assert.IsTrue(collection.Count() == 5);
collection.DeleteAll();
Assert.IsTrue(collection.Count() == 0);
manager.Dispose();
}
}
}
|