Change ThrowIfFaulted to WaitAndThrowIfFaulted

This commit is contained in:
Pranav K 2014-08-21 11:55:41 -07:00
parent 9c4df4606f
commit eccd25bedd
3 changed files with 11 additions and 11 deletions

View File

@ -11,13 +11,13 @@ namespace Microsoft.AspNet.Mvc.Internal
public static class TaskHelper public static class TaskHelper
{ {
/// <summary> /// <summary>
/// Throws the first faulting exception for a task which is faulted. It preserves the original stack trace when /// Waits for the task to complete and throws the first faulting exception if the task is faulted.
/// throwing the exception. /// It preserves the original stack trace when throwing the exception.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Invoking this method is equivalent to calling Wait() on the <paramref name="task" /> if it is not completed. /// Invoking this method is equivalent to calling Wait() on the <paramref name="task" /> if it is not completed.
/// </remarks> /// </remarks>
public static void ThrowIfFaulted(Task task) public static void WaitAndThrowIfFaulted(Task task)
{ {
task.GetAwaiter().GetResult(); task.GetAwaiter().GetResult();
} }

View File

@ -101,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
var viewContext = new ViewContext(_viewContext, viewEngineResult.View, _viewData, writer); var viewContext = new ViewContext(_viewContext, viewEngineResult.View, _viewData, writer);
var renderTask = viewEngineResult.View.RenderAsync(viewContext); var renderTask = viewEngineResult.View.RenderAsync(viewContext);
TaskHelper.ThrowIfFaulted(renderTask); TaskHelper.WaitAndThrowIfFaulted(renderTask);
return writer.ToString(); return writer.ToString();
} }
} }

View File

@ -10,29 +10,29 @@ namespace Microsoft.AspNet.Mvc.Internal
public class TaskHelperTest public class TaskHelperTest
{ {
[Fact] [Fact]
public void ThrowIfFaulted_DoesNotThrowIfTaskIsNotFaulted() public void WaitAndThrowIfFaulted_DoesNotThrowIfTaskIsNotFaulted()
{ {
// Arrange // Arrange
var task = Task.FromResult(0); var task = Task.FromResult(0);
// Act and Assert // Act and Assert
Assert.DoesNotThrow(() => TaskHelper.ThrowIfFaulted(task)); Assert.DoesNotThrow(() => TaskHelper.WaitAndThrowIfFaulted(task));
} }
[Fact] [Fact]
public void ThrowIfFaulted_ThrowsIfTaskIsFaulted() public void WaitAndThrowIfFaulted_ThrowsIfTaskIsFaulted()
{ {
// Arrange // Arrange
var message = "Exception message"; var message = "Exception message";
var task = CreatingFailingTask(message); var task = CreatingFailingTask(message);
// Act and Assert // Act and Assert
var ex = Assert.Throws<Exception>(() => TaskHelper.ThrowIfFaulted(task)); var ex = Assert.Throws<Exception>(() => TaskHelper.WaitAndThrowIfFaulted(task));
Assert.Equal(message, ex.Message); Assert.Equal(message, ex.Message);
} }
[Fact] [Fact]
public void ThrowIfFaulted_ThrowsFirstExceptionWhenAggregateTaskFails() public void WaitAndThrowIfFaulted_ThrowsFirstExceptionWhenAggregateTaskFails()
{ {
// Arrange // Arrange
var message = "Exception message"; var message = "Exception message";
@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Internal
}); });
// Act and Assert // Act and Assert
var ex = Assert.Throws<Exception>(() => TaskHelper.ThrowIfFaulted(task)); var ex = Assert.Throws<Exception>(() => TaskHelper.WaitAndThrowIfFaulted(task));
Assert.Equal(message, ex.Message); Assert.Equal(message, ex.Message);
} }