public async Task OpenAndCloseOnOpen() { var o = new TestCommunicationObject { IsInterceptingTest = true }; o.DoOn("OnOpenAsync", async co => await co.CloseAsync()); await o.OpenAsync(); o.State .Should().Be(CommunicationState.Closed); o.Record .Should().Equal(new string[] { "OnOpeningAsync", "Event_Opening", "OnOpenAsync", "OnClosingAsync", "Event_Closing", "OnAbortAsync", "OnClosedAsync", "Event_Closed", "OnOpenedAsync" }); }
public async Task OpenAndOpenOnOpening() { var o = new TestCommunicationObject(); o.DoOn("OnOpeningAsync", async co => await co.OpenAsync()); // Calling open is only allowed on a fresh object await o.Invoking(x => x.OpenAsync()) .Should().ThrowAsync <InvalidOperationException>(); }
public async Task CloseAndAbortOnClosing() { var o = new TestCommunicationObject(); o.DoOn("OnClosingAsync", async co => await co.AbortAsync()); await o.CloseAsync(); o.State .Should().Be(CommunicationState.Closed); o.Record .Should().Equal(new string[] { "OnClosingAsync", "Event_Closing", "OnAbortAsync", "OnClosedAsync", "Event_Closed" }); }
public async Task OpenAndThrowOnOpening() { var o = new TestCommunicationObject(); o.DoOn("OnOpeningAsync", co => Task.FromException(new TestException())); await o.Invoking(x => x.OpenAsync()) .Should().ThrowAsync <TestException>(); o.State .Should().Be(CommunicationState.Faulted); o.Record .Should().Equal(new string[] { "OnOpeningAsync", "Event_Opening", "OnFaulted", "Event_Faulted", }); }