Skip to content

Commit b882e6d

Browse files
committed
Write a test to verify RegisterAsyncTask + ThrownExceptions behavior. Fixes #501
1 parent b5d16c9 commit b882e6d

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

ReactiveUI.Tests/ReactiveCommandTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,5 +533,41 @@ public void CombinedCommandsShouldReflectParentCanExecute()
533533
Assert.Equal(3, canExecuteOutput.Count);
534534
Assert.Equal(true, canExecuteOutput[2]);
535535
}
536+
537+
[Fact]
538+
public void TaskExceptionsShouldBeMarshaledToThrownExceptions()
539+
{
540+
(new TestScheduler()).With(sched => {
541+
var fixture = new ReactiveCommand();
542+
543+
int result = 0;
544+
fixture.RegisterAsyncTask(async _ => {
545+
await Observable.Timer(TimeSpan.FromMilliseconds(50), RxApp.TaskpoolScheduler);
546+
throw new Exception("Die");
547+
return 5;
548+
}).Subscribe(x => result = x);
549+
550+
var error = default(Exception);
551+
fixture.ThrownExceptions.Subscribe(ex => error = ex);
552+
553+
fixture.Execute(null);
554+
555+
sched.AdvanceByMs(20);
556+
Assert.Null(error);
557+
Assert.Equal(0, result);
558+
559+
// NB: We have to Thread.Sleep here to compensate for not being
560+
// able to control the concurrency of Task
561+
sched.AdvanceByMs(100);
562+
Thread.Sleep(100);
563+
564+
// NB: Advance it one more so that the scheduled ThrownExceptions
565+
// end up being dispatched
566+
sched.AdvanceByMs(10);
567+
568+
Assert.NotNull(error);
569+
Assert.Equal(0, result);
570+
});
571+
}
536572
}
537573
}

ReactiveUI/Interfaces.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,4 @@ public class ViewContractAttribute : Attribute
451451
}
452452
}
453453

454-
// vim: tw=120 ts=4 sw=4 et :
454+
// vim: tw=120 ts=4 sw=4 et :

ReactiveUI/ReactiveUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<Compile Include="..\CommonAssemblyInfo.cs">
6767
<Link>Properties\CommonAssemblyInfo.cs</Link>
6868
</Compile>
69+
<Compile Include="Activation.cs" />
6970
<Compile Include="ReactiveBinding.cs" />
7071
<Compile Include="AutoPersistHelper.cs" />
7172
<Compile Include="BindingTypeConverters.cs" />

0 commit comments

Comments
 (0)