public static void CommunicationObject_Sync_Open_Close_Events_Fire() { MockCommunicationObject mco = new MockCommunicationObject(); List <string> openEventsFired = new List <string>(); List <string> closeEventsFired = new List <string>(); TimeSpan timeout = TimeSpan.FromSeconds(30); // *** SETUP *** \\ MockCommunicationObject.InterceptAllOpenEvents(mco, openEventsFired); MockCommunicationObject.InterceptAllCloseEvents(mco, closeEventsFired); // *** EXECUTE *** \\ mco.Open(timeout); mco.Close(timeout); // *** VALIDATE *** \\ string expectedOpens = "Opening,Opened"; string actualOpens = String.Join(",", openEventsFired); Assert.True(String.Equals(expectedOpens, actualOpens, StringComparison.Ordinal), String.Format("Expected open events to be '{0}' but actual was '{1}'.", expectedOpens, actualOpens)); string expectedCloses = "Closing,Closed"; string actualCloses = String.Join(",", closeEventsFired); Assert.True(String.Equals(expectedCloses, actualCloses, StringComparison.Ordinal), String.Format("Expected close events to be '{0}' but actual was '{1}'.", expectedCloses, actualCloses)); }
public static void CommunicationObject_Async_Open_Close_Events_Fire() { MockCommunicationObject mco = new MockCommunicationObject(); List <string> openEventsFired = new List <string>(); List <string> closeEventsFired = new List <string>(); TimeSpan timeout = TimeSpan.FromMinutes(30); // *** SETUP *** \\ MockCommunicationObject.InterceptAllOpenEvents(mco, openEventsFired); MockCommunicationObject.InterceptAllCloseEvents(mco, closeEventsFired); // *** EXECUTE *** \\ IAsyncResult openAr = mco.BeginOpen(timeout, callback: null, state: null); mco.OpenAsyncResult.Complete(); mco.EndOpen(openAr); IAsyncResult closeAr = mco.BeginClose(timeout, callback: null, state: null); mco.CloseAsyncResult.Complete(); mco.EndClose(closeAr); // *** VALIDATE *** \\ string expectedOpens = "Opening,Opened"; string actualOpens = String.Join(",", openEventsFired); Assert.True(String.Equals(expectedOpens, actualOpens, StringComparison.Ordinal), String.Format("Expected open events to be '{0}' but actual was '{1}'.", expectedOpens, actualOpens)); string expectedCloses = "Closing,Closed"; string actualCloses = String.Join(",", closeEventsFired); Assert.True(String.Equals(expectedCloses, actualCloses, StringComparison.Ordinal), String.Format("Expected close events to be '{0}' but actual was '{1}'.", expectedCloses, actualCloses)); }