Skip to content

Commit 16d4366

Browse files
committed
Allow instance creation to be with inner builder #318
1 parent 60218c2 commit 16d4366

File tree

5 files changed

+86
-38
lines changed

5 files changed

+86
-38
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Controllers
2+
{
3+
/// <summary>
4+
/// Used for adding AndAlso() method to the controller builder.
5+
/// </summary>
6+
/// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam>
7+
public interface IAndControllerInstanceBuilder<TController> : IControllerBuilder<TController>
8+
where TController : class
9+
{
10+
/// <summary>
11+
/// AndAlso method for better readability when building controller instance.
12+
/// </summary>
13+
/// <returns>The same <see cref="IAndControllerBuilder{TController}"/>.</returns>
14+
IAndControllerBuilder<TController> AndAlso();
15+
}
16+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Controllers
2+
{
3+
using System;
4+
using Builders.Contracts.Base;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
/// <summary>
8+
/// Used for building the controller which will be tested.
9+
/// </summary>
10+
/// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam>
11+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
12+
public interface IBaseControllerBuilder<TController, TBuilder> : IBaseTestBuilderWithComponentBuilder<IAndControllerBuilder<TController>>
13+
where TController : class
14+
{
15+
/// <summary>
16+
/// Sets the <see cref="ControllerContext"/> on the tested controller.
17+
/// </summary>
18+
/// <param name="controllerContext">Instance of <see cref="ControllerContext"/> to set.</param>
19+
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
20+
IAndControllerBuilder<TController> WithControllerContext(ControllerContext controllerContext);
21+
22+
/// <summary>
23+
/// Sets the <see cref="ControllerContext"/> on the tested controller.
24+
/// </summary>
25+
/// <param name="controllerContextSetup">Action setting the <see cref="ControllerContext"/>.</param>
26+
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
27+
IAndControllerBuilder<TController> WithControllerContext(Action<ControllerContext> controllerContextSetup);
28+
29+
/// <summary>
30+
/// Sets the <see cref="ActionContext"/> on the tested controller.
31+
/// </summary>
32+
/// <param name="actionContext">Instance of <see cref="ActionContext"/> to set.</param>
33+
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
34+
IAndControllerBuilder<TController> WithActionContext(ActionContext actionContext);
35+
36+
/// <summary>
37+
/// Sets the <see cref="ActionContext"/> on the tested controller.
38+
/// </summary>
39+
/// <param name="actionContextSetup">Action setting the <see cref="ActionContext"/>.</param>
40+
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
41+
IAndControllerBuilder<TController> WithActionContext(Action<ActionContext> actionContextSetup);
42+
43+
/// <summary>
44+
/// Sets custom properties to the controller using a delegate.
45+
/// </summary>
46+
/// <param name="controllerSetup">Action to use for controller setup.</param>
47+
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
48+
IAndControllerBuilder<TController> WithSetup(Action<TController> controllerSetup);
49+
}
50+
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Contracts/Controllers/IControllerBuilder.cs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
using System.Linq.Expressions;
55
using System.Threading.Tasks;
66
using Actions;
7-
using Base;
8-
using Microsoft.AspNetCore.Mvc;
97

108
/// <summary>
119
/// Used for building the controller which will be tested.
1210
/// </summary>
1311
/// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam>
14-
public interface IControllerBuilder<TController> : IBaseTestBuilderWithComponentBuilder<IAndControllerBuilder<TController>>
12+
public interface IControllerBuilder<TController> : IBaseControllerBuilder<TController, IAndControllerBuilder<TController>>
1513
where TController : class
1614
{
1715
/// <summary>
@@ -20,41 +18,6 @@ public interface IControllerBuilder<TController> : IBaseTestBuilderWithComponent
2018
/// <returns>Test builder of <see cref="IControllerTestBuilder"/> type.</returns>
2119
IControllerTestBuilder ShouldHave();
2220

23-
/// <summary>
24-
/// Sets the <see cref="ControllerContext"/> on the tested controller.
25-
/// </summary>
26-
/// <param name="controllerContext">Instance of <see cref="ControllerContext"/> to set.</param>
27-
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
28-
IAndControllerBuilder<TController> WithControllerContext(ControllerContext controllerContext);
29-
30-
/// <summary>
31-
/// Sets the <see cref="ControllerContext"/> on the tested controller.
32-
/// </summary>
33-
/// <param name="controllerContextSetup">Action setting the <see cref="ControllerContext"/>.</param>
34-
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
35-
IAndControllerBuilder<TController> WithControllerContext(Action<ControllerContext> controllerContextSetup);
36-
37-
/// <summary>
38-
/// Sets the <see cref="ActionContext"/> on the tested controller.
39-
/// </summary>
40-
/// <param name="actionContext">Instance of <see cref="ActionContext"/> to set.</param>
41-
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
42-
IAndControllerBuilder<TController> WithActionContext(ActionContext actionContext);
43-
44-
/// <summary>
45-
/// Sets the <see cref="ActionContext"/> on the tested controller.
46-
/// </summary>
47-
/// <param name="actionContextSetup">Action setting the <see cref="ActionContext"/>.</param>
48-
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
49-
IAndControllerBuilder<TController> WithActionContext(Action<ActionContext> actionContextSetup);
50-
51-
/// <summary>
52-
/// Sets custom properties to the controller using a delegate.
53-
/// </summary>
54-
/// <param name="controllerSetup">Action to use for controller setup.</param>
55-
/// <returns>The same <see cref="IControllerBuilder{TController}"/>.</returns>
56-
IAndControllerBuilder<TController> WithSetup(Action<TController> controllerSetup);
57-
5821
/// <summary>
5922
/// Indicates which action should be invoked and tested.
6023
/// </summary>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Controllers
2+
{
3+
/// <summary>
4+
/// Used for building the controller which will be tested.
5+
/// </summary>
6+
/// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam>
7+
public interface IControllerInstanceBuilder<TController> : IBaseControllerBuilder<TController, IAndControllerInstanceBuilder<TController>>
8+
where TController : class
9+
{
10+
}
11+
}

src/MyTested.AspNetCore.Mvc.Controllers/MyController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,13 @@ public static IControllerBuilder<TController> Instance(Func<TController> constru
112112
public new static IControllerTestBuilder ShouldHave()
113113
=> Instance()
114114
.ShouldHave();
115+
116+
/// <summary>
117+
/// Starts a controller test.
118+
/// </summary>
119+
/// <param name="controllerInstanceBuilder">Instance of the ASP.NET Core MVC controller to test.</param>
120+
/// <returns>Test builder of <see cref="IControllerInstanceBuilder{TController}"/> type.</returns>
121+
public static IControllerInstanceBuilder<TController> Isntance(Action<IControllerInstanceBuilder<TController>> controllerInstanceBuilder)
122+
=> null;
115123
}
116124
}

0 commit comments

Comments
 (0)