Permalink
Browse files

TaskSample - refactor tests (extract ShouldBeFaulted)

  • Loading branch information...
bobbymcr committed May 23, 2018
1 parent 26e3e41 commit 71d532cdb2f29b932eba8dd47d35f80344e26aae
Showing with 11 additions and 10 deletions.
  1. +11 −10 projects/TaskSample/TaskSample.Test/FirstAsyncTest.cs
@@ -57,11 +57,7 @@ public void OneItemThrowsSyncThrowsInvalidOperation()
Task<string> task = funcs.FirstAsync(r => true);
task.IsCompleted.Should().BeTrue();
task.Exception.Should().NotBeNull();
task.Exception.InnerException.Should()
.BeOfType<InvalidOperationException>().Which
.Message.Should().Be("No matching result.");
ShouldBeFaulted(task);
}
[Fact]
@@ -127,11 +123,7 @@ public void TwoItemsSyncNoMatchesThrowsInvalidOperation()
Task<string> task = funcs.FirstAsync(r => r.StartsWith("good", StringComparison.Ordinal));
task.IsCompleted.Should().BeTrue();
task.Exception.Should().NotBeNull();
task.Exception.InnerException.Should()
.BeOfType<InvalidOperationException>().Which
.Message.Should().Be("No matching result.");
ShouldBeFaulted(task);
}
[Fact]
@@ -153,5 +145,14 @@ public void TwoItemsFirstHangsUntilCancelSecondMatchesSyncReturns()
task.IsCompletedSuccessfully.Should().BeTrue();
task.Result.Should().Be("good 2");
}
private static void ShouldBeFaulted(Task task)
{
task.IsCompleted.Should().BeTrue();
task.Exception.Should().NotBeNull();
task.Exception.InnerException.Should()
.BeOfType<InvalidOperationException>().Which
.Message.Should().Be("No matching result.");
}
}
}

0 comments on commit 71d532c

Please sign in to comment.