public async SystemTasks.Task TestUnhandledExceptionEventHandler() { await this.RunAsync(async r => { var tcsFail = TaskCompletionSource.Create <bool>(); int count = 0; bool sawFilterException = false; r.OnFailure += (exception) => { // The "N" machine throws a InvalidOperationException which we should receive // here wrapped in ActionExceptionFilterException for the OnFailure callback. if (exception is ActionExceptionFilterException) { sawFilterException = true; return; } count++; tcsFail.SetException(exception); }; var tcs = TaskCompletionSource.Create <bool>(); r.CreateActor(typeof(N), new SetupEvent(tcs)); await this.WaitAsync(tcs.Task); AssertionFailureException ex = await Assert.ThrowsAsync <AssertionFailureException>(async() => await tcsFail.Task); Assert.IsType <InvalidOperationException>(ex.InnerException); Assert.Equal(1, count); Assert.True(sawFilterException); }, handleFailures : false); }
public async Task TestAssertFailureEventHandler() { await this.RunAsync(async r => { var tcsFail = TaskCompletionSource.Create <bool>(); int count = 0; r.OnFailure += (exception) => { if (!(exception is ActionExceptionFilterException)) { count++; tcsFail.SetException(exception); } }; var tcs = TaskCompletionSource.Create <bool>(); r.CreateActor(typeof(M), new SetupEvent(tcs)); await WaitAsync(tcs.Task); AssertionFailureException ex = await Assert.ThrowsAsync <AssertionFailureException>(async() => await tcsFail.Task); Assert.Equal(1, count); }); }
public async Task TestUnhandledExceptionEventHandler() { await this.RunAsync(async r => { var tcsFail = new TaskCompletionSource <bool>(); int count = 0; bool sawFilterException = false; r.OnFailure += (exception) => { // This test throws an exception that we should receive a filter call for if (exception is MachineActionExceptionFilterException) { sawFilterException = true; return; } count++; tcsFail.SetException(exception); }; var tcs = new TaskCompletionSource <bool>(); r.CreateMachine(typeof(N), new Configure(tcs)); await WaitAsync(tcs.Task); AssertionFailureException ex = await Assert.ThrowsAsync <AssertionFailureException>(async() => await tcsFail.Task); Assert.IsType <InvalidOperationException>(ex.InnerException); Assert.Equal(1, count); Assert.True(sawFilterException); }); }
public void CreateInstance_fails_with_useful_message_if_type_cannot_be_found() { const string className = "Number"; AssertionFailureException assertionFailureException = Assert.Throws <AssertionFailureException>(() => Reflector.CreateInstance(MSCorLibAssembly, className)); Assert.AreEqual("Could not find type Number in the specified assembly.", assertionFailureException.Failure.Message); }