Skip to content

Commit f0ea8d3

Browse files
committed
All void ActionResultTestBuilders now return IAndTestBuilder (#13)
1 parent d7ab87d commit f0ea8d3

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

MyWebApi/Builders/Actions/ShouldHaveModelState.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public IModelErrorTestBuilder<TRequestModel> ShouldHaveModelStateFor<TRequestMod
3030
public IAndTestBuilder<TActionResult> ShouldHaveValidModelState()
3131
{
3232
this.CheckValidModelState();
33-
return new AndTestBuilder<TActionResult>(this.Controller, this.ActionName, this.ActionResult);
33+
return this.NewAndTestBuilder();
3434
}
3535

3636
/// <summary>
3737
/// Checks whether the tested action's provided model state is not valid.
3838
/// </summary>
39-
public void ShouldHaveInvalidModelState()
39+
public IAndTestBuilder<TActionResult> ShouldHaveInvalidModelState()
4040
{
4141
if (this.Controller.ModelState.Count == 0)
4242
{
@@ -45,6 +45,8 @@ public void ShouldHaveInvalidModelState()
4545
this.ActionName,
4646
this.Controller.GetName()));
4747
}
48+
49+
return this.NewAndTestBuilder();
4850
}
4951
}
5052
}

MyWebApi/Builders/Actions/ShouldReturnNotFound.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace MyWebApi.Builders.Actions
22
{
33
using System.Web.Http.Results;
4+
using And;
5+
using Contracts.And;
46

57
/// <summary>
68
/// Class containing methods for testing NotFoundResult.
@@ -11,9 +13,10 @@ public partial class ActionResultTestBuilder<TActionResult>
1113
/// <summary>
1214
/// Tests whether action result is NotFoundResult.
1315
/// </summary>
14-
public void ShouldReturnNotFound()
16+
public IAndTestBuilder<TActionResult> ShouldReturnNotFound()
1517
{
1618
this.ShouldReturn<NotFoundResult>();
19+
return this.NewAndTestBuilder();
1720
}
1821
}
1922
}

MyWebApi/Builders/Actions/ShouldReturnStatusCode.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Net;
44
using System.Web.Http.Results;
55
using Common.Extensions;
6+
using Contracts.And;
67
using Exceptions;
78

89
/// <summary>
@@ -14,16 +15,17 @@ public partial class ActionResultTestBuilder<TActionResult>
1415
/// <summary>
1516
/// Tests whether action result is StatusCodeResult.
1617
/// </summary>
17-
public void ShouldReturnStatusCode()
18+
public IAndTestBuilder<TActionResult> ShouldReturnStatusCode()
1819
{
1920
this.ShouldReturn<StatusCodeResult>();
21+
return this.NewAndTestBuilder();
2022
}
2123

2224
/// <summary>
2325
/// Tests whether action result is StatusCodeResult and is the same as provided HttpStatusCode.
2426
/// </summary>
2527
/// <param name="statusCode">HttpStatusCode enumeration.</param>
26-
public void ShouldReturnStatusCode(HttpStatusCode statusCode)
28+
public IAndTestBuilder<TActionResult> ShouldReturnStatusCode(HttpStatusCode statusCode)
2729
{
2830
var statusCodeResult = this.GetReturnObject<StatusCodeResult>();
2931
if (statusCodeResult.StatusCode != statusCode)
@@ -37,6 +39,8 @@ public void ShouldReturnStatusCode(HttpStatusCode statusCode)
3739
(int)statusCodeResult.StatusCode,
3840
statusCodeResult.StatusCode));
3941
}
42+
43+
return this.NewAndTestBuilder();
4044
}
4145
}
4246
}

MyWebApi/Builders/Base/BaseTestBuilderWithActionResult.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
namespace MyWebApi.Builders.Base
22
{
33
using System.Web.Http;
4-
4+
using And;
55
using Common.Extensions;
6+
using Contracts.And;
67
using Contracts.Base;
78
using Exceptions;
89
using Microsoft.CSharp.RuntimeBinder;
@@ -67,5 +68,10 @@ protected TResponseModel GetActualModel<TResponseModel>()
6768
typeof(TResponseModel).ToFriendlyTypeName()));
6869
}
6970
}
71+
72+
protected IAndTestBuilder<TActionResult> NewAndTestBuilder()
73+
{
74+
return new AndTestBuilder<TActionResult>(this.Controller, this.ActionName, this.ActionResult);
75+
}
7076
}
7177
}

MyWebApi/Builders/Contracts/Actions/IActionResultTestBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface IActionResultTestBuilder<out TActionResult> : IBaseTestBuilderW
3030
/// <summary>
3131
/// Checks whether the tested action's provided model state is not valid.
3232
/// </summary>
33-
void ShouldHaveInvalidModelState();
33+
IAndTestBuilder<TActionResult> ShouldHaveInvalidModelState();
3434

3535
/// <summary>
3636
/// Tests whether action result is OkResult or OkNegotiatedContentResult{T}.
@@ -41,18 +41,18 @@ public interface IActionResultTestBuilder<out TActionResult> : IBaseTestBuilderW
4141
/// <summary>
4242
/// Tests whether action result is StatusCodeResult.
4343
/// </summary>
44-
void ShouldReturnStatusCode();
44+
IAndTestBuilder<TActionResult> ShouldReturnStatusCode();
4545

4646
/// <summary>
4747
/// Tests whether action result is StatusCodeResult and is the same as provided HttpStatusCode.
4848
/// </summary>
4949
/// <param name="statusCode">HttpStatusCode enumeration.</param>
50-
void ShouldReturnStatusCode(HttpStatusCode statusCode);
50+
IAndTestBuilder<TActionResult> ShouldReturnStatusCode(HttpStatusCode statusCode);
5151

5252
/// <summary>
5353
/// Tests whether action result is NotFoundResult.
5454
/// </summary>
55-
void ShouldReturnNotFound();
55+
IAndTestBuilder<TActionResult> ShouldReturnNotFound();
5656

5757
/// <summary>
5858
/// Tests whether action result is BadRequestResult, InvalidModelStateResult or BadRequestErrorMessageResult.

0 commit comments

Comments
 (0)