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(response, PMR.Integration.GenericMessageProtocol.Bson); RemoteDataStoreGetResponse des = GenericMessageSerializer.Deserialize(data, PMR.Integration.GenericMessageProtocol.Bson); CalculateRequest cc = des.ProtoObject.Message as CalculateRequest; Assert.AreEqual(calc, cc); } private void Run_Test(IDataStoreManager manager) { IDataStoreCollection collection = manager.GetCollection("TEST"); { collection.Put("int", 10); int value = collection.Get("int"); Assert.AreEqual(value, 10); } { collection.Put("float", 10f); float value = collection.Get("float"); Assert.AreEqual(value, 10f); } { collection.Put("double", 10d); double value = collection.Get("double"); Assert.AreEqual(value, 10d); } { collection.Put("bool", true); bool value = collection.Get("bool"); Assert.AreEqual(value, true); } { collection.Put("string", "some value"); string value = collection.Get("string"); Assert.AreEqual(value, "some value"); } { collection.Put("bytes", new byte[] { 255 }); byte[] value = collection.Get("bytes"); Assert.AreEqual(value[0], 255); } { collection.Put("calc", new CalculateRequest() { A = 10, B = 15 }); CalculateRequest value = collection.Get("calc"); Assert.AreEqual(value, new CalculateRequest() { A = 10, B = 15 }); } Assert.IsTrue(collection.Count() == 7); Assert.ThrowsException(() => collection.Put("somekey", this)); collection.Delete("int"); Assert.ThrowsException(() => collection.Get("int")); collection.Delete("float"); Assert.ThrowsException(() => collection.Get("float")); Assert.IsTrue(collection.Count() == 5); collection.DeleteAll(); Assert.IsTrue(collection.Count() == 0); manager.Dispose(); } } }