Skip to content

Commit bbaf748

Browse files
committed
Added IActionResultOfTTestBuilder interfaces (#359)
1 parent f7f01e2 commit bbaf748

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.ActionResults.ActionResult
2+
{
3+
public class ActionResultOfTTestBuilder
4+
{
5+
}
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.ActionResults.ActionResult
2+
{
3+
using Contracts.Base;
4+
5+
/// <summary>
6+
/// Used for testing <see cref="Microsoft.AspNetCore.Mvc.ActionResult{TResult}"/>.
7+
/// </summary>
8+
/// <typeparam name="TResult">Type of the expected result.</typeparam>
9+
public interface IActionResultOfTTestBuilder<TResult>
10+
: IBaseTestBuilderWithActionResult<TResult>
11+
{
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.ActionResults.ActionResult
2+
{
3+
/// <summary>
4+
/// Used for adding AndAlso() method to
5+
/// the <see cref="Microsoft.AspNetCore.Mvc.ActionResult{TResult}"/> tests.
6+
/// </summary>
7+
/// <typeparam name="TResult">Type of the expected result.</typeparam>
8+
public interface IAndActionResultOfTTestBuilder<TResult>
9+
{
10+
/// <summary>
11+
/// AndAlso method for better readability when
12+
/// chaining <see cref="Microsoft.AspNetCore.Mvc.ActionResult{TResult}"/> tests.
13+
/// </summary>
14+
/// <returns>The same <see cref="IActionResultOfTTestBuilder{TResult}"/>.</returns>
15+
IActionResultOfTTestBuilder<TResult> AndAlso();
16+
}
17+
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Contracts/Actions/IShouldReturnActionResultTestBuilder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Actions
22
{
33
using System;
4+
using ActionResults.ActionResult;
45
using And;
56

67
/// <summary>
@@ -44,7 +45,13 @@ public interface IShouldReturnActionResultTestBuilder<TActionResult>
4445
/// <returns>Test builder of <see cref="IAndTestBuilder"/> type.</returns>
4546
IAndTestBuilder ActionResult<TResult>(Action<IShouldReturnTestBuilder<TActionResult>> actionResultTestBuilder);
4647

47-
//// ActionResult<TResult>, consider OkResult for example to be valid too?!, with additional options to validate the TResult, like EqualTo or Passing (model/result details)
48-
//IAndTestBuilder ActionResult<TResult>(Action<IShouldHaveTestBuilder<TActionResult>> actionResultTestBuilder);
48+
/// <summary>
49+
/// Tests whether the action result is
50+
/// <see cref="Microsoft.AspNetCore.Mvc.ActionResult{TResult}"/>.
51+
/// </summary>
52+
/// <typeparam name="TResult">Type of the expected result.</typeparam>
53+
/// <param name="actionResultTestBuilder">Test builder which asserts the actual result.</param>
54+
/// <returns>Test builder of <see cref="IAndTestBuilder"/> type.</returns>
55+
IAndTestBuilder ActionResult<TResult>(Action<IActionResultOfTTestBuilder<TResult>> actionResultTestBuilder);
4956
}
5057
}

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionsTests/ShouldReturnTests/ShouldReturnActionResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ public void ShouldReturnActionResultOfTShouldWorkCorrectlyWithShouldPassForTheMe
293293
.ShouldReturn()
294294
.ActionResult<ResponseModel>()
295295
.AndAlso()
296-
.ShouldPassForThe<ObjectResult>(model => model.Value.GetType() == typeof(ResponseModel));
296+
.ShouldPassForThe<ObjectResult>(model => model
297+
.Value.GetType() == typeof(ResponseModel));
297298
}
298299

299300
[Fact]

test/MyTested.AspNetCore.Mvc.Controllers.Views.Test/BuildersTests/ActionResultsTests/ViewTests/ViewComponentTestBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using Exceptions;
66
using Microsoft.AspNetCore.Mvc;
77
using Microsoft.Net.Http.Headers;
8-
using MyTested.AspNetCore.Mvc.Test.Setups.Models;
98
using Setups;
9+
using Setups.Models;
1010
using Setups.Controllers;
1111
using Xunit;
1212

0 commit comments

Comments
 (0)