public void TestUnregisterInstance() { // Initialize entities DataWriter writer = _publisher.CreateDataWriter(_topic); Assert.IsNotNull(writer); TestStructDataWriter dataWriter = new TestStructDataWriter(writer); // Unregister not registered instance ReturnCode result = dataWriter.UnregisterInstance(new TestStruct { Id = 1 }); Assert.AreEqual(ReturnCode.PreconditionNotMet, result); // Register an instance TestStruct instance1 = new TestStruct { Id = 1 }; InstanceHandle handle1 = dataWriter.RegisterInstance(instance1); Assert.AreNotEqual(InstanceHandle.HandleNil, handle1); // Unregister the previous registered instance with the simplest overload result = dataWriter.UnregisterInstance(new TestStruct { Id = 1 }); Assert.AreEqual(ReturnCode.Ok, result); // Register a new instance TestStruct instance2 = new TestStruct { Id = 2 }; InstanceHandle handle2 = dataWriter.RegisterInstance(instance2); Assert.AreNotEqual(InstanceHandle.HandleNil, handle2); // Unregister the previous registered instance with the handle result = dataWriter.UnregisterInstance(new TestStruct { Id = 2 }, handle2); Assert.AreEqual(ReturnCode.Ok, result); // Register a new instance TestStruct instance3 = new TestStruct { Id = 3 }; InstanceHandle handle3 = dataWriter.RegisterInstance(instance3); Assert.AreNotEqual(InstanceHandle.HandleNil, handle3); // Unregister the previous registered instance with the handle and the timestamp result = dataWriter.UnregisterInstance(new TestStruct { Id = 3 }, handle3, DateTime.Now.ToTimestamp()); Assert.AreEqual(ReturnCode.Ok, result); }