public void TestSerialisingInterfaceTypes() { // tests control of the serialisation type // - interface types using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true))) { using (CoreServer server = new CoreServer(loggerRef, "UTT", NodeType.Router)) { // start server server.Start(); using (ICoreClient client = new CoreClientFactory(loggerRef).SetEnv("UTT").Create()) { AssetMeasureValue codeValueInstance = new AssetMeasureValue() { Code = "Test", Description = "This is a test", Source = "UnitTest" }; IFpMLCodeValue codeValueInterface = codeValueInstance; // save reference item client.SaveObject(codeValueInstance, "Test0", null, TimeSpan.MaxValue); ICoreItem itemA = client.LoadItem("Test0"); Assert.AreEqual(typeof(AssetMeasureValue).FullName, itemA.DataTypeName); // test interface and instance both serialise identically { client.SaveUntypedObject(codeValueInterface, "Test1", null); ICoreItem itemB = client.LoadItem("Test1"); Assert.AreEqual(typeof(AssetMeasureValue).FullName, itemB.DataTypeName); Assert.AreEqual(itemA.Text, itemB.Text); } { client.SaveObject((AssetMeasureValue)codeValueInterface, "Test2", null, TimeSpan.MaxValue); ICoreItem itemB = client.LoadItem("Test2"); Assert.AreEqual(typeof(AssetMeasureValue).FullName, itemB.DataTypeName); Assert.AreEqual(itemA.Text, itemB.Text); } { // this should fail because interfaces cant be serialised UnitTestHelper.AssertThrows <ArgumentException>("Cannot be an interface type!\r\nParameter name: dataType", () => { client.SaveObject(codeValueInterface, "Test3", null, TimeSpan.MaxValue); }); } { // note: this silently binds to SaveObject<IFpMLCodeValue>(...) which should fail UnitTestHelper.AssertThrows <ArgumentException>("Cannot be an interface type!\r\nParameter name: dataType", () => { client.SaveObject(codeValueInterface, "Test4", null, TimeSpan.MaxValue); }); } } // shutdown server.Stop(); } } }