Skip to content

Commit dc7c3c7

Browse files
committed
Added tests for the ResultDetailsTestBuilder (#359)
1 parent cedad81 commit dc7c3c7

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

src/MyTested.AspNetCore.Mvc.Abstractions/Utilities/Validators/InvocationResultValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ public static void ValidateInvocationResultType<TExpectedType>(
8181
bool allowDifferentGenericTypeDefinitions = false)
8282
=> ValidateInvocationResultType(testContext, typeof(TExpectedType), canBeAssignable, allowDifferentGenericTypeDefinitions);
8383

84-
public static void ValidateInvocationResult<TResult>(ComponentTestContext testContext, TResult model)
84+
public static void ValidateInvocationResult<TResult>(ComponentTestContext testContext, TResult model, bool canBeAssignable = false)
8585
{
8686
if (!Reflection.IsAnonymousType(typeof(TResult)))
8787
{
88-
ValidateInvocationResultType<TResult>(testContext);
88+
ValidateInvocationResultType<TResult>(testContext, canBeAssignable);
8989
}
9090

9191
if (Reflection.AreNotDeeplyEqual(model, testContext.MethodResult, out var result))

src/MyTested.AspNetCore.Mvc.Models/BaseShouldReturnTestBuilderExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
using System;
44
using Builders.Contracts.And;
55
using Builders.Contracts.Invocations;
6-
using Builders.Contracts.Models;
76
using Builders.And;
87
using Builders.Base;
98
using Builders.Contracts.Results;
10-
using Builders.Models;
119
using Builders.Results;
1210
using Exceptions;
1311
using Internal.TestContexts;

src/MyTested.AspNetCore.Mvc.Models/Builders/Results/ResultDetailsTestBuilder{TResult}.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public IAndModelDetailsTestBuilder<TResult> EqualTo(TResult result)
2828
{
2929
InvocationResultValidator.ValidateInvocationResult(
3030
this.TestContext,
31-
result);
31+
result,
32+
canBeAssignable: true);
3233

3334
return this;
3435
}

test/MyTested.AspNetCore.Mvc.Models.Test/BuildersTests/ActionsTests/ShouldReturnTests/ShouldReturnTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,19 @@ public void ShouldReturnShouldWorkWithModelDetailsTestsWithGenericDefinition()
343343
.Passing(c => c.Count == 2));
344344
}
345345

346+
[Fact]
347+
public void ShouldReturnResultOfTypeShouldChainCorrectly()
348+
{
349+
MyController<MvcController>
350+
.Instance()
351+
.Calling(c => c.GenericActionWithCollection())
352+
.ShouldReturn()
353+
.ResultOfType<ICollection<ResponseModel>>(result => result
354+
.EqualTo(TestObjectFactory.GetListOfResponseModels())
355+
.AndAlso()
356+
.Passing(model => model.Count == 2));
357+
}
358+
346359
[Fact]
347360
public void ShouldReturnShouldThrowExceptionIfActionThrowsExceptionWithDefaultReturnValue()
348361
{
@@ -492,6 +505,19 @@ public void ShouldReturnResultShouldThrowExceptionWithDifferentModel()
492505
"When calling GenericInterfaceAction action in MvcController expected result to be List<ResponseModel>, but instead received ResponseModel.");
493506
}
494507

508+
[Fact]
509+
public void ShouldReturnResultShouldChainCorrectly()
510+
{
511+
MyController<MvcController>
512+
.Instance()
513+
.Calling(c => c.GenericActionWithCollection())
514+
.ShouldReturn()
515+
.Result(result => result
516+
.EqualTo(TestObjectFactory.GetListOfResponseModels())
517+
.AndAlso()
518+
.Passing(model => model.Count == 2));
519+
}
520+
495521
[Fact]
496522
public void DynamicResultShouldBeProperlyRecognized()
497523
{

0 commit comments

Comments
 (0)