Ejemplo n.º 1
0
    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));
    }
Ejemplo n.º 2
0
    public static void CommunicationObject_Async_Open_Close_States_Transition()
    {
        MockCommunicationObject mco = new MockCommunicationObject();
        TimeSpan timeout            = TimeSpan.FromMinutes(5);
        CommunicationStateData data = new CommunicationStateData();

        // *** SETUP *** \\
        MockCommunicationObject.InterceptAllStateChanges(mco, data);

        // *** 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 *** \\
        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.StateEnterOnBeginOpen == CommunicationState.Opening,
                    String.Format("CommunicationState entering OnBeginOpen was '{0}' but expected 'Opening'",
                                  data.StateEnterOnBeginOpen));
        Assert.True(data.StateLeaveOnBeginOpen == CommunicationState.Opening,
                    String.Format("CommunicationState leaving OnBeginOpen was '{0}' but expected 'Opening'",
                                  data.StateLeaveOnBeginOpen));

        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.StateEnterOnBeginClose == CommunicationState.Closing,
                    String.Format("CommunicationState entering OnBeginClose was '{0}' but expected 'Closing'",
                                  data.StateEnterOnBeginClose));
        Assert.True(data.StateLeaveOnBeginClose == CommunicationState.Closing,
                    String.Format("CommunicationState leaving OnClose was '{0}' but expected 'Closing'",
                                  data.StateLeaveOnBeginClose));

        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));
    }