public void Test_BasicEventListenerApi() { var rdk = new RoboDK(); rdk.Connect(); // Open Event Channel var eventListener = rdk.OpenRoboDkEventChannel(); var noEvent = eventListener.WaitForEvent(); noEvent.EventType.Should().Be(EventType.NoEvent); // Test Simple Event var frame1 = rdk.AddFrame("Frame1"); var itemMovedEvent = eventListener.WaitForEvent(); itemMovedEvent.EventType.Should().Be(EventType.ItemMovedPose); itemMovedEvent.Item.Name().Should().Be("Frame1"); // The RoboDK link must be set to the RoboDK API instance itemMovedEvent.Item.RDK().RoboDKClientPort.Should().Be(rdk.RoboDKClientPort); // Open a second event channel var eventListener2 = rdk.OpenRoboDkEventChannel(); var frame2 = rdk.AddFrame("Frame2"); var eventOnChannel1 = eventListener.WaitForEvent(); var eventOnChannel2 = eventListener2.WaitForEvent(); eventOnChannel1.EventType.Should().Be(EventType.ItemMovedPose); eventOnChannel1.Item.Name().Should().Be("Frame2"); eventOnChannel2.EventType.Should().Be(EventType.ItemMovedPose); eventOnChannel2.Item.Name().Should().Be("Frame2"); eventOnChannel1.Item.RDK().RoboDKClientPort.Should().Be(rdk.RoboDKClientPort); eventOnChannel2.Item.RDK().RoboDKClientPort.Should().Be(rdk.RoboDKClientPort); // After closing an event channel we should get an exception when calling WaitForEvent eventListener.Close(); var whenAction = new Action(() => eventListener.WaitForEvent()); whenAction.Should().Throw <ObjectDisposedException>(); }
public void Test_RoboDkThrowsObjectDisposedExceptionWhenCallingAnApiMethodAfterDispose() { // Given var rdk = new RoboDK(); rdk.Connect().Should().BeTrue(); // When rdk.Dispose(); // Then var whenAction = new Action(() => rdk.AddFrame("TestFrame")); whenAction.Should().Throw <ObjectDisposedException>(); }