Exemple #1
0
    public static void CommunicationObject_Abort_Close_Methods_Called()
    {
        MockCommunicationObject mco = new MockCommunicationObject();
        List <string>           closeMethodsCalled = new List <string>();
        TimeSpan timeout = TimeSpan.FromSeconds(30);

        // *** SETUP *** \\
        InterceptAllCloseMethods(mco, closeMethodsCalled);

        // *** EXECUTE *** \\
        mco.Open(timeout);
        mco.Abort();

        // *** VALIDATE *** \\
        string expectedCloses = "OnClosing,OnAbort,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));

        Assert.True(mco.State == CommunicationState.Closed,
                    String.Format("Expected final state to be 'Closed' but actual was '{0}", mco.State));
    }
    public static void CommunicationObject_Abort_Close_Methods_Called()
    {
        MockCommunicationObject mco = new MockCommunicationObject();
        List<string> closeMethodsCalled = new List<string>();
        TimeSpan timeout = TimeSpan.FromSeconds(30);

        // *** SETUP *** \\
        MockCommunicationObject.InterceptAllCloseMethods(mco, closeMethodsCalled);

        // *** EXECUTE *** \\
        mco.Open(timeout);
        mco.Abort();

        // *** VALIDATE *** \\
        string expectedCloses = "OnClosing,OnAbort,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));

        Assert.True(mco.State == CommunicationState.Closed,
                String.Format("Expected final state to be 'Closed' but actual was '{0}", mco.State));

    }