Skip to content

Commit 8b46298

Browse files
committed
MyTested.AspNetCore.Mvc.EntityFrameworkCore now only depends on MyTested.AspNetCore.Mvc.Abstractions (#125)
1 parent 6a580b9 commit 8b46298

File tree

39 files changed

+291
-351
lines changed

39 files changed

+291
-351
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,18 @@
17091709
},
17101710
"Microsoft.VisualStudio.Web.BrowserLink.Loader/14.0.0-rc2-final": {
17111711
"type": "package",
1712+
"dependencies": {
1713+
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-final",
1714+
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-rc2-final",
1715+
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-final",
1716+
"Microsoft.NETCore.Platforms": "1.0.1-rc2-24027",
1717+
"Microsoft.Win32.Registry": "4.0.0-rc2-24027",
1718+
"System.Collections": "4.0.11-rc2-24027",
1719+
"System.Net.Sockets": "4.1.0-rc2-24027",
1720+
"System.Runtime.Loader": "4.0.0-rc2-24027",
1721+
"System.Text.Encoding": "4.0.11-rc2-24027",
1722+
"System.Threading": "4.0.11-rc2-24027"
1723+
},
17121724
"compile": {
17131725
"lib/netstandard1.5/Microsoft.VisualStudio.Web.BrowserLink.Loader.dll": {}
17141726
},
@@ -4260,7 +4272,7 @@
42604272
"framework": ".NETStandard,Version=v1.6",
42614273
"dependencies": {
42624274
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
4263-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
4275+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
42644276
},
42654277
"compile": {
42664278
"netstandard1.6/MyTested.AspNetCore.Mvc.EntityFrameworkCore.dll": {}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,7 +4415,7 @@
44154415
"framework": ".NETStandard,Version=v1.6",
44164416
"dependencies": {
44174417
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
4418-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
4418+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
44194419
},
44204420
"compile": {
44214421
"netstandard1.6/MyTested.AspNetCore.Mvc.EntityFrameworkCore.dll": {}
@@ -6765,7 +6765,7 @@
67656765
"framework": ".NETFramework,Version=v4.5.1",
67666766
"dependencies": {
67676767
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
6768-
"MyTested.AspNetCore.Mvc.Core": "1.0.0"
6768+
"MyTested.AspNetCore.Mvc.Abstractions": "1.0.0"
67696769
},
67706770
"compile": {
67716771
"net451/MyTested.AspNetCore.Mvc.EntityFrameworkCore.dll": {}
@@ -8124,7 +8124,7 @@
81248124
]
81258125
},
81268126
"Microsoft.IdentityModel.Logging/1.0.0": {
8127-
"sha512": "Ol7aYJKsY1UDDTnCjXai17G3bJ0Q7Xj97Ao4nCoSU3+sc1/uMaWhCs3RjsZnrapYbdBPtt1xTPbhC8R6M1MqWQ==",
8127+
"sha512": "8lt3q7o9xSLyKfja/D2J67N8EZLwISjXktkwxK275yOrZY16iNCHCWqtDVP1M/DHuC/LWFMoheF3lmaJC9UXQg==",
81288128
"type": "package",
81298129
"path": "Microsoft.IdentityModel.Logging/1.0.0",
81308130
"files": [
@@ -8137,7 +8137,7 @@
81378137
]
81388138
},
81398139
"Microsoft.IdentityModel.Protocols/2.0.0": {
8140-
"sha512": "ACezwKCnK5e+SECvwo1l7VWTd6tMdXhg2UPXOAJ7rh/v06q72VBFmc1hb40QEglDVRyV132HBI9zWRfHDCO2Gw==",
8140+
"sha512": "dHV39tCYxj8yMySDOUhNGakFQSNl3PZcweBWevtHyUeX/8UbroL0sQUHNjE38/UE0c4RS43WvWn+GO39R0PqOA==",
81418141
"type": "package",
81428142
"path": "Microsoft.IdentityModel.Protocols/2.0.0",
81438143
"files": [
@@ -8150,7 +8150,7 @@
81508150
]
81518151
},
81528152
"Microsoft.IdentityModel.Protocols.OpenIdConnect/2.0.0": {
8153-
"sha512": "JNVtDo5nnrBL15wSFQPuXxDd+bhuqjLHSVpkoEK9j7uKNG6oT1G7jheM8B9zHhcmQAUtnuFabRtZy+HadGBcNw==",
8153+
"sha512": "0TVkFvDN2fnDt7DelqZ5w7SEwpOiCycNc/CV1ZZjFEBY0Kn4EwG100Lhf7nvylm5CrgiDWYHb6Db8hnDDTpiWg==",
81548154
"type": "package",
81558155
"path": "Microsoft.IdentityModel.Protocols.OpenIdConnect/2.0.0",
81568156
"files": [
@@ -8163,7 +8163,7 @@
81638163
]
81648164
},
81658165
"Microsoft.IdentityModel.Tokens/5.0.0": {
8166-
"sha512": "EINdydCekJeyG+IyaB/3GbIfEeaOIU5GJiMmpCI+G+o1g9RvRHkS1hpG4KCp3J5nOLzr31k+rRtNrEQcJJEGOQ==",
8166+
"sha512": "VwNw+fm2nlbkL3GRO8b6WBlqs6M4q9Dft0CAg0TMHUYwuiU+4dciiIlZRC6q/HEcllKUvc0KDXt20n2PGcO1pA==",
81678167
"type": "package",
81688168
"path": "Microsoft.IdentityModel.Tokens/5.0.0",
81698169
"files": [
@@ -9935,7 +9935,7 @@
99359935
]
99369936
},
99379937
"System.IdentityModel.Tokens.Jwt/5.0.0": {
9938-
"sha512": "qq2qmY/lV/474QRm5/YBRX44Ez3K4qcqIeB7PC3TG+LlFRoTtVokUttj4TFTXyzOZ1B2JsuEFNFfW1W2FdtsFg==",
9938+
"sha512": "Ne69BCr2FPAysLG7pOM/+U/XFwGg849GIML2NuqtfEwBC3l74SaUPN3AmJfHccBcgOSDL3jVLQ3/ZQTtd3g6JA==",
99399939
"type": "package",
99409940
"path": "System.IdentityModel.Tokens.Jwt/5.0.0",
99419941
"files": [
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Base
22
{
3+
using Contracts.Base;
34
using Internal.TestContexts;
45

5-
public class BaseTestBuilderWithComponentBuilder<TBuilder> : BaseTestBuilder
6+
public abstract class BaseTestBuilderWithComponentBuilder<TBuilder> : BaseTestBuilder,
7+
IBaseTestBuilderWithComponentBuilder<TBuilder>
68
{
7-
public BaseTestBuilderWithComponentBuilder(HttpTestContext testContext)
9+
private TBuilder builder;
10+
11+
protected BaseTestBuilderWithComponentBuilder(HttpTestContext testContext)
812
: base(testContext)
913
{
1014
}
1115

12-
public TBuilder Builder { get; protected set; }
16+
public TBuilder Builder
17+
{
18+
get
19+
{
20+
if (this.builder == null)
21+
{
22+
this.builder = this.SetBuilder();
23+
}
24+
25+
return builder;
26+
}
27+
}
28+
29+
protected abstract TBuilder SetBuilder();
1330
}
1431
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace MyTested.AspNetCore.Mvc.Builders.Base
2+
{
3+
using Contracts.Base;
4+
using Internal.TestContexts;
5+
6+
public abstract class BaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder> : BaseTestBuilderWithComponent,
7+
IBaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder>
8+
{
9+
private TBuilder builder;
10+
11+
protected BaseTestBuilderWithComponentShouldHaveTestBuilder(ComponentTestContext testContext)
12+
: base(testContext)
13+
{
14+
}
15+
16+
public TBuilder Builder
17+
{
18+
get
19+
{
20+
if (this.builder == null)
21+
{
22+
this.builder = this.SetBuilder();
23+
}
24+
25+
return this.builder;
26+
}
27+
}
28+
29+
protected abstract TBuilder SetBuilder();
30+
}
31+
}
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.Base
2+
{
3+
public interface IBaseTestBuilderWithComponentShouldHaveTestBuilder<TBuilder> : IBaseTestBuilderWithComponent
4+
{
5+
}
6+
}

src/MyTested.AspNetCore.Mvc.Caching/ShouldHaveTestBuilderCachingExtensions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public static class ShouldHaveTestBuilderCachingExtensions
1818
/// </summary>
1919
/// <typeparam name="TActionResult">Type of action result type.</typeparam>
2020
/// <param name="shouldHaveTestBuilder">Instance of <see cref="IShouldHaveTestBuilder{TActionResult}"/> type.</param>
21-
/// <returns>Test builder of <see cref="IAndTestBuilder{TActionResult}"/> type.</returns>
22-
public static IAndTestBuilder<TActionResult> NoMemoryCache<TActionResult>(this IShouldHaveTestBuilder<TActionResult> shouldHaveTestBuilder)
21+
/// <returns>Test builder of <see cref="IAndActionResultTestBuilder{TActionResult}"/> type.</returns>
22+
public static IAndActionResultTestBuilder<TActionResult> NoMemoryCache<TActionResult>(this IShouldHaveTestBuilder<TActionResult> shouldHaveTestBuilder)
2323
{
2424
var actualShouldHaveTestBuilder = (ShouldHaveTestBuilder<TActionResult>)shouldHaveTestBuilder;
2525

@@ -30,7 +30,7 @@ public static IAndTestBuilder<TActionResult> NoMemoryCache<TActionResult>(this I
3030
MemoryCacheTestBuilder.MemoryCacheName);
3131
}
3232

33-
return actualShouldHaveTestBuilder.NewAndTestBuilder();
33+
return actualShouldHaveTestBuilder.Builder;
3434
}
3535

3636
/// <summary>
@@ -40,8 +40,8 @@ public static IAndTestBuilder<TActionResult> NoMemoryCache<TActionResult>(this I
4040
/// <param name="shouldHaveTestBuilder">Instance of <see cref="IShouldHaveTestBuilder{TActionResult}"/> type.</param>
4141
/// <param name="withNumberOfEntries">Expected number of <see cref="Microsoft.Extensions.Caching.Memory.IMemoryCache"/> entries.
4242
/// If default null is provided, the test builder checks only if any entries are found.</param>
43-
/// <returns>Test builder of <see cref="IAndTestBuilder{TActionResult}"/> type.</returns>
44-
public static IAndTestBuilder<TActionResult> MemoryCache<TActionResult>(
43+
/// <returns>Test builder of <see cref="IAndActionResultTestBuilder{TActionResult}"/> type.</returns>
44+
public static IAndActionResultTestBuilder<TActionResult> MemoryCache<TActionResult>(
4545
this IShouldHaveTestBuilder<TActionResult> shouldHaveTestBuilder,
4646
int? withNumberOfEntries = null)
4747
{
@@ -53,7 +53,7 @@ public static IAndTestBuilder<TActionResult> MemoryCache<TActionResult>(
5353
withNumberOfEntries,
5454
actualShouldHaveTestBuilder.TestContext.GetMockedMemoryCache().Count);
5555

56-
return actualShouldHaveTestBuilder.NewAndTestBuilder();
56+
return actualShouldHaveTestBuilder.Builder;
5757
}
5858

5959
/// <summary>
@@ -62,16 +62,16 @@ public static IAndTestBuilder<TActionResult> MemoryCache<TActionResult>(
6262
/// <typeparam name="TActionResult">Type of action result type.</typeparam>
6363
/// <param name="shouldHaveTestBuilder">Instance of <see cref="IShouldHaveTestBuilder{TActionResult}"/> type.</param>
6464
/// <param name="memoryCacheTestBuilder">Builder for testing specific <see cref="Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary"/> entries.</param>
65-
/// <returns>Test builder of <see cref="IAndTestBuilder{TActionResult}"/> type.</returns>
66-
public static IAndTestBuilder<TActionResult> MemoryCache<TActionResult>(
65+
/// <returns>Test builder of <see cref="IAndActionResultTestBuilder{TActionResult}"/> type.</returns>
66+
public static IAndActionResultTestBuilder<TActionResult> MemoryCache<TActionResult>(
6767
this IShouldHaveTestBuilder<TActionResult> shouldHaveTestBuilder,
6868
Action<IMemoryCacheTestBuilder> memoryCacheTestBuilder)
6969
{
7070
var actualShouldHaveTestBuilder = (ShouldHaveTestBuilder<TActionResult>)shouldHaveTestBuilder;
7171

7272
memoryCacheTestBuilder(new MemoryCacheTestBuilder(actualShouldHaveTestBuilder.TestContext));
7373

74-
return actualShouldHaveTestBuilder.NewAndTestBuilder();
74+
return actualShouldHaveTestBuilder.Builder;
7575
}
7676
}
7777
}

src/MyTested.AspNetCore.Mvc.Core/Builders/Actions/ShouldHave/ShouldHaveActionAttributes.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,46 @@
1414
public partial class ShouldHaveTestBuilder<TActionResult>
1515
{
1616
/// <inheritdoc />
17-
public IAndTestBuilder<TActionResult> NoActionAttributes()
17+
public IAndActionResultTestBuilder<TActionResult> NoActionAttributes()
1818
{
1919
AttributesValidator.ValidateNoAttributes(
20-
this.ActionLevelAttributes,
20+
this.TestContext.MethodAttributes,
2121
this.ThrowNewAttributeAssertionException);
2222

23-
return this.NewAndTestBuilder();
23+
return this.Builder;
2424
}
2525

2626
/// <inheritdoc />
27-
public IAndTestBuilder<TActionResult> ActionAttributes(int? withTotalNumberOf = null)
27+
public IAndActionResultTestBuilder<TActionResult> ActionAttributes(int? withTotalNumberOf = null)
2828
{
2929
AttributesValidator.ValidateNumberOfAttributes(
30-
this.ActionLevelAttributes,
30+
this.TestContext.MethodAttributes,
3131
this.ThrowNewAttributeAssertionException,
3232
withTotalNumberOf);
3333

34-
return this.NewAndTestBuilder();
34+
return this.Builder;
3535
}
3636

3737
/// <inheritdoc />
38-
public IAndTestBuilder<TActionResult> ActionAttributes(Action<IActionAttributesTestBuilder> attributesTestBuilder)
38+
public IAndActionResultTestBuilder<TActionResult> ActionAttributes(Action<IActionAttributesTestBuilder> attributesTestBuilder)
3939
{
4040
var newAttributesTestBuilder = new ActionAttributesTestBuilder(this.TestContext);
4141
attributesTestBuilder(newAttributesTestBuilder);
4242

4343
AttributesValidator.ValidateAttributes(
44-
this.ActionLevelAttributes,
44+
this.TestContext.MethodAttributes,
4545
newAttributesTestBuilder,
4646
this.ThrowNewAttributeAssertionException);
4747

48-
return this.NewAndTestBuilder();
48+
return this.Builder;
4949
}
5050

5151
private void ThrowNewAttributeAssertionException(string expectedValue, string actualValue)
5252
{
5353
throw new AttributeAssertionException(string.Format(
5454
"When calling {0} action in {1} expected action to {2}, but {3}.",
55-
this.ActionName,
56-
this.Controller.GetName(),
55+
this.TestContext.MethodName,
56+
this.TestContext.Component.GetName(),
5757
expectedValue,
5858
actualValue));
5959
}
Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,60 @@
11
namespace MyTested.AspNetCore.Mvc.Builders.Actions.ShouldHave
22
{
33
using System;
4+
using And;
45
using Base;
56
using Contracts.Actions;
67
using Contracts.And;
78
using Contracts.Http;
89
using Http;
910
using Internal.TestContexts;
11+
using Utilities.Validators;
1012

1113
/// <summary>
1214
/// Used for testing action attributes and controller properties.
1315
/// </summary>
1416
/// <typeparam name="TActionResult">Result from invoked action in ASP.NET Core MVC controller.</typeparam>
1517
public partial class ShouldHaveTestBuilder<TActionResult>
16-
: BaseTestBuilderWithActionResult<TActionResult>, IShouldHaveTestBuilder<TActionResult>
18+
: BaseTestBuilderWithComponentShouldHaveTestBuilder<IAndActionResultTestBuilder<TActionResult>>, IShouldHaveTestBuilder<TActionResult>
1719
{
20+
private ControllerTestContext testContext;
21+
1822
/// <summary>
1923
/// Initializes a new instance of the <see cref="ShouldHaveTestBuilder{TActionResult}"/> class.
2024
/// </summary>
2125
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
2226
public ShouldHaveTestBuilder(ControllerTestContext testContext)
2327
: base(testContext)
2428
{
29+
this.TestContext = testContext;
2530
}
31+
32+
/// <summary>
33+
/// Gets the currently used <see cref="ControllerTestContext"/>.
34+
/// </summary>
35+
/// <value>Result of type <see cref="ControllerTestContext"/>.</value>
36+
public new ControllerTestContext TestContext
37+
{
38+
get
39+
{
40+
return this.testContext;
41+
}
42+
43+
private set
44+
{
45+
CommonValidator.CheckForNullReference(value.Component, nameof(this.TestContext.Component));
46+
this.testContext = value;
47+
}
48+
}
49+
50+
protected override IAndActionResultTestBuilder<TActionResult> SetBuilder()
51+
=> new AndActionResultTestBuilder<TActionResult>(this.TestContext);
2652

2753
/// <inheritdoc />
28-
public IAndTestBuilder<TActionResult> HttpResponse(Action<IHttpResponseTestBuilder> httpResponseTestBuilder)
54+
public IAndActionResultTestBuilder<TActionResult> HttpResponse(Action<IHttpResponseTestBuilder> httpResponseTestBuilder)
2955
{
3056
httpResponseTestBuilder(new HttpResponseTestBuilder(this.TestContext));
31-
return this.NewAndTestBuilder();
57+
return this.Builder;
3258
}
3359
}
3460
}

src/MyTested.AspNetCore.Mvc.Core/Builders/Actions/ShouldReturn/ShouldReturnEmpty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class ShouldReturnTestBuilder<TActionResult>
1212
public IBaseTestBuilderWithActionResult<TActionResult> Empty()
1313
{
1414
this.ValidateActionReturnType<EmptyResult>();
15-
return this.NewAndProvideTestBuilder();
15+
return this.NewAndShouldPassForTestBuilder();
1616
}
1717
}
1818
}

src/MyTested.AspNetCore.Mvc.Core/Builders/Actions/ShouldReturn/ShouldReturnNoContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class ShouldReturnTestBuilder<TActionResult>
1212
public IBaseTestBuilderWithActionResult<TActionResult> NoContent()
1313
{
1414
this.ValidateActionReturnType<NoContentResult>();
15-
return this.NewAndProvideTestBuilder();
15+
return this.NewAndShouldPassForTestBuilder();
1616
}
1717
}
1818
}

0 commit comments

Comments
 (0)