Skip to content

Commit 09f4fc0

Browse files
committed
Extracted Models and Helpers packages (#229)
1 parent 90d32a8 commit 09f4fc0

File tree

40 files changed

+15794
-362
lines changed

40 files changed

+15794
-362
lines changed

MyTested.AspNetCore.Mvc.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NoStartup.Components", "sam
132132
EndProject
133133
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NoStartup.Test", "samples\NoStartup\NoStartup.Test\NoStartup.Test.xproj", "{D28E4019-DC88-452D-8AEF-46799AB32B45}"
134134
EndProject
135+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Models", "src\MyTested.AspNetCore.Mvc.Models\MyTested.AspNetCore.Mvc.Models.xproj", "{A3C86420-DB2E-4103-A4B9-275B6F08C809}"
136+
EndProject
137+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Helpers", "src\MyTested.AspNetCore.Mvc.Helpers\MyTested.AspNetCore.Mvc.Helpers.xproj", "{776BC96D-F536-4788-808E-F0F25C26FB69}"
138+
EndProject
135139
Global
136140
GlobalSection(SolutionConfigurationPlatforms) = preSolution
137141
Debug|Any CPU = Debug|Any CPU
@@ -362,6 +366,14 @@ Global
362366
{D28E4019-DC88-452D-8AEF-46799AB32B45}.Debug|Any CPU.Build.0 = Debug|Any CPU
363367
{D28E4019-DC88-452D-8AEF-46799AB32B45}.Release|Any CPU.ActiveCfg = Release|Any CPU
364368
{D28E4019-DC88-452D-8AEF-46799AB32B45}.Release|Any CPU.Build.0 = Release|Any CPU
369+
{A3C86420-DB2E-4103-A4B9-275B6F08C809}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
370+
{A3C86420-DB2E-4103-A4B9-275B6F08C809}.Debug|Any CPU.Build.0 = Debug|Any CPU
371+
{A3C86420-DB2E-4103-A4B9-275B6F08C809}.Release|Any CPU.ActiveCfg = Release|Any CPU
372+
{A3C86420-DB2E-4103-A4B9-275B6F08C809}.Release|Any CPU.Build.0 = Release|Any CPU
373+
{776BC96D-F536-4788-808E-F0F25C26FB69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
374+
{776BC96D-F536-4788-808E-F0F25C26FB69}.Debug|Any CPU.Build.0 = Debug|Any CPU
375+
{776BC96D-F536-4788-808E-F0F25C26FB69}.Release|Any CPU.ActiveCfg = Release|Any CPU
376+
{776BC96D-F536-4788-808E-F0F25C26FB69}.Release|Any CPU.Build.0 = Release|Any CPU
365377
EndGlobalSection
366378
GlobalSection(SolutionProperties) = preSolution
367379
HideSolutionNode = FALSE
@@ -426,5 +438,7 @@ Global
426438
{7F5BA229-DC61-416A-B03A-0DE756C2459F} = {45B7B5FC-DF8C-498E-956E-28D56946C7DA}
427439
{A8975050-1824-46FB-A3EF-1C1B5CC5EF88} = {45B7B5FC-DF8C-498E-956E-28D56946C7DA}
428440
{D28E4019-DC88-452D-8AEF-46799AB32B45} = {45B7B5FC-DF8C-498E-956E-28D56946C7DA}
441+
{A3C86420-DB2E-4103-A4B9-275B6F08C809} = {09353A03-2B0C-496B-8EB1-2CB6A22D758B}
442+
{776BC96D-F536-4788-808E-F0F25C26FB69} = {09353A03-2B0C-496B-8EB1-2CB6A22D758B}
429443
EndGlobalSection
430444
EndGlobal

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Base/BaseTestBuilderWithResponseModel.cs

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
{
33
using System;
44
using Contracts.Base;
5-
using Contracts.Models;
65
using Internal;
76
using Internal.TestContexts;
87
using Exceptions;
9-
using Models;
108
using Utilities;
119

1210
public abstract class BaseTestBuilderWithResponseModel : BaseTestBuilderWithActionContext, IBaseTestBuilderWithResponseModel
@@ -20,56 +18,15 @@ public BaseTestBuilderWithResponseModel(ActionTestContext testContext)
2018
/// Gets or sets the error message format for the response model assertions.
2119
/// </summary>
2220
/// <value>String value.</value>
23-
protected string ErrorMessageFormat { get; set; } = ExceptionMessageFormats.ResponseModel;
21+
public string ErrorMessageFormat { get; set; } = ExceptionMessageFormats.ResponseModel;
2422

2523
/// <summary>
2624
/// Gets or sets the error message format for the response model type assertions.
2725
/// </summary>
2826
/// <value>String value.</value>
29-
protected string OfTypeErrorMessageFormat { get; set; } = ExceptionMessageFormats.ResponseModelOfType;
30-
31-
/// <inheritdoc />
32-
public IAndModelDetailsTestBuilder<TModel> WithModelOfType<TModel>()
33-
{
34-
var actualResponseDataType = this.GetReturnType();
35-
var expectedResponseDataType = typeof(TModel);
36-
37-
var responseDataTypeIsAssignable = Reflection.AreAssignable(
38-
expectedResponseDataType,
39-
actualResponseDataType);
40-
41-
if (!responseDataTypeIsAssignable)
42-
{
43-
throw new ResponseModelAssertionException(string.Format(
44-
this.OfTypeErrorMessageFormat,
45-
this.TestContext.ExceptionMessagePrefix,
46-
typeof(TModel).ToFriendlyTypeName(),
47-
actualResponseDataType.ToFriendlyTypeName()));
48-
}
49-
50-
this.TestContext.Model = this.GetActualModel<TModel>();
51-
return new ModelDetailsTestBuilder<TModel>(this.TestContext);
52-
}
53-
54-
/// <inheritdoc />
55-
public IAndModelDetailsTestBuilder<TModel> WithModel<TModel>(TModel expectedModel)
56-
{
57-
this.WithModelOfType<TModel>();
58-
59-
var actualModel = this.GetActualModel<TModel>();
60-
if (Reflection.AreNotDeeplyEqual(expectedModel, actualModel))
61-
{
62-
throw new ResponseModelAssertionException(string.Format(
63-
this.ErrorMessageFormat,
64-
this.TestContext.ExceptionMessagePrefix,
65-
typeof(TModel).ToFriendlyTypeName()));
66-
}
67-
68-
this.TestContext.Model = actualModel;
69-
return new ModelDetailsTestBuilder<TModel>(this.TestContext);
70-
}
27+
public string OfTypeErrorMessageFormat { get; set; } = ExceptionMessageFormats.ResponseModelOfType;
7128

72-
protected virtual TModel GetActualModel<TModel>()
29+
public virtual TModel GetActualModel<TModel>()
7330
{
7431
try
7532
{
@@ -84,8 +41,8 @@ protected virtual TModel GetActualModel<TModel>()
8441
}
8542
}
8643

87-
protected abstract object GetActualModel();
44+
public abstract object GetActualModel();
8845

89-
protected abstract Type GetReturnType();
46+
public abstract Type GetReturnType();
9047
}
9148
}
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Base
22
{
3-
using Models;
4-
53
/// <summary>
64
/// Base interface for all test builders with response model.
75
/// </summary>
86
public interface IBaseTestBuilderWithResponseModel : IBaseTestBuilderWithComponent
97
{
10-
/// <summary>
11-
/// Tests whether response model of the given type is returned from the invoked method.
12-
/// </summary>
13-
/// <typeparam name="TModel">Type of the response model.</typeparam>
14-
/// <returns>Test builder of <see cref="IModelDetailsTestBuilder{TResponseModel}"/>.</returns>
15-
IAndModelDetailsTestBuilder<TModel> WithModelOfType<TModel>();
16-
17-
/// <summary>
18-
/// Tests whether a deeply equal object to the provided one is returned from the invoked method.
19-
/// </summary>
20-
/// <typeparam name="TModel">Type of the response model.</typeparam>
21-
/// <param name="expectedModel">Expected model to be returned.</param>
22-
/// <returns>Test builder of <see cref="IModelDetailsTestBuilder{TResponseModel}"/>.</returns>
23-
IAndModelDetailsTestBuilder<TModel> WithModel<TModel>(TModel expectedModel);
248
}
259
}
Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,6 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Invocations
22
{
3-
using System;
4-
using Models;
5-
6-
public interface IBaseShouldReturnTestBuilder<TInvocationResult, TBuilder>
3+
public interface IBaseShouldReturnTestBuilder
74
{
8-
/// <summary>
9-
/// Tests whether the result is the default value of the type.
10-
/// </summary>
11-
/// <returns>Base test builder.</returns>
12-
TBuilder DefaultValue();
13-
14-
/// <summary>
15-
/// Tests whether the result is null.
16-
/// </summary>
17-
/// <returns>Base test builder.</returns>
18-
TBuilder Null();
19-
20-
/// <summary>
21-
/// Tests whether the result is not null.
22-
/// </summary>
23-
/// <returns>Base test builder.</returns>
24-
TBuilder NotNull();
25-
26-
/// <summary>
27-
/// Tests whether the result is of the provided type.
28-
/// </summary>
29-
/// <typeparam name="TResult">Expected response type.</typeparam>
30-
/// <returns>Test builder of <see cref="IModelDetailsTestBuilder{TResult}"/> type.</returns>
31-
IAndModelDetailsTestBuilder<TResult> ResultOfType<TResult>();
32-
33-
/// <summary>
34-
/// Tests whether the result is of the provided type.
35-
/// </summary>
36-
/// <param name="returnType">Expected return type.</param>
37-
/// <returns>Test builder of <see cref="IModelDetailsTestBuilder{TInvocationResult}"/> type.</returns>
38-
IAndModelDetailsTestBuilder<TInvocationResult> ResultOfType(Type returnType);
39-
40-
/// <summary>
41-
/// Tests whether the result is deeply equal to the provided one.
42-
/// </summary>
43-
/// <typeparam name="TResult">Expected response type.</typeparam>
44-
/// <param name="model">Expected return object.</param>
45-
/// <returns>Test builder of <see cref="IModelDetailsTestBuilder{TResult}"/> type.</returns>
46-
IAndModelDetailsTestBuilder<TResult> Result<TResult>(TResult model);
475
}
486
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Invocations
2+
{
3+
public interface IBaseShouldReturnTestBuilder<TInvocationResult, TBuilder>
4+
: IBaseShouldReturnTestBuilder<TInvocationResult>
5+
{
6+
/// <summary>
7+
/// Tests whether the result is the default value of the type.
8+
/// </summary>
9+
/// <returns>Base test builder.</returns>
10+
TBuilder DefaultValue();
11+
12+
/// <summary>
13+
/// Tests whether the result is null.
14+
/// </summary>
15+
/// <returns>Base test builder.</returns>
16+
TBuilder Null();
17+
18+
/// <summary>
19+
/// Tests whether the result is not null.
20+
/// </summary>
21+
/// <returns>Base test builder.</returns>
22+
TBuilder NotNull();
23+
}
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Contracts.Invocations
2+
{
3+
public interface IBaseShouldReturnTestBuilder<TInvocationResult> : IBaseShouldReturnTestBuilder
4+
{
5+
}
6+
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/ActionResults/BadRequest/BadRequestTestBuilder.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Net;
66
using Base;
77
using Contracts.ActionResults.BadRequest;
8-
using Contracts.Models;
98
using Exceptions;
109
using Internal.TestContexts;
1110
using Microsoft.AspNetCore.Mvc;
@@ -36,18 +35,6 @@ public BadRequestTestBuilder(ControllerTestContext testContext)
3635
this.OfTypeErrorMessageFormat = OfTypeErrorMessage;
3736
}
3837

39-
/// <inheritdoc />
40-
public IAndModelDetailsTestBuilder<TError> WithError<TError>(TError error)
41-
{
42-
return this.WithModel(error);
43-
}
44-
45-
/// <inheritdoc />
46-
public IAndModelDetailsTestBuilder<TError> WithErrorOfType<TError>()
47-
{
48-
return this.WithModelOfType<TError>();
49-
}
50-
5138
/// <inheritdoc />
5239
public IAndBadRequestTestBuilder WithNoError()
5340
{

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Actions/ShouldReturn/ShouldReturnResult.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Base/BaseTestBuilderWithActionResult.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Base
22
{
3-
using And;
4-
using Contracts.And;
53
using Contracts.Base;
64
using Internal.TestContexts;
75

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Base/BaseTestBuilderWithResponseModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.AspNetCore.Mvc;
1010
using Microsoft.AspNetCore.Mvc.Formatters;
1111
using Microsoft.Net.Http.Headers;
12-
using Utilities;
1312
using Utilities.Validators;
1413

1514
/// <summary>
@@ -187,12 +186,12 @@ private ObjectResult GetObjectResult()
187186
return objectResult;
188187
}
189188

190-
protected override object GetActualModel()
189+
public override object GetActualModel()
191190
{
192191
return (this.TestContext.MethodResult as ObjectResult)?.Value;
193192
}
194193

195-
protected override Type GetReturnType()
194+
public override Type GetReturnType()
196195
{
197196
if (this.TestContext.MethodResult is ObjectResult)
198197
{

0 commit comments

Comments
 (0)