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

Add netcoreapp1.0 test target to Nancy.Tests #2634

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 87 additions & 18 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,70 @@ Task("Compile")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var projects = GetFiles("./**/*.xproj");

if (IsRunningOnUnix())
{
projects = projects - GetFiles("./**/Nancy.Encryption.MachineKey.xproj");
}
var srcProjects = GetFiles("./src/**/*.xproj");
srcProjects = srcProjects - GetFiles("./**/Nancy.Encryption.MachineKey.xproj");

var testProjects = GetFiles("./test/**/*.xproj");

var dotnetTestProjects = testProjects
- GetFiles("test/**/Nancy.Authentication.Basic.Tests.xproj")
- GetFiles("test/**/Nancy.Authentication.Forms.Tests.xproj")
- GetFiles("test/**/Nancy.Embedded.Tests.xproj")
- GetFiles("test/**/Nancy.Encryption.MachineKey.Tests.xproj")
- GetFiles("test/**/Nancy.Hosting.Aspnet.Tests.xproj")
- GetFiles("test/**/Nancy.Hosting.Self.Tests.xproj")
- GetFiles("test/**/Nancy.Metadata.Modules.Tests.xproj")
- GetFiles("test/**/Nancy.Owin.Tests.xproj")
- GetFiles("test/**/Nancy.Testing.Tests.xproj")
- GetFiles("test/**/Nancy.Tests.Functional.xproj")
- GetFiles("test/**/Nancy.Validation.DataAnnotatioins.Tests.xproj")
- GetFiles("test/**/Nancy.Validation.FluentValidation.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.DotLiquid.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.Markdown.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.Models.xproj");

foreach(var srcProject in srcProjects)
{
DotNetCoreBuild(srcProject.GetDirectory().FullPath, new DotNetCoreBuildSettings {
Configuration = configuration,
Verbose = false
});
}

foreach(var project in projects)
foreach(var testProject in testProjects)
{
DotNetCoreBuild(testProject.GetDirectory().FullPath, new DotNetCoreBuildSettings {
Configuration = configuration,
Verbose = false,
Framework = "net452",
Runtime = "unix-x64"
});
}

foreach(var dotnetTestProject in dotnetTestProjects)
{
DotNetCoreBuild(dotnetTestProject.GetDirectory().FullPath, new DotNetCoreBuildSettings {
Configuration = configuration,
Verbose = false,
Framework = "netcoreapp1.0"
});
}
}
else
{
DotNetCoreBuild(project.GetDirectory().FullPath, new DotNetCoreBuildSettings {
Configuration = configuration,
Verbose = false,
Runtime = IsRunningOnWindows() ? null : "unix-x64"
});
var projects = GetFiles("./**/*.xproj");
projects = projects
- GetFiles("./**/Nancy.Encryption.MachineKey.xproj");
foreach(var project in projects)
{
DotNetCoreBuild(project.GetDirectory().FullPath, new DotNetCoreBuildSettings {
Configuration = configuration,
Verbose = false
});
}
}
});

Expand Down Expand Up @@ -255,6 +305,33 @@ Task("Test")
- GetFiles("./test/**/Nancy.Encryption.MachineKey.Tests.xproj")
- GetFiles("./test/**/Nancy.ViewEngines.DotLiquid.Tests.xproj")
- GetFiles("./test/**/Nancy.Embedded.Tests.xproj"); //Embedded somehow doesnt get executed on Travis but nothing explicit sets it

var testProjects = GetFiles("./test/**/*.xproj");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean on unix dotnet test is called and then mono is called as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I figured that would be desirable. Can be changed.

var dotnetTestProjects = testProjects
- GetFiles("test/**/Nancy.Authentication.Basic.Tests.xproj")
- GetFiles("test/**/Nancy.Authentication.Forms.Tests.xproj")
- GetFiles("test/**/Nancy.Embedded.Tests.xproj")
- GetFiles("test/**/Nancy.Encryption.MachineKey.Tests.xproj")
- GetFiles("test/**/Nancy.Hosting.Aspnet.Tests.xproj")
- GetFiles("test/**/Nancy.Hosting.Self.Tests.xproj")
- GetFiles("test/**/Nancy.Metadata.Modules.Tests.xproj")
- GetFiles("test/**/Nancy.Owin.Tests.xproj")
- GetFiles("test/**/Nancy.Testing.Tests.xproj")
- GetFiles("test/**/Nancy.Tests.Functional.xproj")
- GetFiles("test/**/Nancy.Validation.DataAnnotatioins.Tests.xproj")
- GetFiles("test/**/Nancy.Validation.FluentValidation.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.DotLiquid.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.Markdown.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.xproj")
- GetFiles("test/**/Nancy.ViewEngines.Razor.Tests.Models.xproj");

foreach(var dotnetTestProject in dotnetTestProjects)
{
DotNetCoreTest(dotnetTestProject.GetDirectory().FullPath, new DotNetCoreTestSettings {
Configuration = configuration,
Framework = "netcoreapp1.0"
});
}
}

foreach(var project in projects)
Expand All @@ -267,14 +344,6 @@ Task("Test")
}
else
{
// For when test projects are set to run against netstandard

// DotNetCoreTest(project.GetDirectory().FullPath, new DotNetCoreTestSettings {
// Configuration = configuration,
// Framework = "netstandard1.6",
// Runtime = "unix-64"
// });

var dirPath = project.GetDirectory().FullPath;
var testFile = project.GetFilenameWithoutExtension();

Expand Down
31 changes: 31 additions & 0 deletions test/Nancy.Tests/Helpers/AssemblyHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Nancy.Tests.Helpers
{
using System.IO;
using System.Reflection;

#if CORE
using System.Runtime.Loader;
#endif

/// <summary>
/// Convenience class with helper methods for <see cref="Assembly"/>.
/// </summary>
public static class AssemblyHelpers
{
/// <summary>
/// Loads an assembly from the emitted image contained in <paramref name="stream"/>.
/// </summary>
/// <param name="stream">The steam that contains the emitted assembly.</param>
/// <returns>The loaded assembly.</returns>
public static Assembly Load(MemoryStream stream)
{
#if CORE
stream.Position = 0;
return AssemblyLoadContext.Default.LoadFromStream(stream);
#else
return Assembly.Load(stream.ToArray());
#endif

}
}
}
4 changes: 1 addition & 3 deletions test/Nancy.Tests/NoAppStartupsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public IEnumerable<InstanceRegistration> InstanceRegistrations

private static void ThrowWhenNoAppStartupsFixtureRuns()
{
var frames = new StackTrace().GetFrames();

if (frames != null && frames.Select(f => f.GetMethod().DeclaringType).Any(t => t == typeof(NoAppStartupsFixture)))
if ( Environment.StackTrace.Contains(typeof(NoAppStartupsFixture).FullName))
{
throw new Exception();
}
Expand Down
6 changes: 3 additions & 3 deletions test/Nancy.Tests/Resources/Link.Texts.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions test/Nancy.Tests/Resources/Menu.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/Nancy.Tests/Resources/Menu.Texts.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion test/Nancy.Tests/Unit/AppDomainAssemblyCatalogFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Nancy.Tests.Unit
#if !CORE
namespace Nancy.Tests.Unit
{
using System;
using System.CodeDom.Compiler;
Expand Down Expand Up @@ -69,3 +70,4 @@ public AssemblyName GenerateAssemblyAndGetName()
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ protected override INancyEngine GetEngineInternal()
{
if (this.ShouldThrowWhenGettingEngine)
{
throw new ApplicationException("Something when wrong when trying to compose the engine.");
throw new Exception("Something when wrong when trying to compose the engine.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this exception type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ApplicationException in .NET Core. I'm happy to use another type, if you like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Na, fair enough. Let's use Exception since it's only in the context of the test itself

}

return this.FakeNancyEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected override INancyEngine GetEngineInternal()
{
if (this.ShouldThrowWhenGettingEngine)
{
throw new ApplicationException("Something when wrong when trying to compose the engine.");
throw new Exception("Something when wrong when trying to compose the engine.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this exception type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ApplicationException in .NET Core. I'm happy to use another type, if you like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

}

return this.FakeNancyEngine;
Expand Down
49 changes: 29 additions & 20 deletions test/Nancy.Tests/Unit/DefaultNancyBootstrapperFixture.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
namespace Nancy.Tests.Unit
{
using System.CodeDom.Compiler;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.CSharp;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Nancy.Bootstrapper;
using Nancy.Extensions;
using Nancy.Tests.Fakes;
using Nancy.Tests.Helpers;
using Nancy.TinyIoc;

using Xunit;
Expand Down Expand Up @@ -74,22 +78,27 @@ public void Request_should_be_available_to_request_startup()
public void Container_should_ignore_specified_assemblies()
{
// Given
var ass = CSharpCodeProvider
.CreateProvider("CSharp")
.CompileAssemblyFromSource(
new CompilerParameters
{
GenerateInMemory = true,
GenerateExecutable = false,
IncludeDebugInformation = false,
OutputAssembly = "TestAssembly.dll"
},
new[]
{
"public interface IWillNotBeResolved { int i { get; set; } }",
"public class WillNotBeResolved : IWillNotBeResolved { public int i { get; set; } }"
})
.CompiledAssembly;
var syntaxTree = CSharpSyntaxTree.ParseText(
"public interface IWillNotBeResolved { int i { get; set; } }" +
"public class WillNotBeResolved : IWillNotBeResolved { public int i { get; set; } }");

var mscorlib = MetadataReference.CreateFromFile(typeof(object).GetAssembly().Location);
var compilation = CSharpCompilation.Create("MyCompilation",
new[] { syntaxTree },
new[] { mscorlib },
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

Assembly ass;
using (var memoryStream = new MemoryStream())
{
var emitResult = compilation.Emit(memoryStream);

Assert.True(emitResult.Success,
"Compilation failed:" + Environment.NewLine + " " +
string.Join(Environment.NewLine + " ", emitResult.Diagnostics));

ass = AssemblyHelpers.Load(memoryStream);
}

// When
this.bootstrapper.Initialise ();
Expand Down Expand Up @@ -158,4 +167,4 @@ public class MultiInstance : IMultiInstance
public interface IMultiInstance
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Nancy.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is likely not required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetMethods on line 73 needs it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't that change shows in this change set? =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't understand. What change? Do you mean "a change involving GetMethods on line 73"? There is none. There was always (from my perspective) a call to GetMethods. In .NET Framework, it just worked. In .NET Core, we require a using System.Reflection, since GetMethods is an extension method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thecodejunkie, you asked for me to point out any unresponded-to comments. I'm afraid you didn't see this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's fine 👍

using Xunit;

public class InteractiveDiagnosticsFixture
Expand Down
2 changes: 2 additions & 0 deletions test/Nancy.Tests/Unit/IO/RequestStreamFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ public void Should_still_be_in_memory_when_more_bytes_have_been_written_to_strea
request.IsInMemory.ShouldBeTrue();
}

#if !CORE // BeginRead, EndRead, BeginWrite, EndWrite don't exist in .NET Core
[Fact]
public void Should_call_beginread_on_underlaying_stream_when_beginread_is_called()
{
Expand Down Expand Up @@ -553,6 +554,7 @@ public void Should_call_endwrite_on_underlaying_stream_when_endwrite_is_called()
// Then
A.CallTo(() => stream.EndWrite(asyncResult)).MustHaveHappened();
}
#endif

private static Stream CreateFakeStream()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using FakeItEasy;

using Nancy.Extensions;
using Nancy.Localization;

using Xunit;
Expand All @@ -14,7 +15,7 @@ public void Should_Return_Null_If_No_Assembly_Found()
{
// Given
var resourceAssemblyProvider = A.Fake<IResourceAssemblyProvider>();
A.CallTo(() => resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { typeof(NancyEngine).Assembly });
A.CallTo(() => resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { typeof(NancyEngine).GetAssembly() });

var defaultTextResource = new ResourceBasedTextResource(resourceAssemblyProvider);
var context = new NancyContext();
Expand All @@ -31,7 +32,7 @@ public void Should_return_resource_string_if_unique_match_could_be_made()
{
// Given
var resourceAssemblyProvider = A.Fake<IResourceAssemblyProvider>();
A.CallTo(() => resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { this.GetType().Assembly });
A.CallTo(() => resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { this.GetType().GetAssembly() });

var defaultTextResource = new ResourceBasedTextResource(resourceAssemblyProvider);
var context = new NancyContext();
Expand All @@ -51,7 +52,7 @@ public void Should_throw_exception_when_multiple_resources_matches_key()
"More than one text resources match the Texts key. Try providing a more specific key.";

var resourceAssemblyProvider = A.Fake<IResourceAssemblyProvider>();
A.CallTo(() => resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { this.GetType().Assembly });
A.CallTo(() => resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { this.GetType().GetAssembly() });

var defaultTextResource = new ResourceBasedTextResource(resourceAssemblyProvider);
var context = new NancyContext();
Expand Down
Loading