1- namespace MyTested . AspNetCore . Mvc . Builders . ExceptionErrors
1+ namespace MyTested . AspNetCore . Mvc . Builders . CaughtExceptions
22{
33 using System ;
44 using Base ;
5- using Contracts . ExceptionErrors ;
5+ using Contracts . CaughtExceptions ;
66 using Exceptions ;
77 using Internal . TestContexts ;
88 using Utilities ;
9- using Utilities . Extensions ;
109
1110 /// <summary>
1211 /// Used for testing expected exceptions.
1312 /// </summary>
14- public class ExceptionTestBuilder : BaseTestBuilderWithInvokedAction , IAndExceptionTestBuilder
13+ public class ExceptionTestBuilder : BaseTestBuilderWithComponent , IAndExceptionTestBuilder
1514 {
1615 /// <summary>
1716 /// Initializes a new instance of the <see cref="ExceptionTestBuilder"/> class.
1817 /// </summary>
19- /// <param name="testContext"><see cref="ControllerTestContext "/> containing data about the currently executed assertion chain.</param>
20- public ExceptionTestBuilder ( ControllerTestContext testContext )
18+ /// <param name="testContext"><see cref="ComponentTestContext "/> containing data about the currently executed assertion chain.</param>
19+ public ExceptionTestBuilder ( ComponentTestContext testContext )
2120 : base ( testContext )
2221 {
2322 }
@@ -26,15 +25,14 @@ public ExceptionTestBuilder(ControllerTestContext testContext)
2625 public IAndExceptionTestBuilder OfType < TException > ( )
2726 {
2827 var expectedExceptionType = typeof ( TException ) ;
29- var actualExceptionType = this . CaughtException . GetType ( ) ;
28+ var actualExceptionType = this . TestContext . CaughtException . GetType ( ) ;
3029 if ( Reflection . AreDifferentTypes ( expectedExceptionType , actualExceptionType ) )
3130 {
3231 throw new InvalidExceptionAssertionException ( string . Format (
33- "When calling {0} action in {1} expected {2}, but instead received {3}." ,
34- this . ActionName ,
35- this . Controller . GetName ( ) ,
32+ "{0} {1}, but instead received {2}." ,
33+ this . TestContext . ExceptionMessagePrefix ,
3634 expectedExceptionType . ToFriendlyTypeName ( ) ,
37- this . CaughtException . GetName ( ) ) ) ;
35+ actualExceptionType . ToFriendlyTypeName ( ) ) ) ;
3836 }
3937
4038 return this ;
@@ -51,13 +49,12 @@ public IExceptionMessageTestBuilder WithMessage()
5149 /// <inheritdoc />
5250 public IAndExceptionTestBuilder WithMessage ( string message )
5351 {
54- var actualExceptionMessage = this . CaughtException . Message ;
52+ var actualExceptionMessage = this . TestContext . CaughtException . Message ;
5553 if ( actualExceptionMessage != message )
5654 {
5755 throw new InvalidExceptionAssertionException ( string . Format (
58- "When calling {0} action in {1} expected exception with message '{2}', but instead received '{3}'." ,
59- this . ActionName ,
60- this . Controller . GetName ( ) ,
56+ "{0} exception with message '{1}', but instead received '{2}'." ,
57+ this . TestContext . ExceptionMessagePrefix ,
6158 message ,
6259 actualExceptionMessage ) ) ;
6360 }
@@ -68,20 +65,19 @@ public IAndExceptionTestBuilder WithMessage(string message)
6865 /// <inheritdoc />
6966 public IAndExceptionTestBuilder WithMessage ( Action < string > assertions )
7067 {
71- assertions ( this . CaughtException . Message ) ;
68+ assertions ( this . TestContext . CaughtException . Message ) ;
7269 return this ;
7370 }
7471
7572 /// <inheritdoc />
7673 public IAndExceptionTestBuilder WithMessage ( Func < string , bool > predicate )
7774 {
78- var actualExceptionMessage = this . CaughtException . Message ;
75+ var actualExceptionMessage = this . TestContext . CaughtException . Message ;
7976 if ( ! predicate ( actualExceptionMessage ) )
8077 {
8178 throw new InvalidExceptionAssertionException ( string . Format (
82- "When calling {0} action in {1} expected exception message ('{2}') to pass the given predicate, but it failed." ,
83- this . ActionName ,
84- this . Controller . GetName ( ) ,
79+ "{0} exception message ('{1}') to pass the given predicate, but it failed." ,
80+ this . TestContext . ExceptionMessagePrefix ,
8581 actualExceptionMessage ) ) ;
8682 }
8783
0 commit comments