Skip to content

Commit c8e2b9e

Browse files
committed
Moved Models builders to the Abstractions package (#66)
1 parent b410482 commit c8e2b9e

File tree

54 files changed

+402
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+402
-286
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Base
2+
{
3+
using Internal.TestContexts;
4+
using Utilities.Validators;
5+
6+
public class BaseTestBuilderWithActionContext : BaseTestBuilderWithComponent
7+
{
8+
private ActionTestContext testContext;
9+
10+
public BaseTestBuilderWithActionContext(ActionTestContext testContext)
11+
: base(testContext)
12+
{
13+
this.TestContext = testContext;
14+
}
15+
16+
/// <summary>
17+
/// Gets the currently used <see cref="ActionTestContext"/>.
18+
/// </summary>
19+
/// <value>Result of type <see cref="ActionTestContext"/>.</value>
20+
public new ActionTestContext TestContext
21+
{
22+
get
23+
{
24+
return this.testContext;
25+
}
26+
27+
private set
28+
{
29+
CommonValidator.CheckForNullReference(value, nameof(this.TestContext));
30+
this.testContext = value;
31+
}
32+
}
33+
}
34+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Used for adding AndAlso() method to the model details tests.
55
/// </summary>
6-
/// <typeparam name="TModel">Model from invoked action in ASP.NET Core MVC controller.</typeparam>
6+
/// <typeparam name="TModel">Model from invoked method in ASP.NET Core MVC.</typeparam>
77
public interface IAndModelDetailsTestBuilder<TModel> : IModelDetailsTestBuilder<TModel>
88
{
99
/// <summary>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// Used for adding AndAlso() method to the <see cref="Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary"/> error tests.
55
/// </summary>
6-
/// <typeparam name="TModel">Model from invoked action in ASP.NET Core MVC controller.</typeparam>
6+
/// <typeparam name="TModel">Model from invoked method in ASP.NET Core MVC.</typeparam>
77
public interface IAndModelErrorTestBuilder<TModel> : IModelErrorTestBuilder<TModel>
88
{
99
/// <summary>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Models
2+
{
3+
using And;
4+
using System;
5+
6+
/// <summary>
7+
/// Used for testing the model members.
8+
/// </summary>
9+
/// <typeparam name="TModel">Model from invoked method in ASP.NET Core MVC.</typeparam>
10+
public interface IModelDetailsTestBuilder<TModel> : IModelErrorTestBuilder<TModel>
11+
{
12+
/// <summary>
13+
/// Tests whether the returned model from the invoked method passes the given assertions.
14+
/// </summary>
15+
/// <param name="assertions">Method containing all assertions on the model.</param>
16+
/// <returns>Test builder of <see cref="IAndTestBuilder"/>.</returns>
17+
IAndTestBuilder Passing(Action<TModel> assertions);
18+
19+
/// <summary>
20+
/// Tests whether the returned model from the invoked method passes the given predicate.
21+
/// </summary>
22+
/// <param name="predicate">Predicate testing the model.</param>
23+
/// <returns>Test builder of <see cref="IAndTestBuilder"/>.</returns>
24+
IAndTestBuilder Passing(Func<TModel, bool> predicate);
25+
}
26+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// <summary>
66
/// Used for testing <see cref="Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary"/> errors.
77
/// </summary>
8-
public interface IModelErrorTestBuilder : IBaseTestBuilderWithInvokedAction
8+
public interface IModelErrorTestBuilder : IBaseTestBuilderWithComponent
99
{
1010
}
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/// <summary>
66
/// Used for testing <see cref="Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary"/> errors.
77
/// </summary>
8-
/// <typeparam name="TModel">Model from invoked action in ASP.NET Core MVC controller.</typeparam>
9-
public interface IModelErrorTestBuilder<TModel> : IModelErrorTestBuilder, IBaseTestBuilderWithModel<TModel>
8+
/// <typeparam name="TModel">Model from invoked method in ASP.NET Core MVC.</typeparam>
9+
public interface IModelErrorTestBuilder<TModel> : IModelErrorTestBuilder, IBaseTestBuilderWithComponent
1010
{
1111
}
1212
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Models/ModelDetailsTestBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Models/ModelDetailsTestBuilder.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Models
22
{
33
using System;
4+
using And;
45
using Contracts.And;
56
using Contracts.Models;
67
using Exceptions;
@@ -11,39 +12,39 @@
1112
/// <summary>
1213
/// Used for testing the model members.
1314
/// </summary>
14-
/// <typeparam name="TModel">Model from invoked action in ASP.NET Core MVC controller.</typeparam>
15+
/// <typeparam name="TModel">Model from invoked method in ASP.NET Core MVC.</typeparam>
1516
public class ModelDetailsTestBuilder<TModel>
1617
: ModelErrorTestBuilder<TModel>, IAndModelDetailsTestBuilder<TModel>
1718
{
1819
/// <summary>
1920
/// Initializes a new instance of the <see cref="ModelDetailsTestBuilder{TResponseModel}"/> class.
2021
/// </summary>
21-
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
22-
public ModelDetailsTestBuilder(ControllerTestContext testContext)
22+
/// <param name="testContext"><see cref="ActionTestContext"/> containing data about the currently executed assertion chain.</param>
23+
public ModelDetailsTestBuilder(ActionTestContext testContext)
2324
: base(testContext)
2425
{
2526
}
2627

2728
/// <inheritdoc />
28-
public IAndTestBuilderWithInvokedAction Passing(Action<TModel> assertions)
29+
public IAndTestBuilder Passing(Action<TModel> assertions)
2930
{
3031
assertions(this.Model);
31-
return this.NewAndTestBuilderWithInvokedAction();
32+
return new AndTestBuilder(this.TestContext);
3233
}
3334

3435
/// <inheritdoc />
35-
public IAndTestBuilderWithInvokedAction Passing(Func<TModel, bool> predicate)
36+
public IAndTestBuilder Passing(Func<TModel, bool> predicate)
3637
{
3738
if (!predicate(this.Model))
3839
{
3940
throw new ResponseModelAssertionException(string.Format(
4041
"When calling {0} action in {1} expected response model {2} to pass the given predicate, but it failed.",
41-
this.ActionName,
42-
this.Controller.GetName(),
42+
this.TestContext.MethodName,
43+
this.TestContext.Component.GetName(),
4344
typeof(TModel).ToFriendlyTypeName()));
4445
}
4546

46-
return this.NewAndTestBuilderWithInvokedAction();
47+
return new AndTestBuilder(this.TestContext);
4748
}
4849

4950
/// <inheritdoc />

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Models/ModelErrorTestBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Models/ModelErrorTestBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
/// <summary>
99
/// Used for testing the <see cref="ModelStateDictionary"/> errors.
1010
/// </summary>
11-
public class ModelErrorTestBuilder : BaseTestBuilderWithInvokedAction, IModelErrorTestBuilder
11+
public class ModelErrorTestBuilder : BaseTestBuilderWithActionContext, IModelErrorTestBuilder
1212
{
1313
/// <summary>
1414
/// Initializes a new instance of the <see cref="ModelErrorTestBuilder"/> class.
1515
/// </summary>
16-
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
16+
/// <param name="testContext"><see cref="ActionTestContext"/> containing data about the currently executed assertion chain.</param>
1717
/// <param name="modelState">Optional <see cref="ModelStateDictionary"/> to use the test builder with. Default is controller's <see cref="ModelStateDictionary"/>.</param>
1818
public ModelErrorTestBuilder(
19-
ControllerTestContext testContext,
19+
ActionTestContext testContext,
2020
ModelStateDictionary modelState = null)
2121
: base(testContext)
2222
{

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Models/ModelErrorTestBuilder{TModel}.cs renamed to src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Models/ModelErrorTestBuilder{TModel}.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
/// <summary>
1111
/// Used for testing the <see cref="ModelStateDictionary"/> errors.
1212
/// </summary>
13-
/// <typeparam name="TModel">Model from invoked action in ASP.NET Core MVC controller.</typeparam>
13+
/// <typeparam name="TModel">Model from invoked method in ASP.NET Core MVC.</typeparam>
1414
public class ModelErrorTestBuilder<TModel> : ModelErrorTestBuilder, IAndModelErrorTestBuilder<TModel>
1515
{
1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="ModelErrorTestBuilder{TModel}"/> class.
1818
/// </summary>
19-
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
19+
/// <param name="testContext"><see cref="ActionTestContext"/> containing data about the currently executed assertion chain.</param>
2020
/// <param name="modelState">Optional <see cref="ModelStateDictionary"/> to use the class with. Default is Default is <see cref="ControllerBase"/>'s <see cref="ModelStateDictionary"/>.</param>
2121
public ModelErrorTestBuilder(
22-
ControllerTestContext testContext,
22+
ActionTestContext testContext,
2323
ModelStateDictionary modelState = null)
2424
: base(testContext, modelState)
2525
{
2626
}
2727

2828
/// <summary>
29-
/// Gets model from invoked action in ASP.NET Core MVC controller.
29+
/// Gets model from invoked method in ASP.NET Core MVC.
3030
/// </summary>
31-
/// <value>Model from invoked action.</value>
31+
/// <value>Model from invoked method.</value>
3232
protected TModel Model => this.TestContext.ModelAs<TModel>();
3333

3434
/// <inheritdoc />
@@ -38,8 +38,8 @@ public void ThrowNewModelErrorAssertionException(string messageFormat, string er
3838
{
3939
throw new ModelErrorAssertionException(string.Format(
4040
messageFormat,
41-
this.ActionName,
42-
this.Controller.GetName(),
41+
this.TestContext.MethodName,
42+
this.TestContext.Component.GetName(),
4343
errorKey));
4444
}
4545
}

src/MyTested.AspNetCore.Mvc.Controllers/Exceptions/ActionResultAssertionException.cs renamed to src/MyTested.AspNetCore.Mvc.Abstractions/Exceptions/InvocationResultAssertionException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
/// <summary>
66
/// <see cref="Exception"/> for invalid action return type.
77
/// </summary>
8-
public class ActionResultAssertionException : Exception
8+
public class InvocationResultAssertionException : Exception
99
{
1010
/// <summary>
11-
/// Initializes a new instance of the <see cref="ActionResultAssertionException"/> class.
11+
/// Initializes a new instance of the <see cref="InvocationResultAssertionException"/> class.
1212
/// </summary>
1313
/// <param name="message">The message that describes the error.</param>
14-
public ActionResultAssertionException(string message)
14+
public InvocationResultAssertionException(string message)
1515
: base(message)
1616
{
1717
}

0 commit comments

Comments
 (0)