Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit ec6f251

Browse files
authored
Merge pull request #2634 from blairconrad/update-FIE-to-3.0.0-alpha001
Add netcoreapp1.0 test target to Nancy.Tests
2 parents 9d4b679 + 9fdb6f5 commit ec6f251

28 files changed

+320
-112
lines changed

build.cake

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,70 @@ Task("Compile")
5858
.IsDependentOn("Restore-NuGet-Packages")
5959
.Does(() =>
6060
{
61-
var projects = GetFiles("./**/*.xproj");
62-
6361
if (IsRunningOnUnix())
6462
{
65-
projects = projects - GetFiles("./**/Nancy.Encryption.MachineKey.xproj");
66-
}
63+
var srcProjects = GetFiles("./src/**/*.xproj");
64+
srcProjects = srcProjects - GetFiles("./**/Nancy.Encryption.MachineKey.xproj");
65+
66+
var testProjects = GetFiles("./test/**/*.xproj");
67+
68+
var dotnetTestProjects = testProjects
69+
- GetFiles("test/**/Nancy.Authentication.Basic.Tests.xproj")
70+
- GetFiles("test/**/Nancy.Authentication.Forms.Tests.xproj")
71+
- GetFiles("test/**/Nancy.Embedded.Tests.xproj")
72+
- GetFiles("test/**/Nancy.Encryption.MachineKey.Tests.xproj")
73+
- GetFiles("test/**/Nancy.Hosting.Aspnet.Tests.xproj")
74+
- GetFiles("test/**/Nancy.Hosting.Self.Tests.xproj")
75+
- GetFiles("test/**/Nancy.Metadata.Modules.Tests.xproj")
76+
- GetFiles("test/**/Nancy.Owin.Tests.xproj")
77+
- GetFiles("test/**/Nancy.Testing.Tests.xproj")
78+
- GetFiles("test/**/Nancy.Tests.Functional.xproj")
79+
- GetFiles("test/**/Nancy.Validation.DataAnnotatioins.Tests.xproj")
80+
- GetFiles("test/**/Nancy.Validation.FluentValidation.Tests.xproj")
81+
- GetFiles("test/**/Nancy.ViewEngines.DotLiquid.Tests.xproj")
82+
- GetFiles("test/**/Nancy.ViewEngines.Markdown.Tests.xproj")
83+
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.xproj")
84+
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.Models.xproj");
85+
86+
foreach(var srcProject in srcProjects)
87+
{
88+
DotNetCoreBuild(srcProject.GetDirectory().FullPath, new DotNetCoreBuildSettings {
89+
Configuration = configuration,
90+
Verbose = false
91+
});
92+
}
6793

68-
foreach(var project in projects)
94+
foreach(var testProject in testProjects)
95+
{
96+
DotNetCoreBuild(testProject.GetDirectory().FullPath, new DotNetCoreBuildSettings {
97+
Configuration = configuration,
98+
Verbose = false,
99+
Framework = "net452",
100+
Runtime = "unix-x64"
101+
});
102+
}
103+
104+
foreach(var dotnetTestProject in dotnetTestProjects)
105+
{
106+
DotNetCoreBuild(dotnetTestProject.GetDirectory().FullPath, new DotNetCoreBuildSettings {
107+
Configuration = configuration,
108+
Verbose = false,
109+
Framework = "netcoreapp1.0"
110+
});
111+
}
112+
}
113+
else
69114
{
70-
DotNetCoreBuild(project.GetDirectory().FullPath, new DotNetCoreBuildSettings {
71-
Configuration = configuration,
72-
Verbose = false,
73-
Runtime = IsRunningOnWindows() ? null : "unix-x64"
74-
});
115+
var projects = GetFiles("./**/*.xproj");
116+
projects = projects
117+
- GetFiles("./**/Nancy.Encryption.MachineKey.xproj");
118+
foreach(var project in projects)
119+
{
120+
DotNetCoreBuild(project.GetDirectory().FullPath, new DotNetCoreBuildSettings {
121+
Configuration = configuration,
122+
Verbose = false
123+
});
124+
}
75125
}
76126
});
77127

@@ -255,6 +305,33 @@ Task("Test")
255305
- GetFiles("./test/**/Nancy.Encryption.MachineKey.Tests.xproj")
256306
- GetFiles("./test/**/Nancy.ViewEngines.DotLiquid.Tests.xproj")
257307
- GetFiles("./test/**/Nancy.Embedded.Tests.xproj"); //Embedded somehow doesnt get executed on Travis but nothing explicit sets it
308+
309+
var testProjects = GetFiles("./test/**/*.xproj");
310+
var dotnetTestProjects = testProjects
311+
- GetFiles("test/**/Nancy.Authentication.Basic.Tests.xproj")
312+
- GetFiles("test/**/Nancy.Authentication.Forms.Tests.xproj")
313+
- GetFiles("test/**/Nancy.Embedded.Tests.xproj")
314+
- GetFiles("test/**/Nancy.Encryption.MachineKey.Tests.xproj")
315+
- GetFiles("test/**/Nancy.Hosting.Aspnet.Tests.xproj")
316+
- GetFiles("test/**/Nancy.Hosting.Self.Tests.xproj")
317+
- GetFiles("test/**/Nancy.Metadata.Modules.Tests.xproj")
318+
- GetFiles("test/**/Nancy.Owin.Tests.xproj")
319+
- GetFiles("test/**/Nancy.Testing.Tests.xproj")
320+
- GetFiles("test/**/Nancy.Tests.Functional.xproj")
321+
- GetFiles("test/**/Nancy.Validation.DataAnnotatioins.Tests.xproj")
322+
- GetFiles("test/**/Nancy.Validation.FluentValidation.Tests.xproj")
323+
- GetFiles("test/**/Nancy.ViewEngines.DotLiquid.Tests.xproj")
324+
- GetFiles("test/**/Nancy.ViewEngines.Markdown.Tests.xproj")
325+
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.xproj")
326+
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.Models.xproj");
327+
328+
foreach(var dotnetTestProject in dotnetTestProjects)
329+
{
330+
DotNetCoreTest(dotnetTestProject.GetDirectory().FullPath, new DotNetCoreTestSettings {
331+
Configuration = configuration,
332+
Framework = "netcoreapp1.0"
333+
});
334+
}
258335
}
259336

260337
foreach(var project in projects)
@@ -267,14 +344,6 @@ Task("Test")
267344
}
268345
else
269346
{
270-
// For when test projects are set to run against netstandard
271-
272-
// DotNetCoreTest(project.GetDirectory().FullPath, new DotNetCoreTestSettings {
273-
// Configuration = configuration,
274-
// Framework = "netstandard1.6",
275-
// Runtime = "unix-64"
276-
// });
277-
278347
var dirPath = project.GetDirectory().FullPath;
279348
var testFile = project.GetFilenameWithoutExtension();
280349

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace Nancy.Tests.Helpers
2+
{
3+
using System.IO;
4+
using System.Reflection;
5+
6+
#if CORE
7+
using System.Runtime.Loader;
8+
#endif
9+
10+
/// <summary>
11+
/// Convenience class with helper methods for <see cref="Assembly"/>.
12+
/// </summary>
13+
public static class AssemblyHelpers
14+
{
15+
/// <summary>
16+
/// Loads an assembly from the emitted image contained in <paramref name="stream"/>.
17+
/// </summary>
18+
/// <param name="stream">The steam that contains the emitted assembly.</param>
19+
/// <returns>The loaded assembly.</returns>
20+
public static Assembly Load(MemoryStream stream)
21+
{
22+
#if CORE
23+
stream.Position = 0;
24+
return AssemblyLoadContext.Default.LoadFromStream(stream);
25+
#else
26+
return Assembly.Load(stream.ToArray());
27+
#endif
28+
29+
}
30+
}
31+
}

test/Nancy.Tests/NoAppStartupsFixture.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public IEnumerable<InstanceRegistration> InstanceRegistrations
4444

4545
private static void ThrowWhenNoAppStartupsFixtureRuns()
4646
{
47-
var frames = new StackTrace().GetFrames();
48-
49-
if (frames != null && frames.Select(f => f.GetMethod().DeclaringType).Any(t => t == typeof(NoAppStartupsFixture)))
47+
if ( Environment.StackTrace.Contains(typeof(NoAppStartupsFixture).FullName))
5048
{
5149
throw new Exception();
5250
}

test/Nancy.Tests/Resources/Link.Texts.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Nancy.Tests/Resources/Menu.Designer.cs

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Nancy.Tests/Resources/Menu.Texts.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Nancy.Tests/Unit/AppDomainAssemblyCatalogFixture.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace Nancy.Tests.Unit
1+
#if !CORE
2+
namespace Nancy.Tests.Unit
23
{
34
using System;
45
using System.CodeDom.Compiler;
@@ -69,3 +70,4 @@ public AssemblyName GenerateAssemblyAndGetName()
6970
}
7071
}
7172
}
73+
#endif

test/Nancy.Tests/Unit/Bootstrapper/NancyBootstrapperBaseFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ protected override INancyEngine GetEngineInternal()
327327
{
328328
if (this.ShouldThrowWhenGettingEngine)
329329
{
330-
throw new ApplicationException("Something when wrong when trying to compose the engine.");
330+
throw new Exception("Something when wrong when trying to compose the engine.");
331331
}
332332

333333
return this.FakeNancyEngine;

test/Nancy.Tests/Unit/Bootstrapper/NancyBootstrapperWithRequestContainerBaseFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected override INancyEngine GetEngineInternal()
245245
{
246246
if (this.ShouldThrowWhenGettingEngine)
247247
{
248-
throw new ApplicationException("Something when wrong when trying to compose the engine.");
248+
throw new Exception("Something when wrong when trying to compose the engine.");
249249
}
250250

251251
return this.FakeNancyEngine;

test/Nancy.Tests/Unit/DefaultNancyBootstrapperFixture.cs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
namespace Nancy.Tests.Unit
22
{
3-
using System.CodeDom.Compiler;
3+
using System;
44
using System.Collections.Generic;
5+
using System.IO;
56
using System.Linq;
7+
using System.Reflection;
68
using System.Threading.Tasks;
7-
using Microsoft.CSharp;
8-
9+
using Microsoft.CodeAnalysis;
10+
using Microsoft.CodeAnalysis.CSharp;
911
using Nancy.Bootstrapper;
12+
using Nancy.Extensions;
1013
using Nancy.Tests.Fakes;
14+
using Nancy.Tests.Helpers;
1115
using Nancy.TinyIoc;
1216

1317
using Xunit;
@@ -74,22 +78,27 @@ public void Request_should_be_available_to_request_startup()
7478
public void Container_should_ignore_specified_assemblies()
7579
{
7680
// Given
77-
var ass = CSharpCodeProvider
78-
.CreateProvider("CSharp")
79-
.CompileAssemblyFromSource(
80-
new CompilerParameters
81-
{
82-
GenerateInMemory = true,
83-
GenerateExecutable = false,
84-
IncludeDebugInformation = false,
85-
OutputAssembly = "TestAssembly.dll"
86-
},
87-
new[]
88-
{
89-
"public interface IWillNotBeResolved { int i { get; set; } }",
90-
"public class WillNotBeResolved : IWillNotBeResolved { public int i { get; set; } }"
91-
})
92-
.CompiledAssembly;
81+
var syntaxTree = CSharpSyntaxTree.ParseText(
82+
"public interface IWillNotBeResolved { int i { get; set; } }" +
83+
"public class WillNotBeResolved : IWillNotBeResolved { public int i { get; set; } }");
84+
85+
var mscorlib = MetadataReference.CreateFromFile(typeof(object).GetAssembly().Location);
86+
var compilation = CSharpCompilation.Create("MyCompilation",
87+
new[] { syntaxTree },
88+
new[] { mscorlib },
89+
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
90+
91+
Assembly ass;
92+
using (var memoryStream = new MemoryStream())
93+
{
94+
var emitResult = compilation.Emit(memoryStream);
95+
96+
Assert.True(emitResult.Success,
97+
"Compilation failed:" + Environment.NewLine + " " +
98+
string.Join(Environment.NewLine + " ", emitResult.Diagnostics));
99+
100+
ass = AssemblyHelpers.Load(memoryStream);
101+
}
93102

94103
// When
95104
this.bootstrapper.Initialise ();
@@ -158,4 +167,4 @@ public class MultiInstance : IMultiInstance
158167
public interface IMultiInstance
159168
{
160169
}
161-
}
170+
}

0 commit comments

Comments
 (0)