Skip to content

Commit 443aa68

Browse files
committed
Added basic tests to validate the Versioning plugin is working correctly (#358)
1 parent df5434d commit 443aa68

File tree

27 files changed

+172
-28
lines changed

27 files changed

+172
-28
lines changed

MyTested.AspNetCore.Mvc.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.MultipleEntryPoints",
231231
EndProject
232232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "samples\Configuration\Common\Common.csproj", "{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}"
233233
EndProject
234+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Versioning", "plugins\MyTested.AspNetCore.Mvc.Versioning\MyTested.AspNetCore.Mvc.Versioning.csproj", "{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}"
235+
EndProject
236+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Versioning.Test", "test\MyTested.AspNetCore.Mvc.Versioning.Test\MyTested.AspNetCore.Mvc.Versioning.Test.csproj", "{6541FC98-C8B1-48CF-A3A5-7028B19455E8}"
237+
EndProject
234238
Global
235239
GlobalSection(SolutionConfigurationPlatforms) = preSolution
236240
Debug|Any CPU = Debug|Any CPU
@@ -645,6 +649,14 @@ Global
645649
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}.Debug|Any CPU.Build.0 = Debug|Any CPU
646650
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}.Release|Any CPU.ActiveCfg = Release|Any CPU
647651
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}.Release|Any CPU.Build.0 = Release|Any CPU
652+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
653+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Debug|Any CPU.Build.0 = Debug|Any CPU
654+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Release|Any CPU.ActiveCfg = Release|Any CPU
655+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}.Release|Any CPU.Build.0 = Release|Any CPU
656+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
657+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
658+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
659+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Release|Any CPU.Build.0 = Release|Any CPU
648660
EndGlobalSection
649661
GlobalSection(SolutionProperties) = preSolution
650662
HideSolutionNode = FALSE
@@ -760,6 +772,8 @@ Global
760772
{25649D8E-C12B-492E-8778-9638B0C4B31C} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
761773
{840C7C04-90CC-4F0F-BDF9-0D97D399BA3F} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
762774
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
775+
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73} = {EF386110-3D7B-4BDF-B403-8DC2AB8CF7BB}
776+
{6541FC98-C8B1-48CF-A3A5-7028B19455E8} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
763777
EndGlobalSection
764778
GlobalSection(ExtensibilityGlobals) = postSolution
765779
SolutionGuid = {99A2DEDD-5195-4EE6-A546-B1CA54C5539F}

plugins/MyTested.AspNetCore.Mvc.Versioning/Plugins/VersioningTestPlugin.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
public class VersioningTestPlugin : IHttpFeatureRegistrationPlugin
88
{
99
public Action<HttpContext> HttpFeatureRegistrationDelegate
10-
=> httpContext => httpContext.Features.Set(new ApiVersioningFeature(httpContext));
10+
=> httpContext => httpContext
11+
.Features
12+
.Set<IApiVersioningFeature>(new ApiVersioningFeature(httpContext));
1113
}
1214
}

src/MyTested.AspNetCore.Mvc.Abstractions/Utilities/Extensions/HttpContextExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Internal.Routing;
44
using Microsoft.AspNetCore.Http;
5+
using Microsoft.AspNetCore.Http.Features;
56
using Microsoft.AspNetCore.Routing;
67

78
public static class HttpContextExtensions
@@ -12,6 +13,11 @@ public static void SetRouteData(this HttpContext httpContext, RouteData routeDat
1213
{
1314
RouteData = routeData
1415
};
16+
17+
httpContext.Features[typeof(IRouteValuesFeature)] = new RouteValuesFeature
18+
{
19+
RouteValues = routeData.Values
20+
};
1521
}
1622
}
1723
}

test/MyTested.AspNetCore.Mvc.Caching.Test/PluginsTests/CachingTestPluginTest.cs renamed to test/MyTested.AspNetCore.Mvc.Caching.Test/PluginsTests/CachingTestPluginTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
22
{
3-
using System;
43
using Microsoft.Extensions.Caching.Distributed;
54
using Microsoft.Extensions.Caching.Memory;
65
using Microsoft.Extensions.DependencyInjection;
76
using Plugins;
87
using Xunit;
98

10-
public class CachingTestPluginTest
9+
public class CachingTestPluginTests
1110
{
1211
[Fact]
1312
public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()

test/MyTested.AspNetCore.Mvc.Controllers.Test/MyTested.AspNetCore.Mvc.Controllers.Test.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,4 @@
3434
<PackageReference Include="xunit" Version="2.4.1" />
3535
</ItemGroup>
3636

37-
<ItemGroup>
38-
<Folder Include="PluginsTests\" />
39-
</ItemGroup>
40-
4137
</Project>

test/MyTested.AspNetCore.Mvc.Controllers.Test/PluginsTests/ControllersTestPluginTest.cs renamed to test/MyTested.AspNetCore.Mvc.Controllers.Test/PluginsTests/ControllersTestPluginTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Plugins;
88
using Xunit;
99

10-
public class ControllersTestPluginTest
10+
public class ControllersTestPluginTests
1111
{
1212
[Fact]
1313
public void ShouldHavePriorityWithDefaultValue()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Plugins;
77
using Xunit;
88

9-
public class ViewActionResultTestPluginTest
9+
public class ViewActionResultTestPluginTests
1010
{
1111
[Fact]
1212
public void ShouldHavePriorityWithDefaultValue()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Plugins;
77
using Xunit;
88

9-
public class DataAnnotationsTestPluginTest
9+
public class DataAnnotationsTestPluginTests
1010
{
1111
[Fact]
1212
public void ShouldHavePriorityWithDefaultValue()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Plugins;
99
using Xunit;
1010

11-
public class EntityFrameworkCoreTestPluginTest
11+
public class EntityFrameworkCoreTestPluginTests
1212
{
1313
[Fact]
1414
public void ShouldThrowArgumentNullExceptionWithInvalidServiceCollection()

test/MyTested.AspNetCore.Mvc.Http.Test/PluginsTests/HttpTestPluginTest.cs renamed to test/MyTested.AspNetCore.Mvc.Http.Test/PluginsTests/HttpTestPluginTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
88
using Plugins;
99
using Xunit;
1010

11-
public class HttpTestPluginTest
11+
public class HttpTestPluginTests
1212
{
1313
[Fact]
1414
public void ShouldHavePriorityWithDefaultValue()

0 commit comments

Comments
 (0)