Skip to content

Commit 82a1c9f

Browse files
committed
MyTested.AspNetCore.Mvc.Session now depends only on MyTested.AspNetCore.Mvc.Abstractions (#125)
1 parent 578c6ae commit 82a1c9f

File tree

17 files changed

+160
-309
lines changed

17 files changed

+160
-309
lines changed

samples/ApplicationParts/ApplicationParts.Test/project.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4314,7 +4314,7 @@
43144314
"framework": ".NETStandard,Version=v1.6",
43154315
"dependencies": {
43164316
"Microsoft.AspNetCore.Session": "1.0.0",
4317-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
4317+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
43184318
},
43194319
"compile": {
43204320
"netstandard1.6/MyTested.AspNetCore.Mvc.Session.dll": {}

samples/MusicStore/MusicStore.Test/project.lock.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,7 +4457,7 @@
44574457
"framework": ".NETStandard,Version=v1.6",
44584458
"dependencies": {
44594459
"Microsoft.AspNetCore.Session": "1.0.0",
4460-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
4460+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
44614461
},
44624462
"compile": {
44634463
"netstandard1.6/MyTested.AspNetCore.Mvc.Session.dll": {}
@@ -6803,7 +6803,7 @@
68036803
"framework": ".NETFramework,Version=v4.5.1",
68046804
"dependencies": {
68056805
"Microsoft.AspNetCore.Session": "1.0.0",
6806-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
6806+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
68076807
},
68086808
"compile": {
68096809
"net451/MyTested.AspNetCore.Mvc.Session.dll": {}

src/MyTested.AspNetCore.Mvc.Core/Builders/Data/BaseDataProviderTestBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/BaseDataProviderTestBuilder.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
/// <summary>
1212
/// Base class for all data provider test builder.
1313
/// </summary>
14-
public abstract class BaseDataProviderTestBuilder : BaseTestBuilderWithInvokedAction
14+
public abstract class BaseDataProviderTestBuilder : BaseTestBuilderWithComponent
1515
{
16+
private IDictionary<string, object> dataProvider;
17+
1618
/// <summary>
1719
/// Initializes a new instance of the <see cref="BaseDataProviderTestBuilder"/> class.
1820
/// </summary>
19-
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
21+
/// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
2022
/// <param name="dataProviderName">Name of the data provider.</param>
21-
protected BaseDataProviderTestBuilder(ControllerTestContext testContext, string dataProviderName)
23+
protected BaseDataProviderTestBuilder(ComponentTestContext testContext, string dataProviderName)
2224
: base(testContext)
2325
{
2426
CommonValidator.CheckForNotWhiteSpaceString(dataProviderName);
2527
this.DataProviderName = dataProviderName;
26-
this.DataProvider = this.GetDataProvider();
27-
CommonValidator.CheckForNullReference(this.DataProvider);
2828
}
2929

3030
/// <summary>
@@ -37,7 +37,20 @@ protected BaseDataProviderTestBuilder(ControllerTestContext testContext, string
3737
/// Gets the data provider as <see cref="IDictionary{TKey,TValue}"/>.
3838
/// </summary>
3939
/// <value>Data provider as <see cref="IDictionary{TKey,TValue}"/>.</value>
40-
protected IDictionary<string, object> DataProvider { get; private set; }
40+
protected IDictionary<string, object> DataProvider
41+
{
42+
get
43+
{
44+
if (this.dataProvider == null)
45+
{
46+
this.dataProvider = this.GetDataProvider();
47+
CommonValidator.CheckForNullReference(this.dataProvider, nameof(this.DataProvider));
48+
}
49+
50+
return this.dataProvider;
51+
}
52+
}
53+
4154

4255
/// <summary>
4356
/// When overridden in derived class provides a way to built the data provider as <see cref="IDictionary{TKey,TValue}"/>.
@@ -143,8 +156,8 @@ protected void ThrowNewDataProviderAssertionException(string propertyName, strin
143156
{
144157
throw new DataProviderAssertionException(string.Format(
145158
"When calling {0} action in {1} expected {2} {3}, but {4}.",
146-
this.ActionName,
147-
this.Controller.GetName(),
159+
this.TestContext.MethodName,
160+
this.TestContext.Component.GetName(),
148161
propertyName,
149162
expectedValue,
150163
actualValue));

src/MyTested.AspNetCore.Mvc.Core/Builders/Data/BaseDataProviderWithStringKeyTestBuilder.cs renamed to src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/BaseDataProviderWithStringKeyTestBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public abstract class BaseDataProviderWithStringKeyTestBuilder<TDataProviderTest
1414
/// <summary>
1515
/// Initializes a new instance of the <see cref="BaseDataProviderTestBuilder"/> class.
1616
/// </summary>
17-
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
17+
/// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
1818
/// <param name="dataProviderName">Name of the data provider.</param>
19-
protected BaseDataProviderWithStringKeyTestBuilder(ControllerTestContext testContext, string dataProviderName)
19+
protected BaseDataProviderWithStringKeyTestBuilder(ComponentTestContext testContext, string dataProviderName)
2020
: base(testContext, dataProviderName)
2121
{
2222
}

src/MyTested.AspNetCore.Mvc.Options/ControllerBuilderOptionsExtensions.cs renamed to src/MyTested.AspNetCore.Mvc.Options/ComponentBuilderOptionsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// <summary>
1010
/// Contains configuration options extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
1111
/// </summary>
12-
public static class ControllerBuilderOptionsExtensions
12+
public static class ComponentBuilderOptionsExtensions
1313
{
1414
/// <summary>
1515
/// Sets initial values to the configuration options on the tested component.

src/MyTested.AspNetCore.Mvc.Session/Builders/Data/SessionTestBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class SessionTestBuilder : BaseDataProviderTestBuilder, IAndSessionTestBu
1919
/// <summary>
2020
/// Initializes a new instance of the <see cref="SessionTestBuilder"/> class.
2121
/// </summary>
22-
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
23-
public SessionTestBuilder(ControllerTestContext testContext)
22+
/// <param name="testContext"><see cref="ComponentTestContext"/> containing data about the currently executed assertion chain.</param>
23+
public SessionTestBuilder(ComponentTestContext testContext)
2424
: base(testContext, SessionName)
2525
{
2626
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using System;
4+
using Builders.Base;
5+
using Builders.Contracts.Base;
6+
using Builders.Contracts.Data;
7+
using Builders.Data;
8+
9+
/// <summary>
10+
/// Contains <see cref="Microsoft.AspNetCore.Http.ISession"/> extension methods for <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/>.
11+
/// </summary>
12+
public static class ComponentBuilderSessionExtensions
13+
{
14+
/// <summary>
15+
/// Sets initial values to the HTTP <see cref="Microsoft.AspNetCore.Http.ISession"/>.
16+
/// </summary>
17+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
18+
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentBuilder{TBuilder}"/> type.</param>
19+
/// <param name="sessionBuilder">Action setting the <see cref="Microsoft.AspNetCore.Http.ISession"/> values by using <see cref="ISessionBuilder"/>.</param>
20+
/// <returns>The same component builder.</returns>
21+
public static TBuilder WithSession<TBuilder>(
22+
this IBaseTestBuilderWithComponentBuilder<TBuilder> builder,
23+
Action<ISessionBuilder> sessionBuilder)
24+
where TBuilder : IBaseTestBuilder
25+
{
26+
var actualBuilder = (BaseTestBuilderWithComponentBuilder<TBuilder>)builder;
27+
28+
sessionBuilder(new SessionBuilder(actualBuilder.TestContext.Session));
29+
30+
return actualBuilder.Builder;
31+
}
32+
}
33+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using System;
4+
using System.Linq;
5+
using Builders.Base;
6+
using Builders.Contracts.Base;
7+
using Builders.Contracts.Data;
8+
using Builders.Data;
9+
using Utilities.Validators;
10+
11+
/// <summary>
12+
/// Contains <see cref="Microsoft.AspNetCore.Http.ISession"/> extension methods for <see cref="IBaseTestBuilderWithComponentShouldHaveTestBuilder{TBuilder}"/>.
13+
/// </summary>
14+
public static class ComponentShouldHaveTestBuilderSessionExtensions
15+
{
16+
/// <summary>
17+
/// Tests whether the component does not set any <see cref="Microsoft.AspNetCore.Http.ISession"/> entries.
18+
/// </summary>
19+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
20+
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentShouldHaveTestBuilder{TBuilder}"/> type.</param>
21+
/// <returns>The same component should have test builder.</returns>
22+
public static TBuilder NoSession<TBuilder>(this IBaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder> builder)
23+
where TBuilder : IBaseTestBuilder
24+
{
25+
var actualBuilder = (BaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder>)builder;
26+
27+
if (actualBuilder.TestContext.Session.Keys.Any())
28+
{
29+
DataProviderValidator.ThrowNewDataProviderAssertionExceptionWithNoEntries(
30+
actualBuilder.TestContext,
31+
SessionTestBuilder.SessionName);
32+
}
33+
34+
return actualBuilder.Builder;
35+
}
36+
37+
/// <summary>
38+
/// Tests whether the component sets entries in the <see cref="Microsoft.AspNetCore.Http.ISession"/>.
39+
/// </summary>
40+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
41+
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentShouldHaveTestBuilder{TBuilder}"/> type.</param>
42+
/// <param name="withNumberOfEntries">Expected number of <see cref="Microsoft.AspNetCore.Http.ISession"/> entries.
43+
/// If default null is provided, the test builder checks only if any entries are found.</param>
44+
/// <returns>The same component should have test builder.</returns>
45+
public static TBuilder Session<TBuilder>(
46+
this IBaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder> builder,
47+
int? withNumberOfEntries = null)
48+
where TBuilder : IBaseTestBuilder
49+
{
50+
var actualBuilder = (BaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder>)builder;
51+
52+
DataProviderValidator.ValidateDataProviderNumberOfEntries(
53+
actualBuilder.TestContext,
54+
SessionTestBuilder.SessionName,
55+
withNumberOfEntries,
56+
actualBuilder.TestContext.Session.Keys.Count());
57+
58+
return actualBuilder.Builder;
59+
}
60+
61+
/// <summary>
62+
/// Tests whether the component sets specific <see cref="Microsoft.AspNetCore.Http.ISession"/> entries.
63+
/// </summary>
64+
/// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
65+
/// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentShouldHaveTestBuilder{TBuilder}"/> type.</param>
66+
/// <param name="sessionTestBuilder">Builder for testing specific <see cref="Microsoft.AspNetCore.Http.ISession"/> entries.</param>
67+
/// <returns>The same component should have test builder.</returns>
68+
public static TBuilder Session<TBuilder>(
69+
this IBaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder> builder,
70+
Action<ISessionTestBuilder> sessionTestBuilder)
71+
where TBuilder : IBaseTestBuilder
72+
{
73+
var actualBuilder = (BaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder>)builder;
74+
75+
sessionTestBuilder(new SessionTestBuilder(actualBuilder.TestContext));
76+
77+
return actualBuilder.Builder;
78+
}
79+
}
80+
}

src/MyTested.AspNetCore.Mvc.Session/ControllerBuilderSessionExtensions.cs

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

src/MyTested.AspNetCore.Mvc.Session/ShouldHaveTestBuilderSessionExtensions.cs

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

0 commit comments

Comments
 (0)