Skip to content

Commit 9e57031

Browse files
committed
Added workaround for .NET 4.5.1 not being able to load plugins Startup class (#135)
1 parent 8ecf1e0 commit 9e57031

File tree

11 files changed

+330
-423
lines changed

11 files changed

+330
-423
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,18 +1709,6 @@
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-
},
17241712
"compile": {
17251713
"lib/netstandard1.5/Microsoft.VisualStudio.Web.BrowserLink.Loader.dll": {}
17261714
},

samples/ApplicationParts/ApplicationParts.Web/project.lock.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,18 +1705,6 @@
17051705
},
17061706
"Microsoft.VisualStudio.Web.BrowserLink.Loader/14.0.0-rc2-final": {
17071707
"type": "package",
1708-
"dependencies": {
1709-
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-final",
1710-
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-rc2-final",
1711-
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-final",
1712-
"Microsoft.NETCore.Platforms": "1.0.1-rc2-24027",
1713-
"Microsoft.Win32.Registry": "4.0.0-rc2-24027",
1714-
"System.Collections": "4.0.11-rc2-24027",
1715-
"System.Net.Sockets": "4.1.0-rc2-24027",
1716-
"System.Runtime.Loader": "4.0.0-rc2-24027",
1717-
"System.Text.Encoding": "4.0.11-rc2-24027",
1718-
"System.Threading": "4.0.11-rc2-24027"
1719-
},
17201708
"compile": {
17211709
"lib/netstandard1.5/Microsoft.VisualStudio.Web.BrowserLink.Loader.dll": {}
17221710
},

samples/MusicStore/MusicStore.Test/TestStartup.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
using Mocks;
77
using Models;
88
using MyTested.AspNetCore.Mvc;
9+
#if NET451
10+
using System.Reflection;
11+
using Microsoft.AspNetCore.Mvc.ApplicationParts;
12+
using MyTested.AspNetCore.Mvc.Internal;
13+
using MyTested.AspNetCore.Mvc.Session;
14+
#endif
915

1016
public class TestStartup : Startup
1117
{
@@ -19,6 +25,22 @@ public void ConfigureTestServices(IServiceCollection services)
1925
base.ConfigureServices(services);
2026

2127
services.ReplaceSingleton<SignInManager<ApplicationUser>, MockedSignInManager>();
28+
29+
// temporary workaround while DependencyContext issues are fixed for .NET 4.5.1
30+
#if NET451
31+
var mvc = services.AddMvc();
32+
var applicationParts = mvc.PartManager.ApplicationParts;
33+
applicationParts.Clear();
34+
applicationParts.Add(new AssemblyPart(typeof(Startup).GetTypeInfo().Assembly));
35+
36+
TestHelper.HttpFeatureRegistrationPlugins.Add(new SessionTestPlugin());
37+
38+
services.ReplaceDbContext();
39+
services.ReplaceMemoryCache();
40+
services.ReplaceSession();
41+
services.ReplaceOptions();
42+
services.ReplaceTempDataProvider();
43+
#endif
2244
}
2345
}
2446
}

samples/MusicStore/MusicStore.Test/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"warningsAsErrors": true,
44
"copyToOutput": {
55
"include": [
6-
"config.json"
6+
"config.json",
7+
"testconfig.json"
78
]
89
}
910
},

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8130,7 +8130,7 @@
81308130
]
81318131
},
81328132
"Microsoft.IdentityModel.Logging/1.0.0": {
8133-
"sha512": "8lt3q7o9xSLyKfja/D2J67N8EZLwISjXktkwxK275yOrZY16iNCHCWqtDVP1M/DHuC/LWFMoheF3lmaJC9UXQg==",
8133+
"sha512": "Ol7aYJKsY1UDDTnCjXai17G3bJ0Q7Xj97Ao4nCoSU3+sc1/uMaWhCs3RjsZnrapYbdBPtt1xTPbhC8R6M1MqWQ==",
81348134
"type": "package",
81358135
"path": "Microsoft.IdentityModel.Logging/1.0.0",
81368136
"files": [
@@ -8143,7 +8143,7 @@
81438143
]
81448144
},
81458145
"Microsoft.IdentityModel.Protocols/2.0.0": {
8146-
"sha512": "dHV39tCYxj8yMySDOUhNGakFQSNl3PZcweBWevtHyUeX/8UbroL0sQUHNjE38/UE0c4RS43WvWn+GO39R0PqOA==",
8146+
"sha512": "ACezwKCnK5e+SECvwo1l7VWTd6tMdXhg2UPXOAJ7rh/v06q72VBFmc1hb40QEglDVRyV132HBI9zWRfHDCO2Gw==",
81478147
"type": "package",
81488148
"path": "Microsoft.IdentityModel.Protocols/2.0.0",
81498149
"files": [
@@ -8156,7 +8156,7 @@
81568156
]
81578157
},
81588158
"Microsoft.IdentityModel.Protocols.OpenIdConnect/2.0.0": {
8159-
"sha512": "0TVkFvDN2fnDt7DelqZ5w7SEwpOiCycNc/CV1ZZjFEBY0Kn4EwG100Lhf7nvylm5CrgiDWYHb6Db8hnDDTpiWg==",
8159+
"sha512": "JNVtDo5nnrBL15wSFQPuXxDd+bhuqjLHSVpkoEK9j7uKNG6oT1G7jheM8B9zHhcmQAUtnuFabRtZy+HadGBcNw==",
81608160
"type": "package",
81618161
"path": "Microsoft.IdentityModel.Protocols.OpenIdConnect/2.0.0",
81628162
"files": [
@@ -8169,7 +8169,7 @@
81698169
]
81708170
},
81718171
"Microsoft.IdentityModel.Tokens/5.0.0": {
8172-
"sha512": "VwNw+fm2nlbkL3GRO8b6WBlqs6M4q9Dft0CAg0TMHUYwuiU+4dciiIlZRC6q/HEcllKUvc0KDXt20n2PGcO1pA==",
8172+
"sha512": "EINdydCekJeyG+IyaB/3GbIfEeaOIU5GJiMmpCI+G+o1g9RvRHkS1hpG4KCp3J5nOLzr31k+rRtNrEQcJJEGOQ==",
81738173
"type": "package",
81748174
"path": "Microsoft.IdentityModel.Tokens/5.0.0",
81758175
"files": [
@@ -9941,7 +9941,7 @@
99419941
]
99429942
},
99439943
"System.IdentityModel.Tokens.Jwt/5.0.0": {
9944-
"sha512": "Ne69BCr2FPAysLG7pOM/+U/XFwGg849GIML2NuqtfEwBC3l74SaUPN3AmJfHccBcgOSDL3jVLQ3/ZQTtd3g6JA==",
9944+
"sha512": "qq2qmY/lV/474QRm5/YBRX44Ez3K4qcqIeB7PC3TG+LlFRoTtVokUttj4TFTXyzOZ1B2JsuEFNFfW1W2FdtsFg==",
99459945
"type": "package",
99469946
"path": "System.IdentityModel.Tokens.Jwt/5.0.0",
99479947
"files": [
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"TestAssemblyName": "MusicStore.Test"
3+
}

samples/MusicStore/MusicStore.Web/project.lock.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7031,7 +7031,7 @@
70317031
]
70327032
},
70337033
"Microsoft.IdentityModel.Logging/1.0.0": {
7034-
"sha512": "8lt3q7o9xSLyKfja/D2J67N8EZLwISjXktkwxK275yOrZY16iNCHCWqtDVP1M/DHuC/LWFMoheF3lmaJC9UXQg==",
7034+
"sha512": "Ol7aYJKsY1UDDTnCjXai17G3bJ0Q7Xj97Ao4nCoSU3+sc1/uMaWhCs3RjsZnrapYbdBPtt1xTPbhC8R6M1MqWQ==",
70357035
"type": "package",
70367036
"path": "Microsoft.IdentityModel.Logging/1.0.0",
70377037
"files": [
@@ -7044,7 +7044,7 @@
70447044
]
70457045
},
70467046
"Microsoft.IdentityModel.Protocols/2.0.0": {
7047-
"sha512": "dHV39tCYxj8yMySDOUhNGakFQSNl3PZcweBWevtHyUeX/8UbroL0sQUHNjE38/UE0c4RS43WvWn+GO39R0PqOA==",
7047+
"sha512": "ACezwKCnK5e+SECvwo1l7VWTd6tMdXhg2UPXOAJ7rh/v06q72VBFmc1hb40QEglDVRyV132HBI9zWRfHDCO2Gw==",
70487048
"type": "package",
70497049
"path": "Microsoft.IdentityModel.Protocols/2.0.0",
70507050
"files": [
@@ -7057,7 +7057,7 @@
70577057
]
70587058
},
70597059
"Microsoft.IdentityModel.Protocols.OpenIdConnect/2.0.0": {
7060-
"sha512": "0TVkFvDN2fnDt7DelqZ5w7SEwpOiCycNc/CV1ZZjFEBY0Kn4EwG100Lhf7nvylm5CrgiDWYHb6Db8hnDDTpiWg==",
7060+
"sha512": "JNVtDo5nnrBL15wSFQPuXxDd+bhuqjLHSVpkoEK9j7uKNG6oT1G7jheM8B9zHhcmQAUtnuFabRtZy+HadGBcNw==",
70617061
"type": "package",
70627062
"path": "Microsoft.IdentityModel.Protocols.OpenIdConnect/2.0.0",
70637063
"files": [
@@ -7070,7 +7070,7 @@
70707070
]
70717071
},
70727072
"Microsoft.IdentityModel.Tokens/5.0.0": {
7073-
"sha512": "VwNw+fm2nlbkL3GRO8b6WBlqs6M4q9Dft0CAg0TMHUYwuiU+4dciiIlZRC6q/HEcllKUvc0KDXt20n2PGcO1pA==",
7073+
"sha512": "EINdydCekJeyG+IyaB/3GbIfEeaOIU5GJiMmpCI+G+o1g9RvRHkS1hpG4KCp3J5nOLzr31k+rRtNrEQcJJEGOQ==",
70747074
"type": "package",
70757075
"path": "Microsoft.IdentityModel.Tokens/5.0.0",
70767076
"files": [
@@ -8749,7 +8749,7 @@
87498749
]
87508750
},
87518751
"System.IdentityModel.Tokens.Jwt/5.0.0": {
8752-
"sha512": "Ne69BCr2FPAysLG7pOM/+U/XFwGg849GIML2NuqtfEwBC3l74SaUPN3AmJfHccBcgOSDL3jVLQ3/ZQTtd3g6JA==",
8752+
"sha512": "qq2qmY/lV/474QRm5/YBRX44Ez3K4qcqIeB7PC3TG+LlFRoTtVokUttj4TFTXyzOZ1B2JsuEFNFfW1W2FdtsFg==",
87538753
"type": "package",
87548754
"path": "System.IdentityModel.Tokens.Jwt/5.0.0",
87558755
"files": [

src/MyTested.AspNetCore.Mvc.Core/Internal/Application/TestApplication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ internal static void TryInitialize()
210210
internal static Type TryFindDefaultStartupType()
211211
{
212212
var applicationAssembly = Assembly.Load(new AssemblyName(testAssemblyName));
213-
213+
214214
var startupName = TestConfiguration.FullStartupName ?? $"{Environment.EnvironmentName}Startup";
215215

216216
// check root of the test project
@@ -245,7 +245,7 @@ private static IConfiguration PrepareTestConfiguration()
245245

246246
private static void FindTestAssemblyName()
247247
{
248-
testAssemblyName = DependencyContext
248+
testAssemblyName = TestConfiguration.TestAssemblyName ?? DependencyContext
249249
.Default
250250
.GetDefaultAssemblyNames()
251251
.First()

src/MyTested.AspNetCore.Mvc.Core/Internal/TestConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
internal class TestConfiguration
77
{
8+
private const string TestAssemblyNameConfigKey = "TestAssemblyName";
89
private const string ApplicationNameConfigKey = "ApplicationName";
910
private const string EnvironmentNameConfigKey = "Environment";
1011
private const string AutomaticStartupConfigKey = "AutomaticStartup";
@@ -20,6 +21,8 @@ private TestConfiguration(IConfiguration configuration)
2021
this.configuration = configuration;
2122
}
2223

24+
internal string TestAssemblyName => this.configuration[TestAssemblyNameConfigKey];
25+
2326
internal string ApplicationName => this.configuration[ApplicationNameConfigKey];
2427

2528
internal string EnvironmentName => this.configuration[EnvironmentNameConfigKey] ?? "Test";

src/MyTested.AspNetCore.Mvc.Core/Internal/TestHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class TestHelper
1515
{
1616
public static Action GlobalTestCleanup { get; set; }
1717

18-
internal static ISet<IHttpFeatureRegistrationPlugin> HttpFeatureRegistrationPlugins { get; }
18+
public static ISet<IHttpFeatureRegistrationPlugin> HttpFeatureRegistrationPlugins { get; }
1919
= new HashSet<IHttpFeatureRegistrationPlugin>();
2020

2121
/// <summary>

0 commit comments

Comments
 (0)