public void Support_Cancelation() { var events = Substitute.For<IEventAggregator>(); var sut = new BusyViewModel(events); const string taskName = nameof(Support_Cancelation); var msg = new StartTaskMessage((c, p) => Enumerable.Range(1, 10).ToList().ForEach(i => { Thread.Sleep(10); p.Report(i * 10); c.ThrowIfCancellationRequested(); }), taskName); var task = sut.Handle(msg); sut.IsBusy.Should().BeTrue(); sut.WaitingFor.Should().Be($"Waiting for '{taskName}'..."); sut.Cancel(); sut.WaitingFor.Should().Be($"Cancelling '{taskName}'..."); sut.IsIndeterminate.Should().BeTrue(); sut.IsBusy.Should().BeTrue(); // ReSharper disable once MethodSupportsCancellation task.Wait(); sut.IsBusy.Should().BeFalse(); events.Received().PublishOnUIThread(TaskState.Canceled); }