Skip to content
Browse files

Merge pull request #2272 from thecodejunkie/coreclr-convert-nancy-tes…

…ts-to-project-json

Converted Nancy.Tests to project.json
  • Loading branch information...
2 parents b4b3d97 + 04e7d17 commit 48cf11086207c2a5aa26559a7ec589b2ae309075 @jchannon jchannon committed
View
1 .gitignore
@@ -30,3 +30,4 @@ Gemfile.lock
.vs/
packages/
project.lock.json
+TestAssembly.dll
View
21 Nancy.Next.sln
@@ -48,6 +48,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Nancy.ViewEngines.Razor.Bui
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Nancy.ViewEngines.Spark", "src\Nancy.ViewEngines.Spark\Nancy.ViewEngines.Spark.xproj", "{25E3AB38-D95E-4D11-B0F0-0F60571A97A0}"
EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Nancy.Tests", "test\Nancy.Tests\Nancy.Tests.xproj", "{3BA7D452-98E5-47B0-BD1E-DC348E13A72A}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F44224E5-8E58-4D52-A0F0-BCBA2ADC0A0B}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -130,6 +134,22 @@ Global
{25E3AB38-D95E-4D11-B0F0-0F60571A97A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25E3AB38-D95E-4D11-B0F0-0F60571A97A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25E3AB38-D95E-4D11-B0F0-0F60571A97A0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3BA7D452-98E5-47B0-BD1E-DC348E13A72A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3BA7D452-98E5-47B0-BD1E-DC348E13A72A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3BA7D452-98E5-47B0-BD1E-DC348E13A72A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3BA7D452-98E5-47B0-BD1E-DC348E13A72A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5C28CEAB-C794-4B97-9304-85EC3095C627}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5C28CEAB-C794-4B97-9304-85EC3095C627}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5C28CEAB-C794-4B97-9304-85EC3095C627}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5C28CEAB-C794-4B97-9304-85EC3095C627}.Release|Any CPU.Build.0 = Release|Any CPU
+ {58FC1168-11F4-440B-B46A-EADF54A2612F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {58FC1168-11F4-440B-B46A-EADF54A2612F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {58FC1168-11F4-440B-B46A-EADF54A2612F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {58FC1168-11F4-440B-B46A-EADF54A2612F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E2712DB8-09AF-41DA-AE6E-81F43B54DE91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E2712DB8-09AF-41DA-AE6E-81F43B54DE91}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E2712DB8-09AF-41DA-AE6E-81F43B54DE91}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E2712DB8-09AF-41DA-AE6E-81F43B54DE91}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -154,5 +174,6 @@ Global
{3A376B78-DD7D-4450-9FDE-F7236FAA6E63} = {5734E9DC-CF67-4337-B28E-695280598B88}
{26DF3BE0-146B-43A6-B230-D5B33355F415} = {5734E9DC-CF67-4337-B28E-695280598B88}
{25E3AB38-D95E-4D11-B0F0-0F60571A97A0} = {5734E9DC-CF67-4337-B28E-695280598B88}
+ {3BA7D452-98E5-47B0-BD1E-DC348E13A72A} = {F44224E5-8E58-4D52-A0F0-BCBA2ADC0A0B}
EndGlobalSection
EndGlobal
View
4 SharedAssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("Nancy")]
[assembly: AssemblyDescription("A Sinatra inspired web framework for the .NET platform")]
@@ -8,6 +7,3 @@
[assembly: AssemblyCopyright("Copyright (C) Andreas Hakansson, Steven Robbins and contributors")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyInformationalVersion("1.4.1")]
-
-[assembly: InternalsVisibleTo("Nancy.Tests")]
-[assembly: InternalsVisibleTo("Nancy.Hosting.Self.Tests")]
View
17 build.ps1
@@ -45,8 +45,7 @@ function Pack-Projects
function Test-Projects
{
- param([string] $DirectoryName)
- & dnx -p ("""" + $DirectoryName + """") test; if($LASTEXITCODE -ne 0) { exit 3 }
+ & dnx test; if($LASTEXITCODE -ne 0) { exit 3 }
}
function Remove-PathVariable
@@ -99,12 +98,20 @@ Write-Host "Build number: " $env:DNX_BUILD_VERSION
Get-ChildItem -Path .\src -Filter *.xproj -Recurse | ForEach-Object { Pack-Projects $_.DirectoryName $env:CONFIGURATION }
# Test - Skipping tests until properly migrated to new xUnit
-Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName }
+Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object {
+ Push-Location $_.DirectoryName
+ Test-Projects $_.DirectoryName
+ Pop-Location
+ }
# Switch to Core CLR
-dnvm use $dnxVersion -r CoreCLR
+#dnvm use $dnxVersion -r CoreCLR
# Test again
-Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName }
+# Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object {
+# Push-Location $_.DirectoryName
+# Test-Projects $_.DirectoryName
+# Pop-Location
+# }
Pop-Location
View
3 src/Nancy.Hosting.Self.MSBuild/Nancy.Hosting.Self.csproj
@@ -103,6 +103,9 @@
<Compile Include="..\Nancy.Hosting.Self\IgnoredHeaders.cs">
<Link>IgnoredHeaders.cs</Link>
</Compile>
+ <Compile Include="..\Nancy.Hosting.Self\Properties\InternalsVisibleTo.cs">
+ <Link>Properties\InternalsVisibleTo.cs</Link>
+ </Compile>
<Compile Include="..\Nancy.Hosting.Self\UrlReservations.cs">
<Link>UrlReservations.cs</Link>
</Compile>
View
3 src/Nancy.Hosting.Self/Properties/InternalsVisibleTo.cs
@@ -0,0 +1,3 @@
+using System.Runtime.CompilerServices;
+
+[assembly: InternalsVisibleTo("Nancy.Hosting.Self.Tests")]
View
3 src/Nancy.MSBuild/Nancy.csproj
@@ -383,6 +383,9 @@
<Compile Include="..\Nancy\ITypeCatalog.cs">
<Link>ITypeCatalog.cs</Link>
</Compile>
+ <Compile Include="..\Nancy\Properties\InternalsVisibleTo.cs">
+ <Link>Properties\InternalsVisibleTo.cs</Link>
+ </Compile>
<Compile Include="..\Nancy\TypeCatalogExtensions.cs">
<Link>TypeCatalogExtensions.cs</Link>
</Compile>
View
4 src/Nancy/Properties/InternalsVisibleTo.cs
@@ -0,0 +1,4 @@
+using System.Runtime.CompilerServices;
+
+[assembly: InternalsVisibleTo("Nancy.Tests")]
+[assembly: InternalsVisibleTo("Nancy.Hosting.Self.Tests")]
View
5 src/Nancy/project.json
@@ -8,6 +8,11 @@
"licenseUrl": "https://github.com/NancyFx/Nancy/blob/master/license.txt",
"iconUrl": "http://nancyfx.org/nancy-nuget.png",
+ "resource": [
+ "Diagnostics/Resources/**/*.*",
+ "Diagnostics/Views/**/*.*"
+ ],
+
"frameworks": {
"net451": {
"frameworkAssemblies": {
View
20 test/Nancy.Tests/Nancy.Tests.xproj
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>3ba7d452-98e5-47b0-bd1e-dc348e13a72a</ProjectGuid>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
+ </PropertyGroup>
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <ItemGroup>
+ <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
+ </ItemGroup>
+ <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>
View
37 test/Nancy.Tests/Unit/ResponseExtensionsFixture.cs
@@ -44,21 +44,18 @@ public void Should_not_allow_null_filename_on_generic_responses_as_attachments()
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden()
{
// Given
- var assemblyPath =
- Path.GetDirectoryName(this.GetType().Assembly.Location);
-
var environment = new DefaultNancyEnvironment();
- environment.StaticContent(safepaths:assemblyPath);
+ environment.StaticContent(safepaths:this.GetLocation());
- var filename = Path.GetFileName(this.GetType().Assembly.Location);
- var response = new GenericFileResponse(filename, "image/png", new NancyContext() {Environment = environment});
+ var filename = this.GetFilePath();
+ var response = new GenericFileResponse(filename, "foo/bar", new NancyContext() {Environment = environment});
// When
var result = response.AsAttachment();
-
+
// Then
- result.Headers["Content-Disposition"].ShouldContain(filename);
- result.ContentType.ShouldEqual("image/png");
+ result.Headers["Content-Disposition"].ShouldContain(Path.GetFileName(filename));
+ result.ContentType.ShouldEqual("foo/bar");
}
[Fact]
@@ -114,7 +111,7 @@ public void Should_add_all_headers_using_withheaders()
var response = new Response();
var result = response.WithHeaders(
- Tuple.Create("test", "testvalue"),
+ Tuple.Create("test", "testvalue"),
Tuple.Create("test2", "test2value"));
result.Headers.ShouldNotBeNull();
@@ -128,7 +125,7 @@ public void Should_be_able_to_supply_withHeaders_headers_as_anonymous_types()
var response = new Response();
var result = response.WithHeaders(
- new { Header = "test", Value = "testvalue" },
+ new { Header = "test", Value = "testvalue" },
new { Header = "test2", Value = "test2value" });
result.Headers.ShouldNotBeNull();
@@ -177,5 +174,23 @@ public void Should_set_status_code_int()
respone.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
}
+
+ private string GetLocation()
+ {
+#if DNX
+ return Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath;
+#else
+ return Path.GetDirectoryName(this.GetType().Assembly.Location);
+#endif
+ }
+
+ private string GetFilePath()
+ {
+#if DNX
+ return Path.Combine("Resources", "test.txt");
+#else
+ return Path.GetFileName(this.GetType().Assembly.Location);
+#endif
+ }
}
}
View
90 test/Nancy.Tests/Unit/Responses/GenericFileResponseFixture.cs
@@ -2,37 +2,50 @@
{
using System.Collections.Generic;
using System.IO;
-
using Nancy.Configuration;
using Nancy.Responses;
-
using Xunit;
+ using Xunit.Abstractions;
public class GenericFileResponseFixture
{
- private readonly string imagePath;
- private const string imageContentType = "image/png";
+ private readonly string filePath;
+ private readonly string fileContentType = "foo/bar";
private readonly NancyContext context;
- public GenericFileResponseFixture()
+ public GenericFileResponseFixture(ITestOutputHelper output)
{
- var assemblyPath =
- Path.GetDirectoryName(this.GetType().Assembly.Location);
-
var environment = new DefaultNancyEnvironment();
- environment.StaticContent(safepaths:assemblyPath);
+ environment.StaticContent(safepaths: this.GetLocation());
this.context = new NancyContext { Environment = environment };
- this.imagePath =
- Path.GetFileName(this.GetType().Assembly.Location);
+ this.filePath = this.GetFilePath();
+ }
+
+ private string GetLocation()
+ {
+#if DNX
+ return Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath;
+#else
+ return Path.GetDirectoryName(this.GetType().Assembly.Location);
+#endif
+ }
+
+ private string GetFilePath()
+ {
+#if DNX
+ return Path.Combine("Resources", "test.txt");
+#else
+ return Path.GetFileName(this.GetType().Assembly.Location);
+#endif
}
[Fact]
public void Should_set_status_code_to_not_found_when_file_name_is_empty()
{
// Given, When
- var response = new GenericFileResponse(string.Empty, imageContentType, this.context);
+ var response = new GenericFileResponse(string.Empty, this.fileContentType, this.context);
// Then
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
@@ -42,7 +55,7 @@ public void Should_set_status_code_to_not_found_when_file_name_is_empty()
public void Should_set_status_code_to_not_found_when_file_name_is_null()
{
// Given, When
- var response = new GenericFileResponse(null, imageContentType, this.context);
+ var response = new GenericFileResponse(null, this.fileContentType, this.context);
// Then
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
@@ -52,10 +65,10 @@ public void Should_set_status_code_to_not_found_when_file_name_is_null()
public void Should_set_status_code_to_not_found_when_file_name_does_not_contain_extension()
{
// Given
- var path = Path.Combine("Resources", "zip");
+ var fileNameWithoutExtensions = Path.GetFileNameWithoutExtension(this.filePath);
// When
- var response = new GenericFileResponse(path, imageContentType, this.context);
+ var response = new GenericFileResponse(fileNameWithoutExtensions, this.fileContentType, this.context);
// Then
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
@@ -65,10 +78,8 @@ public void Should_set_status_code_to_not_found_when_file_name_does_not_contain_
public void Should_set_status_code_to_not_found_when_file_does_not_exist()
{
// Given
- var path = Path.Combine("Resources", "thatsnotit.jpg");
-
// When
- var response = new GenericFileResponse(path, imageContentType, this.context);
+ var response = new GenericFileResponse("nancy", this.fileContentType, this.context);
// Then
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
@@ -78,11 +89,11 @@ public void Should_set_status_code_to_not_found_when_file_does_not_exist()
public void Should_set_status_code_to_not_found_when_file_is_above_root_path()
{
// Given
- var path =
- Path.Combine(this.imagePath, "..", "..");
+ var path =
+ Path.Combine(this.filePath, "..", "..");
// When
- var response = new GenericFileResponse(path, imageContentType, this.context);
+ var response = new GenericFileResponse(path, this.fileContentType, this.context);
// Then
response.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
@@ -91,9 +102,10 @@ public void Should_set_status_code_to_not_found_when_file_is_above_root_path()
[Fact]
public void Should_set_status_code_to_ok()
{
- // Given, When
- var response = new GenericFileResponse(this.imagePath, imageContentType, this.context);
-
+ // Given
+ // When
+ var response = new GenericFileResponse(this.filePath, "text/plain", this.context);
+
// Then
response.StatusCode.ShouldEqual(HttpStatusCode.OK);
}
@@ -102,12 +114,13 @@ public void Should_set_status_code_to_ok()
public void Should_return_file_unchanged()
{
// Given
- var expected = File.ReadAllBytes(this.imagePath);
- var response = new GenericFileResponse(this.imagePath, imageContentType, this.context);
-
+ var path = Path.Combine(this.GetLocation(), this.filePath);
+ var expected = File.ReadAllBytes(path);
+ var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context);
+
// When
var result = GetResponseContents(response);
-
+
// Then
result.ShouldEqualSequence(expected);
}
@@ -115,19 +128,20 @@ public void Should_return_file_unchanged()
[Fact]
public void Should_set_filename_property_to_filename()
{
- // Given, When
- var response = new GenericFileResponse(this.imagePath, imageContentType, this.context);
+ // Given
+ // When
+ var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context);
// Then
- response.Filename.ShouldEqual(Path.GetFileName(this.imagePath));
+ response.Filename.ShouldEqual(Path.GetFileName(this.filePath));
}
[Fact]
public void Should_contain_etag_in_response_header()
{
- // Given, when
- var response =
- new GenericFileResponse(this.imagePath, imageContentType, this.context);
+ // Given
+ // When
+ var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context);
// Then
response.Headers["ETag"].ShouldStartWith("\"");
@@ -138,9 +152,9 @@ public void Should_contain_etag_in_response_header()
public void Should_set_content_length_in_response_header()
{
// Given, when
- var expected = new FileInfo(imagePath).Length.ToString();
- var response =
- new GenericFileResponse(this.imagePath, imageContentType, this.context);
+ var path = Path.Combine(this.GetLocation(), this.filePath);
+ var expected = new FileInfo(path).Length.ToString();
+ var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context);
// Then
response.Headers["Content-Length"].ShouldEqual(expected);
@@ -151,7 +165,7 @@ private static IEnumerable<byte> GetResponseContents(Response response)
var ms = new MemoryStream();
response.Contents(ms);
ms.Flush();
-
+
return ms.ToArray();
}
}
View
28 test/Nancy.Tests/project.json
@@ -0,0 +1,28 @@
+{
+ "dependencies": {
+ "FakeItEasy": "2.0.0-beta011",
+ "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final",
+ "Nancy": { "target": "project" },
+ "Nancy.Testing": { "target": "project" },
+ "xunit": "2.1.0",
+ "xunit.runner.dnx": "2.1.0-*"
+ },
+
+ "commands": {
+ "test": "xunit.runner.dnx"
+ },
+
+ "compilationOptions": {
+ "define": [ "DNX" ]
+ },
+
+ "resource": "Resources/views/staticviewresource.html",
+
+ "frameworks": {
+ "dnx451": {
+ "frameworkAssemblies": {
+ "System.Web": ""
+ }
+ }
+ }
+}

0 comments on commit 48cf110

Please sign in to comment.
Something went wrong with that request. Please try again.