public static void CommunicationObject_Sync_Close_Propagates_Exception() { MockCommunicationObject mco = new MockCommunicationObject(); TimeSpan timeout = TimeSpan.FromSeconds(30); string exceptionMessage = "Expected exception"; // *** SETUP *** \\ mco.OnCloseOverride = (t) => { throw new InvalidOperationException(exceptionMessage); }; // *** EXECUTE *** \\ mco.Open(timeout); InvalidOperationException actualException = Assert.Throws <InvalidOperationException>(() => { mco.Close(timeout); }); // *** VALIDATE *** \\ Assert.True(String.Equals(exceptionMessage, actualException.Message), String.Format("Expected exception message '{0}' but actual was '{1}'", exceptionMessage, actualException.Message)); }
public static void CommunicationObject_Sync_Open_Close_States_Transition() { MockCommunicationObject mco = new MockCommunicationObject(); TimeSpan timeout = TimeSpan.FromSeconds(30); CommunicationStateData data = new CommunicationStateData(); // *** SETUP *** \\ InterceptAllStateChanges(mco, data); // *** EXECUTE *** \\ mco.Open(timeout); mco.Close(timeout); // *** VALIDATE *** \\ Assert.True(data.StateAfterCreate == CommunicationState.Created, String.Format("CommunicationState after creation was '{0}' but expected 'Created'", data.StateAfterCreate)); Assert.True(data.StateEnterOnOpening == CommunicationState.Opening, String.Format("CommunicationState entering OnOpening was '{0}' but expected 'Opening'", data.StateEnterOnOpening)); Assert.True(data.StateLeaveOnOpening == CommunicationState.Opening, String.Format("CommunicationState leaving OnOpening was '{0}' but expected 'Opening'", data.StateLeaveOnOpening)); Assert.True(data.StateEnterOnOpen == CommunicationState.Opening, String.Format("CommunicationState entering OnOpen was '{0}' but expected 'Opening'", data.StateEnterOnOpen)); Assert.True(data.StateLeaveOnOpen == CommunicationState.Opening, String.Format("CommunicationState leaving OnOpen was '{0}' but expected 'Opening'", data.StateLeaveOnOpen)); Assert.True(data.StateEnterOnOpened == CommunicationState.Opening, String.Format("CommunicationState entering OnOpened was '{0}' but expected 'Opening'", data.StateEnterOnOpened)); Assert.True(data.StateLeaveOnOpened == CommunicationState.Opened, String.Format("CommunicationState leaving OnOpened was '{0}' but expected 'Opened'", data.StateLeaveOnOpened)); Assert.True(data.StateEnterOnClosing == CommunicationState.Closing, String.Format("CommunicationState entering OnClosing was '{0}' but expected 'Closing'", data.StateEnterOnClosing)); Assert.True(data.StateLeaveOnClosing == CommunicationState.Closing, String.Format("CommunicationState leaving OnClosing was '{0}' but expected 'Closing'", data.StateLeaveOnClosing)); Assert.True(data.StateEnterOnClose == CommunicationState.Closing, String.Format("CommunicationState entering OnClose was '{0}' but expected 'Closing'", data.StateEnterOnClose)); Assert.True(data.StateLeaveOnClose == CommunicationState.Closing, String.Format("CommunicationState leaving OnClose was '{0}' but expected 'Closing'", data.StateLeaveOnClose)); Assert.True(data.StateEnterOnClosed == CommunicationState.Closing, String.Format("CommunicationState entering OnClosed was '{0}' but expected 'Closing'", data.StateEnterOnClosed)); Assert.True(data.StateLeaveOnClosed == CommunicationState.Closed, String.Format("CommunicationState leaving OnClosed was '{0}' but expected 'Closed'", data.StateLeaveOnClosed)); }
public static void CommunicationObject_Sync_Open_Close_Methods_Called() { MockCommunicationObject mco = new MockCommunicationObject(); List <string> openMethodsCalled = new List <string>(); List <string> closeMethodsCalled = new List <string>(); TimeSpan timeout = TimeSpan.FromSeconds(30); // *** SETUP *** \\ InterceptAllOpenMethods(mco, openMethodsCalled); InterceptAllCloseMethods(mco, closeMethodsCalled); // *** EXECUTE *** \\ mco.Open(timeout); mco.Close(timeout); // *** VALIDATE *** \\ string expectedOpens = "OnOpening,OnOpen,OnOpened"; string actualOpens = String.Join(",", openMethodsCalled); Assert.True(String.Equals(expectedOpens, actualOpens, StringComparison.Ordinal), String.Format("Expected open methods to be '{0}' but actual was '{1}'.", expectedOpens, actualOpens)); string expectedCloses = "OnClosing,OnClose,OnClosed"; string actualCloses = String.Join(",", closeMethodsCalled); Assert.True(String.Equals(expectedCloses, actualCloses, StringComparison.Ordinal), String.Format("Expected close methods to be '{0}' but actual was '{1}'.", expectedCloses, actualCloses)); }
public static void CommunicationObject_Sync_Open_Close_Methods_Called() { MockCommunicationObject mco = new MockCommunicationObject(); List<string> openMethodsCalled = new List<string>(); List<string> closeMethodsCalled = new List<string>(); TimeSpan timeout = TimeSpan.FromSeconds(30); // *** SETUP *** \\ MockCommunicationObject.InterceptAllOpenMethods(mco, openMethodsCalled); MockCommunicationObject.InterceptAllCloseMethods(mco, closeMethodsCalled); // *** EXECUTE *** \\ mco.Open(timeout); mco.Close(timeout); // *** VALIDATE *** \\ string expectedOpens = "OnOpening,OnOpen,OnOpened"; string actualOpens = String.Join(",", openMethodsCalled); Assert.True(String.Equals(expectedOpens, actualOpens, StringComparison.Ordinal), String.Format("Expected open methods to be '{0}' but actual was '{1}'.", expectedOpens, actualOpens)); string expectedCloses = "OnClosing,OnClose,OnClosed"; string actualCloses = String.Join(",", closeMethodsCalled); Assert.True(String.Equals(expectedCloses, actualCloses, StringComparison.Ordinal), String.Format("Expected close methods to be '{0}' but actual was '{1}'.", expectedCloses, actualCloses)); }
public static void CommunicationObject_Sync_Close_Propagates_Exception() { MockCommunicationObject mco = new MockCommunicationObject(); TimeSpan timeout = TimeSpan.FromSeconds(30); string exceptionMessage = "Expected exception"; // *** SETUP *** \\ mco.OnCloseOverride = (t) => { throw new InvalidOperationException(exceptionMessage); }; // *** EXECUTE *** \\ mco.Open(timeout); InvalidOperationException actualException = Assert.Throws<InvalidOperationException>(() => { mco.Close(timeout); }); // *** VALIDATE *** \\ Assert.True(String.Equals(exceptionMessage, actualException.Message), String.Format("Expected exception message '{0}' but actual was '{1}'", exceptionMessage, actualException.Message)); }
public static void CommunicationObject_Sync_Open_Close_States_Transition() { MockCommunicationObject mco = new MockCommunicationObject(); TimeSpan timeout = TimeSpan.FromSeconds(30); CommunicationStateData data = new CommunicationStateData(); // *** SETUP *** \\ MockCommunicationObject.InterceptAllStateChanges(mco, data); // *** EXECUTE *** \\ mco.Open(timeout); mco.Close(timeout); // *** VALIDATE *** \\ Assert.True(data.StateAfterCreate == CommunicationState.Created, String.Format("CommunicationState after creation was '{0}' but expected 'Created'", data.StateAfterCreate)); Assert.True(data.StateEnterOnOpening == CommunicationState.Opening, String.Format("CommunicationState entering OnOpening was '{0}' but expected 'Opening'", data.StateEnterOnOpening)); Assert.True(data.StateLeaveOnOpening == CommunicationState.Opening, String.Format("CommunicationState leaving OnOpening was '{0}' but expected 'Opening'", data.StateLeaveOnOpening)); Assert.True(data.StateEnterOnOpen == CommunicationState.Opening, String.Format("CommunicationState entering OnOpen was '{0}' but expected 'Opening'", data.StateEnterOnOpen)); Assert.True(data.StateLeaveOnOpen == CommunicationState.Opening, String.Format("CommunicationState leaving OnOpen was '{0}' but expected 'Opening'", data.StateLeaveOnOpen)); Assert.True(data.StateEnterOnOpened == CommunicationState.Opening, String.Format("CommunicationState entering OnOpened was '{0}' but expected 'Opening'", data.StateEnterOnOpened)); Assert.True(data.StateLeaveOnOpened == CommunicationState.Opened, String.Format("CommunicationState leaving OnOpened was '{0}' but expected 'Opened'", data.StateLeaveOnOpened)); Assert.True(data.StateEnterOnClosing == CommunicationState.Closing, String.Format("CommunicationState entering OnClosing was '{0}' but expected 'Closing'", data.StateEnterOnClosing)); Assert.True(data.StateLeaveOnClosing == CommunicationState.Closing, String.Format("CommunicationState leaving OnClosing was '{0}' but expected 'Closing'", data.StateLeaveOnClosing)); Assert.True(data.StateEnterOnClose == CommunicationState.Closing, String.Format("CommunicationState entering OnClose was '{0}' but expected 'Closing'", data.StateEnterOnClose)); Assert.True(data.StateLeaveOnClose == CommunicationState.Closing, String.Format("CommunicationState leaving OnClose was '{0}' but expected 'Closing'", data.StateLeaveOnClose)); Assert.True(data.StateEnterOnClosed == CommunicationState.Closing, String.Format("CommunicationState entering OnClosed was '{0}' but expected 'Closing'", data.StateEnterOnClosed)); Assert.True(data.StateLeaveOnClosed == CommunicationState.Closed, String.Format("CommunicationState leaving OnClosed was '{0}' but expected 'Closed'", data.StateLeaveOnClosed)); }