Browse files

Build with dotnet (#571).

  • Loading branch information...
1 parent 1209eca commit 6757a31fd2ae035e2d2ff7e1f586b8f1498d3b60 @cesarbs cesarbs committed Jan 13, 2016
Showing with 328 additions and 731 deletions.
  1. +2 −0 .gitattributes
  2. +3 −1 .gitignore
  3. +2 −1 .travis.yml
  4. +1 −8 KestrelHttpServer.sln
  5. +3 −1 appveyor.yml
  6. +32 −32 build.cmd
  7. +21 −19 build.sh
  8. +8 −1 makefile.shade
  9. +2 −0 samples/LargeResponseApp/Startup.cs
  10. +6 −4 samples/LargeResponseApp/project.json
  11. +1 −0 samples/SampleApp/Startup.cs
  12. +3 −5 samples/SampleApp/project.json
  13. +2 −1 src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json
  14. +10 −19 src/Microsoft.AspNetCore.Server.Kestrel/project.json
  15. +12 −9 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs
  16. +32 −31 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs
  17. +17 −0 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs
  18. +16 −12 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs
  19. +9 −6 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs
  20. +3 −2 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs
  21. +15 −4 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json
  22. +6 −6 test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs
  23. +3 −3 test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs
  24. +35 −33 test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs
  25. +6 −7 test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs
  26. +12 −9 test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs
  27. +0 −37 test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs
  28. +4 −4 test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs
  29. +15 −4 test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs
  30. +18 −8 test/Microsoft.AspNetCore.Server.KestrelTests/project.json
  31. +1 −12 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs
  32. +2 −10 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs
  33. +1 −1 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs
  34. +8 −12 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json
  35. +10 −5 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs
  36. +7 −19 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json
  37. +0 −20 tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj
  38. +0 −49 tools/Microsoft.StandardsPolice/Program.cs
  39. +0 −292 tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs
  40. +0 −44 tools/Microsoft.StandardsPolice/project.json
View
2 .gitattributes
@@ -48,3 +48,5 @@
*.fsproj text=auto
*.dbproj text=auto
*.sln text=auto eol=crlf
+
+*.sh eol=lf
View
4 .gitignore
@@ -26,4 +26,6 @@ nuget.exe
*.*sdf
*.ipch
project.lock.json
-runtimes/
+runtimes/
+.build/
+.testPublish/
View
3 .travis.yml
@@ -11,7 +11,7 @@ addons:
- libunwind8
- zlib1g
env:
- - KOREBUILD_DNU_RESTORE_CORECLR=true KOREBUILD_TEST_DNXCORE=true
+ - KOREBUILD_TEST_SKIPMONO=true
install:
- curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | tar zxfv - -C /tmp && cd /tmp/libuv-1.4.2/
- sh autogen.sh
@@ -22,5 +22,6 @@ install:
- cd $OLDPWD
mono:
- 4.0.5
+osx_image: xcode7.1
script:
- ./build.sh --quiet verify
View
9 KestrelHttpServer.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
-VisualStudioVersion = 14.0.23107.0
+VisualStudioVersion = 14.0.24709.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}"
EndProject
@@ -29,8 +29,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}"
EndProject
-Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.StandardsPolice", "tools\Microsoft.StandardsPolice\Microsoft.StandardsPolice.xproj", "{82295647-7C1C-4671-BAB6-0FEF58F949EC}"
-EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier", "tools\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj", "{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}"
@@ -63,10 +61,6 @@ Global
{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU
- {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.Build.0 = Release|Any CPU
{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -89,7 +83,6 @@ Global
{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}
{B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}
{BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD}
- {82295647-7C1C-4671-BAB6-0FEF58F949EC} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD}
{8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD}
{5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750}
{9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483}
View
4 appveyor.yml
@@ -4,4 +4,6 @@ build_script:
- build.cmd --quiet verify
clone_depth: 1
test: off
-deploy: off
+deploy: off
+environment:
+ NO_PARALLEL_TEST_PROJECTS: Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
View
64 build.cmd
@@ -1,40 +1,40 @@
-@echo off
-cd %~dp0
-
+@ECHO off
SETLOCAL
+
+SET REPO_FOLDER=%~dp0
+CD %REPO_FOLDER%
+
+SET BUILD_FOLDER=.build
+SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet
+SET KOREBUILD_VERSION=
+
+SET NUGET_PATH=%BUILD_FOLDER%\NuGet.exe
SET NUGET_VERSION=latest
SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe
-SET BUILDCMD_KOREBUILD_VERSION=
-SET BUILDCMD_DNX_VERSION=
-
-IF EXIST %CACHED_NUGET% goto copynuget
-echo Downloading latest version of NuGet.exe...
-IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
-@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'"
-
-:copynuget
-IF EXIST .nuget\nuget.exe goto restore
-md .nuget
-copy %CACHED_NUGET% .nuget\nuget.exe > nul
-
-:restore
-IF EXIST packages\Sake goto getdnx
-IF "%BUILDCMD_KOREBUILD_VERSION%"=="" (
- .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
-) ELSE (
- .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre
+
+IF NOT EXIST %BUILD_FOLDER% (
+ md %BUILD_FOLDER%
)
-.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages
-:getdnx
-IF "%BUILDCMD_DNX_VERSION%"=="" (
- SET BUILDCMD_DNX_VERSION=latest
+IF NOT EXIST %NUGET_PATH% (
+ IF NOT EXIST %CACHED_NUGET% (
+ echo Downloading latest version of NuGet.exe...
+ IF NOT EXIST %LocalAppData%\NuGet (
+ md %LocalAppData%\NuGet
+ )
+ @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'"
+ )
+
+ copy %CACHED_NUGET% %NUGET_PATH% > nul
)
-IF "%SKIP_DNX_INSTALL%"=="" (
- CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default
- CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default
-) ELSE (
- CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86
+
+IF NOT EXIST %KOREBUILD_FOLDER% (
+ SET KOREBUILD_DOWNLOAD_ARGS=
+ IF NOT "%KOREBUILD_VERSION%"=="" (
+ SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION%
+ )
+
+ %BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS%
)
-packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*
+"%KOREBUILD_FOLDER%\build\KoreBuild.cmd" %*
View
40 build.sh
@@ -1,5 +1,10 @@
#!/usr/bin/env bash
+buildFolder=.build
+koreBuildFolder=$buildFolder/KoreBuild-dotnet
+
+nugetPath=$buildFolder/nuget.exe
+
if test `uname` = Darwin; then
cachedir=~/Library/Caches/KBuild
else
@@ -11,33 +16,30 @@ else
fi
mkdir -p $cachedir
nugetVersion=latest
-cachePath=$cachedir/nuget.$nugetVersion.exe
+cacheNuget=$cachedir/nuget.$nugetVersion.exe
-url=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe
+nugetUrl=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe
-if test ! -f $cachePath; then
- wget -O $cachePath $url 2>/dev/null || curl -o $cachePath --location $url /dev/null
+if test ! -d $buildFolder; then
+ mkdir $buildFolder
fi
-if test ! -e .nuget; then
- mkdir .nuget
- cp $cachePath .nuget/nuget.exe
-fi
+if test ! -f $nugetPath; then
+ if test ! -f $cacheNuget; then
+ wget -O $cacheNuget $nugetUrl 2>/dev/null || curl -o $cacheNuget --location $nugetUrl /dev/null
+ fi
-if test ! -d packages/Sake; then
- mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
- mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages
+ cp $cacheNuget $nugetPath
fi
-if ! type dnvm > /dev/null 2>&1; then
- source packages/KoreBuild/build/dnvm.sh
+if test ! -d $koreBuildFolder; then
+ mono $nugetPath install KoreBuild-dotnet -ExcludeVersion -o $buildFolder -nocache -pre
+ chmod +x $koreBuildFolder/build/KoreBuild.sh
fi
-if ! type dnx > /dev/null 2>&1 || [ -z "$SKIP_DNX_INSTALL" ]; then
- dnvm install latest -runtime coreclr -alias default
- dnvm install default -runtime mono -alias default
-else
- dnvm use default -runtime mono
+makeFile=makefile.shade
+if [ ! -e $makeFile ]; then
+ makeFile=$koreBuildFolder/build/makefile.shade
fi
-mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"
+./$koreBuildFolder/build/KoreBuild.sh -n $nugetPath -m $makeFile "$@"
View
9 makefile.shade
@@ -1,8 +1,15 @@
-
var VERSION='0.1'
var FULL_VERSION='0.1'
var AUTHORS='Microsoft'
+var kestrelSrcDir='${Path.Combine(Directory.GetCurrentDirectory(), "src/Microsoft.AspNetCore.Server.Kestrel")}'
use-standard-lifecycle
k-standard-goals
custom-goals
+
+exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode' workingdir='${kestrelSrcDir}'
+exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}'
+
+exec program='dotnet' commandline='restore' workingdir='${kestrelSrcDir}'
+exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}'
+exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}'
View
2 samples/LargeResponseApp/Startup.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
@@ -40,6 +41,7 @@ public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseDefaultConfiguration(args)
+ .UseApplicationBasePath(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
View
10 samples/LargeResponseApp/project.json
@@ -8,9 +8,11 @@
},
"frameworks": {
"dnx451": { },
- "dnxcore50": { }
+ "dnxcore50": {
+ "dependencies": {
+ "NETStandard.Library": "1.0.0-*"
+ }
+ }
},
- "commands": {
- "web": "LargeResponseApp"
- }
+ "content": [ "hosting.json" ]
}
View
1 samples/SampleApp/Startup.cs
@@ -65,6 +65,7 @@ public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseDefaultConfiguration(args)
+ .UseApplicationBasePath(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
View
8 samples/SampleApp/project.json
@@ -9,15 +9,13 @@
"emitEntryPoint": true
},
"frameworks": {
- "dnx451": {
- },
+ "dnx451": { },
"dnxcore50": {
"dependencies": {
+ "NETStandard.Library": "1.0.0-*",
"System.Console": "4.0.0-*"
}
}
},
- "commands": {
- "web": "SampleApp"
- }
+ "content": [ "hosting.json" ]
}
View
3 src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json
@@ -16,7 +16,8 @@
"dotnet5.4": {
"dependencies": {
"System.Net.Security": "4.0.0-*"
- }
+ },
+ "imports": "portable-net45+win8"
}
}
}
View
29 src/Microsoft.AspNetCore.Server.Kestrel/project.json
@@ -7,26 +7,26 @@
},
"dependencies": {
"System.Buffers": "4.0.0-*",
+ "System.Numerics.Vectors": "4.1.1-*",
+ "System.Threading.Tasks.Extensions": "4.0.0-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
- "System.Numerics.Vectors": "4.1.1-*",
- "Microsoft.StandardsPolice": {
- "version": "1.0.0-*",
- "type": "build"
- },
"Microsoft.AspNetCore.Internal.libuv-Darwin": {
"version": "1.0.0-*",
"type": "build"
},
"Microsoft.AspNetCore.Internal.libuv-Windows": {
"version": "1.0.0-*",
"type": "build"
- },
- "System.Threading.Tasks.Extensions": "4.0.0-*"
+ }
},
"frameworks": {
- "net451": { },
+ "net451": {
+ "frameworkAssemblies": {
+ "System.Threading.Tasks": ""
+ }
+ },
"dotnet5.4": {
"dependencies": {
"System.Collections": "4.0.11-*",
@@ -45,23 +45,14 @@
"System.Threading.Thread": "4.0.0-*",
"System.Threading.ThreadPool": "4.0.10-*",
"System.Threading.Timer": "4.0.1-*"
- }
+ },
+ "imports": "portable-net45+win8"
}
},
"compilationOptions": {
"allowUnsafe": true,
"keyFile": "../../tools/Key.snk"
},
- "scripts": {
- "prepare": [
- "dnu restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode",
- "dnx -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs"
- ],
- "postrestore": [
- "dnu restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier",
- "dnx -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier run"
- ]
- },
"packInclude": {
"/": "../../content/thirdpartynotices.txt",
"runtimes/win7-x64/native/": "runtimes/win7-x64/native/*",
View
21 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs
@@ -64,11 +64,13 @@ public class AddressRegistrationTests
{
get
{
+ var port1 = PortManager.GetPort();
+ var port2 = PortManager.GetPort();
var dataset = new TheoryData<string, string[]>();
- dataset.Add("8787", new[] { "http://localhost:8787/" });
- dataset.Add("8787;8788", new[] { "http://localhost:8787/", "http://localhost:8788/" });
- dataset.Add("http://127.0.0.1:8787/", new[] { "http://127.0.0.1:8787/", });
- dataset.Add("http://localhost:8787/base/path", new[] { "http://localhost:8787/base/path" });
+ dataset.Add($"{port1}", new[] { $"http://localhost:{port1}/" });
+ dataset.Add($"{port1};{port2}", new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" });
+ dataset.Add($"http://127.0.0.1:{port1}/", new[] { $"http://127.0.0.1:{port1}/", });
+ dataset.Add($"http://localhost:{port1}/base/path", new[] { $"http://localhost:{port1}/base/path" });
return dataset;
}
@@ -78,14 +80,15 @@ public class AddressRegistrationTests
{
get
{
+ var port = PortManager.GetPort();
var dataset = new TheoryData<string, string[]>();
- dataset.Add("http://*:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/", "http://[::1]:8787/" });
- dataset.Add("http://localhost:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/",
+ dataset.Add($"http://*:{port}/", new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" });
+ dataset.Add($"http://localhost:{port}/", new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/",
/* // https://github.com/aspnet/KestrelHttpServer/issues/231
- "http://[::1]:8787/"
+ $"http://[::1]:{port}/"
*/ });
- dataset.Add("http://[::1]:8787/", new[] { "http://[::1]:8787/", });
- dataset.Add("http://127.0.0.1:8787/;http://[::1]:8787/", new[] { "http://127.0.0.1:8787/", "http://[::1]:8787/" });
+ dataset.Add($"http://[::1]:{port}/", new[] { $"http://[::1]:{port}/", });
+ dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" });
return dataset;
}
View
63 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs
@@ -18,65 +18,66 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
public class PathBaseTests
{
[ConditionalTheory]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/base", "/base", "")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/base/something", "/base", "/something")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/base/something/", "/base", "/something/")]
- [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more", "/base/more", "")]
- [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something", "/base/more", "/something")]
- [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something/", "/base/more", "/something/")]
+ [InlineData("/base", "/base", "/base", "")]
+ [InlineData("/base", "/base/", "/base", "/")]
+ [InlineData("/base", "/base/something", "/base", "/something")]
+ [InlineData("/base", "/base/something/", "/base", "/something/")]
+ [InlineData("/base/more", "/base/more", "/base/more", "")]
+ [InlineData("/base/more", "/base/more/something", "/base/more", "/something")]
+ [InlineData("/base/more", "/base/more/something/", "/base/more", "/something/")]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
- public Task RequestPathBaseIsServerPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath)
+ public Task RequestPathBaseIsServerPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath)
{
- return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath);
+ return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath);
}
[ConditionalTheory]
- [InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")]
- [InlineData("http://localhost:8791", "http://localhost:8791/something", "", "/something")]
- [InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/", "", "/")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/something", "", "/something")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/baseandsomething", "", "/baseandsomething")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/ba", "", "/ba")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/ba/se", "", "/ba/se")]
+ [InlineData("", "/", "", "/")]
+ [InlineData("", "/something", "", "/something")]
+ [InlineData("/", "/", "", "/")]
+ [InlineData("/base", "/", "", "/")]
+ [InlineData("/base", "/something", "", "/something")]
+ [InlineData("/base", "/baseandsomething", "", "/baseandsomething")]
+ [InlineData("/base", "/ba", "", "/ba")]
+ [InlineData("/base", "/ba/se", "", "/ba/se")]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
- public Task DefaultPathBaseIsEmpty(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath)
+ public Task DefaultPathBaseIsEmpty(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath)
{
- return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath);
+ return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath);
}
[ConditionalTheory]
- [InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")]
- [InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")]
- [InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")]
- [InlineData("http://localhost:8791/base/", "http://localhost:8791/base", "/base", "")]
- [InlineData("http://localhost:8791/base/", "http://localhost:8791/base/", "/base", "/")]
+ [InlineData("", "/", "", "/")]
+ [InlineData("/", "/", "", "/")]
+ [InlineData("/base", "/base/", "/base", "/")]
+ [InlineData("/base/", "/base", "/base", "")]
+ [InlineData("/base/", "/base/", "/base", "/")]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
- public Task PathBaseNeverEndsWithSlash(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath)
+ public Task PathBaseNeverEndsWithSlash(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath)
{
- return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath);
+ return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath);
}
[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
public Task PathBaseAndPathPreserveRequestCasing()
{
- return TestPathBase("http://localhost:8791/base", "http://localhost:8791/Base/Something", "/Base", "/Something");
+ return TestPathBase("/base", "/Base/Something", "/Base", "/Something");
}
[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
public Task PathBaseCanHaveUTF8Characters()
{
- return TestPathBase("http://localhost:8791/b♫se", "http://localhost:8791/b♫se/something", "/b♫se", "/something");
+ return TestPathBase("/b♫se", "/b♫se/something", "/b♫se", "/something");
}
- private async Task TestPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath)
+ private async Task TestPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath)
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder().AddInMemoryCollection(
new Dictionary<string, string> {
- { "server.urls", registerAddress }
+ { "server.urls", $"http://localhost:{port}{registerPathBase}" }
}).Build();
var builder = new WebHostBuilder()
@@ -100,7 +101,7 @@ public Task PathBaseCanHaveUTF8Characters()
using (var client = new HttpClient())
{
- var response = await client.GetAsync(requestAddress);
+ var response = await client.GetAsync($"http://localhost:{port}{requestPath}");
response.EnsureSuccessStatusCode();
var responseText = await response.Content.ReadAsStringAsync();
View
17 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs
@@ -0,0 +1,17 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.Threading;
+
+namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
+{
+ public static class PortManager
+ {
+ private static int _nextPort = 8001;
+
+ public static int GetPort()
+ {
+ return Interlocked.Increment(ref _nextPort);
+ }
+ }
+}
View
28 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs
@@ -25,10 +25,11 @@ public class RequestTests
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
public async Task LargeUpload()
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
- { "server.urls", "http://localhost:8791/" }
+ { "server.urls", $"http://localhost:{port}/" }
})
.Build();
@@ -69,7 +70,7 @@ public class RequestTests
bytes[i] = (byte)i;
}
- var response = await client.PostAsync("http://localhost:8791/", new ByteArrayContent(bytes));
+ var response = await client.PostAsync($"http://localhost:{port}/", new ByteArrayContent(bytes));
response.EnsureSuccessStatusCode();
var sizeString = await response.Content.ReadAsStringAsync();
Assert.Equal(sizeString, bytes.Length.ToString(CultureInfo.InvariantCulture));
@@ -78,29 +79,30 @@ public class RequestTests
}
[ConditionalTheory]
- [InlineData("127.0.0.1", "127.0.0.1", "8792")]
- [InlineData("localhost", "127.0.0.1", "8792")]
+ [InlineData("127.0.0.1", "127.0.0.1")]
+ [InlineData("localhost", "127.0.0.1")]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
- public Task RemoteIPv4Address(string requestAddress, string expectAddress, string port)
+ public Task RemoteIPv4Address(string requestAddress, string expectAddress)
{
- return TestRemoteIPAddress("localhost", requestAddress, expectAddress, port);
+ return TestRemoteIPAddress("localhost", requestAddress, expectAddress);
}
[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
[IPv6SupportedCondition]
public Task RemoteIPv6Address()
{
- return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8793");
+ return TestRemoteIPAddress("[::1]", "[::1]", "::1");
}
[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
public async Task DoesNotHangOnConnectionCloseRequest()
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder().AddInMemoryCollection(
new Dictionary<string, string> {
- { "server.urls", "http://localhost:8794" }
+ { "server.urls", $"http://localhost:{port}" }
}).Build();
var builder = new WebHostBuilder()
@@ -123,7 +125,7 @@ public Task RemoteIPv6Address()
client.DefaultRequestHeaders.Connection.Clear();
client.DefaultRequestHeaders.Connection.Add("close");
- var response = await client.GetAsync("http://localhost:8794/");
+ var response = await client.GetAsync($"http://localhost:{port}/");
response.EnsureSuccessStatusCode();
}
}
@@ -132,9 +134,10 @@ public Task RemoteIPv6Address()
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
public async Task RequestPathIsNormalized()
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder().AddInMemoryCollection(
new Dictionary<string, string> {
- { "server.urls", "http://localhost:8795/\u0041\u030A" }
+ { "server.urls", $"http://localhost:{port}/\u0041\u030A" }
}).Build();
var builder = new WebHostBuilder()
@@ -157,7 +160,7 @@ public Task RemoteIPv6Address()
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
- socket.Connect(new IPEndPoint(IPAddress.Loopback, 8795));
+ socket.Connect(new IPEndPoint(IPAddress.Loopback, port));
socket.Send(Encoding.ASCII.GetBytes("GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1\r\n\r\n"));
socket.Shutdown(SocketShutdown.Send);
@@ -179,8 +182,9 @@ public Task RemoteIPv6Address()
}
}
- private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress, string port)
+ private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress)
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder().AddInMemoryCollection(
new Dictionary<string, string> {
{ "server.urls", $"http://{registerAddress}:{port}" }
View
15 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs
@@ -23,10 +23,11 @@ public class ResponseTests
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")]
public async Task LargeDownload()
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
- { "server.urls", "http://localhost:8792/" }
+ { "server.urls", $"http://localhost:{port}/" }
})
.Build();
@@ -58,7 +59,7 @@ public class ResponseTests
using (var client = new HttpClient())
{
- var response = await client.GetAsync("http://localhost:8792/");
+ var response = await client.GetAsync($"http://localhost:{port}/");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStreamAsync();
@@ -83,10 +84,11 @@ public class ResponseTests
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")]
public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue)
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
- { "server.urls", "http://localhost:8793/" }
+ { "server.urls", $"http://localhost:{port}/" }
})
.Build();
@@ -109,7 +111,7 @@ public class ResponseTests
using (var client = new HttpClient())
{
- var response = await client.GetAsync("http://localhost:8793/");
+ var response = await client.GetAsync($"http://localhost:{port}/");
response.EnsureSuccessStatusCode();
var headers = response.Headers;
@@ -131,10 +133,11 @@ public class ResponseTests
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")]
public async Task OnCompleteCalledEvenWhenOnStartingNotCalled()
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
- { "server.urls", "http://localhost:8794/" }
+ { "server.urls", $"http://localhost:{port}/" }
})
.Build();
@@ -162,7 +165,7 @@ public class ResponseTests
using (var client = new HttpClient())
{
- var response = await client.GetAsync("http://localhost:8794/");
+ var response = await client.GetAsync($"http://localhost:{port}/");
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
Assert.False(onStartingCalled);
View
5 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs
@@ -16,10 +16,11 @@ public class ThreadCountTests
{
public async Task ZeroToTenThreads(int threadCount)
{
+ var port = PortManager.GetPort();
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
- { "server.urls", "http://localhost:8790/" }
+ { "server.urls", $"http://localhost:{port}/" }
})
.Build();
@@ -46,7 +47,7 @@ public class ThreadCountTests
var requestTasks = new List<Task<string>>();
for (int i = 0; i < 20; i++)
{
- var requestTask = client.GetStringAsync("http://localhost:8790/");
+ var requestTask = client.GetStringAsync($"http://localhost:{port}/");
requestTasks.Add(requestTask);
}
View
19 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json
@@ -4,17 +4,28 @@
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNetCore.Testing": "1.0.0-*",
+ "Microsoft.NETCore.Platforms": "1.0.1-*",
"System.Net.Http": "4.0.1-*",
- "xunit.runner.aspnet": "2.0.0-aspnet-*"
+ "xunit": "2.1.0"
},
"frameworks": {
- "dnx451": { },
- "dnxcore50": { }
+ "dnx451": {
+ "dependencies": {
+ "xunit.runner.console": "2.1.0"
+ }
+ },
+ "dnxcore50": {
+ "dependencies": {
+ "xunit.runner.aspnet": "2.0.0-aspnet-*"
+ },
+ "imports": "portable-net45+win8"
+ }
},
"compilationOptions": {
"allowUnsafe": true
},
+ "testRunner": "xunit",
"commands": {
- "test": "xunit.runner.aspnet -parallel none"
+ "test": "xunit.runner.aspnet"
}
}
View
12 test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs
@@ -24,7 +24,7 @@ public class ChunkedResponseTests
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6);
}))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -58,7 +58,7 @@ public class ChunkedResponseTests
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6);
}))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -90,7 +90,7 @@ public class ChunkedResponseTests
await response.Body.WriteAsync(new byte[0], 0, 0);
}))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -119,7 +119,7 @@ public class ChunkedResponseTests
throw new Exception();
}))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
// SendEnd is not called, so it isn't the client closing the connection.
// client closing the connection.
@@ -150,7 +150,7 @@ public class ChunkedResponseTests
throw new Exception();
}))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
// SendEnd is not called, so it isn't the client closing the connection.
await connection.Send(
@@ -186,7 +186,7 @@ public class ChunkedResponseTests
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6);
}))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
View
6 test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs
@@ -44,7 +44,7 @@ public class ConnectionFilterTests
using (var server = new TestServer(App, serviceContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
// "?" changes to "!"
await connection.SendEnd(sendString);
@@ -69,7 +69,7 @@ public class ConnectionFilterTests
using (var server = new TestServer(App, serviceContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"POST / HTTP/1.0",
@@ -94,7 +94,7 @@ public class ConnectionFilterTests
using (var server = new TestServer(App, serviceContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
try
{
View
68 test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs
@@ -98,7 +98,7 @@ public void ListenerCanCreateAndDispose(TestServiceContext testContext)
testContext.App = App;
var engine = new KestrelEngine(testContext);
engine.Start(1);
- var address = ServerAddress.FromUrl("http://localhost:54321/");
+ var address = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}/");
var started = engine.CreateServer(address);
started.Dispose();
engine.Dispose();
@@ -109,15 +109,16 @@ public void ListenerCanCreateAndDispose(TestServiceContext testContext)
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")]
public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
+ var port = TestServer.GetNextPort();
testContext.App = App;
var engine = new KestrelEngine(testContext);
engine.Start(1);
- var address = ServerAddress.FromUrl("http://localhost:54321/");
+ var address = ServerAddress.FromUrl($"http://localhost:{port}/");
var started = engine.CreateServer(address);
Console.WriteLine("Started");
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- socket.Connect(new IPEndPoint(IPAddress.Loopback, 54321));
+ socket.Connect(new IPEndPoint(IPAddress.Loopback, port));
socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World"));
socket.Shutdown(SocketShutdown.Send);
var buffer = new byte[8192];
@@ -139,7 +140,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(App, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"POST / HTTP/1.0",
@@ -161,7 +162,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(AppChunked, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -207,7 +208,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
var requestData =
Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount)
@@ -250,7 +251,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
var requestData =
Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount)
@@ -276,7 +277,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(App, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.Send(
"POST / HTTP/1.0",
@@ -298,7 +299,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(App, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.Send(
"POST / HTTP/1.0",
@@ -320,7 +321,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(AppChunked, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.0",
@@ -350,7 +351,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(App, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.0",
@@ -381,7 +382,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(AppChunked, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"POST / HTTP/1.0",
@@ -413,7 +414,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(AppChunked, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"POST / HTTP/1.0",
@@ -446,7 +447,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(AppChunked, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.Send(
"POST / HTTP/1.1",
@@ -474,11 +475,12 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
using (var server = new TestServer(App, testContext))
{
var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
- socket.Connect(IPAddress.Loopback, 54321);
+ socket.Connect(IPAddress.Loopback, server.Port);
+ await Task.Delay(200);
socket.Dispose();
await Task.Delay(200);
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.0",
@@ -497,7 +499,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(EmptyApp, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -526,7 +528,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(EmptyApp, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -540,7 +542,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
"");
}
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.0",
@@ -561,7 +563,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(EmptyApp, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"HEAD / HTTP/1.1",
@@ -593,7 +595,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
}
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"POST / HTTP/1.1",
@@ -654,7 +656,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
throw new Exception();
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -713,7 +715,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
throw new Exception();
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.Send(
"GET / HTTP/1.1",
@@ -756,7 +758,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
throw new Exception();
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.Send(
"GET / HTTP/1.1",
@@ -781,7 +783,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(AppChunked, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -809,14 +811,14 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
{
using (var server = new TestServer(AppChunked, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET /");
await connection.ReceiveEnd();
}
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -829,7 +831,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
"");
}
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -884,7 +886,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
failedWriteCount++;
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"GET / HTTP/1.1",
@@ -950,7 +952,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.Send(
"GET / HTTP/1.1",
@@ -988,7 +990,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.SendEnd(
"POST / HTTP/1.1",
@@ -1063,7 +1065,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
}
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
// Never send the body so CopyToAsync always fails.
await connection.Send(
@@ -1134,7 +1136,7 @@ public void ConnectionCanReadAndWrite(TestServiceContext testContext)
writeTcs.SetException(new Exception("This shouldn't be reached."));
}, testContext))
{
- using (var connection = new TestConnection())
+ using (var connection = new TestConnection(server.Port))
{
await connection.Send(
"POST / HTTP/1.1",
View
13 test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs
@@ -58,8 +58,7 @@ public class HttpsConnectionFilterTests
var handler = new WinHttpHandler();
handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
#endif
-
- var serverAddress = "https://localhost:54321/";
+ var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/";
var serviceContext = new TestServiceContext()
{
ConnectionFilter = new HttpsConnectionFilter(
@@ -108,7 +107,7 @@ public class HttpsConnectionFilterTests
handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
#endif
- var serverAddress = "https://localhost:54321/";
+ var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/";
var serviceContext = new TestServiceContext()
{
ConnectionFilter = new HttpsConnectionFilter(
@@ -157,7 +156,7 @@ public class HttpsConnectionFilterTests
handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
#endif
- var serverAddress = "https://localhost:54321/";
+ var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/";
var serviceContext = new TestServiceContext()
{
ConnectionFilter = new HttpsConnectionFilter(
@@ -209,7 +208,7 @@ public class HttpsConnectionFilterTests
ServicePointManager.ServerCertificateValidationCallback += validationCallback;
#endif
- var serverAddress = "https://localhost:54321/";
+ var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/";
var serviceContext = new TestServiceContext()
{
ConnectionFilter = new HttpsConnectionFilter(
@@ -238,7 +237,7 @@ public class HttpsConnectionFilterTests
// of the certificate authorities sent by the server in the SSL handshake.
using (var client = new TcpClient())
{
- await client.ConnectAsync("127.0.0.1", 54321);
+ await client.ConnectAsync("127.0.0.1", server.Port);
SslStream stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true,
(sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"));
@@ -281,7 +280,7 @@ public class HttpsConnectionFilterTests
handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
#endif
- var serverAddress = "https://localhost:54321/";
+ var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/";
var serviceContext = new TestServiceContext()
{
ConnectionFilter = new HttpsConnectionFilter(
View
21 test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs
@@ -76,7 +76,8 @@ public void SocketCanBeInitAndClose()
loop.Init(_uv);
var tcp = new UvTcpHandle(_logger);
tcp.Init(loop);
- var address = ServerAddress.FromUrl("http://localhost:54321/");
+ var port = TestServer.GetNextPort();
+ var address = ServerAddress.FromUrl($"http://localhost:{port}/");
tcp.Bind(address);
tcp.Listen(10, (stream, status, error, state) =>
{
@@ -96,11 +97,11 @@ public void SocketCanBeInitAndClose()
await Task.Factory.FromAsync(
socket.BeginConnect,
socket.EndConnect,
- new IPEndPoint(IPAddress.Loopback, 54321),
+ new IPEndPoint(IPAddress.Loopback, port),
null,
TaskCreationOptions.None);
#else
- await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321));
+ await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port));
#endif
socket.Dispose();
});
@@ -117,7 +118,8 @@ public void SocketCanBeInitAndClose()
loop.Init(_uv);
var tcp = new UvTcpHandle(_logger);
tcp.Init(loop);
- var address = ServerAddress.FromUrl("http://localhost:54321/");
+ var port = TestServer.GetNextPort();
+ var address = ServerAddress.FromUrl($"http://localhost:{port}/");
tcp.Bind(address);
tcp.Listen(10, (_, status, error, state) =>
{
@@ -149,7 +151,7 @@ public void SocketCanBeInitAndClose()
await Task.Factory.FromAsync(
socket.BeginConnect,
socket.EndConnect,
- new IPEndPoint(IPAddress.Loopback, 54321),
+ new IPEndPoint(IPAddress.Loopback, port),
null,
TaskCreationOptions.None);
await Task.Factory.FromAsync(
@@ -160,7 +162,7 @@ public void SocketCanBeInitAndClose()
null,
TaskCreationOptions.None);
#else
- await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321));
+ await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port));
await socket.SendAsync(new[] { new ArraySegment<byte>(new byte[] { 1, 2, 3, 4, 5 }) },
SocketFlags.None);
#endif
@@ -178,7 +180,8 @@ public void SocketCanBeInitAndClose()
loop.Init(_uv);
var tcp = new UvTcpHandle(_logger);
tcp.Init(loop);
- var address = ServerAddress.FromUrl("http://localhost:54321/");
+ var port = TestServer.GetNextPort();
+ var address = ServerAddress.FromUrl($"http://localhost:{port}/");
tcp.Bind(address);
tcp.Listen(10, (_, status, error, state) =>
{
@@ -235,7 +238,7 @@ public void SocketCanBeInitAndClose()
await Task.Factory.FromAsync(
socket.BeginConnect,
socket.EndConnect,
- new IPEndPoint(IPAddress.Loopback, 54321),
+ new IPEndPoint(IPAddress.Loopback, port),
null,
TaskCreationOptions.None);
await Task.Factory.FromAsync(
@@ -246,7 +249,7 @@ public void SocketCanBeInitAndClose()
null,
TaskCreationOptions.None);
#else
- await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321));
+ await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port));
await socket.SendAsync(new[] { new ArraySegment<byte>(new byte[] { 1, 2, 3, 4, 5 }) },
SocketFlags.None);
#endif
View
37 test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs
@@ -1,37 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using Microsoft.Extensions.PlatformAbstractions;
-
-namespace Microsoft.AspNetCore.Server.KestrelTests
-{
- /// <summary>
- /// Summary description for Program
- /// </summary>
- public class Program
- {
- private readonly IApplicationEnvironment env;
- private readonly IServiceProvider sp;
- private readonly ILibraryManager _libraryManager;
-
- public Program(
- IApplicationEnvironment env,
- IServiceProvider sp,
- ILibraryManager libraryManager)
- {
- this.env = env;
- this.sp = sp;
- _libraryManager = libraryManager;
- }
-
- public int Main()
- {
- return Xunit.Runner.Dnx.Program.Main(new string[]
- {
- "-class",
- typeof(MultipleLoopTests).FullName
- });
- }
- }
-}
View
8 test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs
@@ -21,15 +21,15 @@ public class TestConnection : IDisposable
private NetworkStream _stream;
private StreamReader _reader;
- public TestConnection()
+ public TestConnection(int port)
{
- Create();
+ Create(port);
}
- public void Create()
+ public void Create(int port)
{
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- _socket.Connect(new IPEndPoint(IPAddress.Loopback, 54321));
+ _socket.Connect(new IPEndPoint(IPAddress.Loopback, port));
_stream = new NetworkStream(_socket, false);
_reader = new StreamReader(_stream, Encoding.ASCII);
View
19 test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.Threading;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Http;
@@ -13,24 +14,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
/// </summary>
public class TestServer : IDisposable
{
+ private static int _nextPort = 9001;
+
private KestrelEngine _engine;
private IDisposable _server;
+ ServerAddress _address;
public TestServer(RequestDelegate app)
: this(app, new TestServiceContext())
{
}
public TestServer(RequestDelegate app, ServiceContext context)
- : this(app, context, "http://localhost:54321/")
+ : this(app, context, $"http://localhost:{GetNextPort()}/")
{
}
+
+ public int Port => _address.Port;
+
public TestServer(RequestDelegate app, ServiceContext context, string serverAddress)
{
Create(app, context, serverAddress);
}
-
public void Create(RequestDelegate app, ServiceContext context, string serverAddress)
{
context.FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) =>
@@ -39,14 +45,19 @@ public void Create(RequestDelegate app, ServiceContext context, string serverAdd
};
_engine = new KestrelEngine(context);
_engine.Start(1);
- _server = _engine.CreateServer(
- ServerAddress.FromUrl(serverAddress));
+ _address = ServerAddress.FromUrl(serverAddress);
+ _server = _engine.CreateServer(_address);
}
public void Dispose()
{
_server.Dispose();
_engine.Dispose();
}
+
+ public static int GetNextPort()
+ {
+ return Interlocked.Increment(ref _nextPort);
+ }
}
}
View
26 test/Microsoft.AspNetCore.Server.KestrelTests/project.json
@@ -1,31 +1,41 @@
{
"version": "1.0.0-*",
"dependencies": {
- "xunit.runner.aspnet": "2.0.0-aspnet-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*",
"Microsoft.AspNetCore.Testing": "1.0.0-*",
- "System.Net.Http": "4.0.1-*"
+ "Microsoft.NETCore.Platforms": "1.0.1-*",
+ "System.Net.Http": "4.0.1-*",
+ "xunit": "2.1.0"
},
"frameworks": {
- "dnx451": { },
+ "dnx451": {
+ "dependencies": {
+ "xunit.runner.console": "2.1.0"
+ }
+ },
"dnxcore50": {
"dependencies": {
"System.Diagnostics.TraceSource": "4.0.0-*",
"System.Globalization.Extensions": "4.0.1-*",
"System.IO": "4.1.0-*",
"System.Net.Http.WinHttpHandler": "4.0.0-*",
"System.Net.Sockets": "4.1.0-*",
- "System.Runtime.Handles": "4.0.1-*"
- }
+ "System.Runtime.Handles": "4.0.1-*",
+ "xunit.runner.aspnet": "2.0.0-aspnet-*"
+ },
+ "imports": "portable-net45+win8"
}
},
"compilationOptions": {
"allowUnsafe": true,
"keyFile": "../../tools/Key.snk"
},
+ "testRunner": "xunit",
"commands": {
- "run": "Microsoft.AspNetCore.Server.KestrelTests",
- "test": "xunit.runner.aspnet -parallel none"
- }
+ "test": "xunit.runner.aspnet"
+ },
+ "content": [
+ "TestResources/testCert.pfx"
+ ]
}
View
13 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs
@@ -2,27 +2,20 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Http.Features;
-using Microsoft.Dnx.Compilation.CSharp;
using Microsoft.AspNetCore.Http.Features.Internal;
using Microsoft.AspNetCore.Http.Features.Authentication;
namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode
{
// This project can output the Class library as a NuGet Package.
// To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build".
- public class FrameFeatureCollection : ICompileModule
+ public class FrameFeatureCollection
{
static string Each<T>(IEnumerable<T> values, Func<T, string> formatter)
{
return values.Select(formatter).Aggregate((a, b) => a + b);
}
- public virtual void BeforeCompile(BeforeCompileContext context)
- {
- var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(GeneratedFile());
- context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree);
- }
-
public static string GeneratedFile()
{
var alwaysFeatures = new[]
@@ -129,9 +122,5 @@ private void FastFeatureSet(Type key, object feature)
}}
";
}
-
- public virtual void AfterCompile(AfterCompileContext context)
- {
- }
}
}
View
12 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs
@@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Microsoft.Dnx.Compilation.CSharp;
using System.Text;
namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode
{
// This project can output the Class library as a NuGet Package.
// To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build".
- public class KnownHeaders : ICompileModule
+ public class KnownHeaders
{
static string Each<T>(IEnumerable<T> values, Func<T, string> formatter)
{
@@ -73,11 +72,7 @@ protected string Term(string name, int offset, int count, string array, string s
return $"(({array}[{offset / count}] & {mask}{suffix}) == {comp}{suffix})";
}
}
- public virtual void BeforeCompile(BeforeCompileContext context)
- {
- var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(GeneratedFile());
- context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree);
- }
+
public static string GeneratedFile()
{
var commonHeaders = new[]
@@ -488,8 +483,5 @@ public bool MoveNext()
}}
")}}}";
}
- public virtual void AfterCompile(AfterCompileContext context)
- {
- }
}
}
View
2 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs
@@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode
{
public class Program
{
- public int Main(string[] args)
+ public static int Main(string[] args)
{
var text0 = KnownHeaders.GeneratedFile();
var text1 = FrameFeatureCollection.GeneratedFile();
View
20 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json
@@ -1,28 +1,24 @@
{
"version": "1.0.0-*",
-
+ "compilationOptions": {
+ "emitEntryPoint": true
+ },
"dependencies": {
- "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*",
"Microsoft.AspNetCore.Http.Features": "1.0.0-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-*"
},
-
- "commands": {
- "run": "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode"
- },
-
"frameworks": {
+ "dnxcore50": {
+ "dependencies": {
+ "NETStandard.Library": "1.0.0-*"
+ }
+ },
"dnx451": {
"frameworkAssemblies": {
"System.Runtime": "",
"System.Text.Encoding": "",
"System.Threading.Tasks": ""
}
- },
- "dnxcore50": {
- "dependencies": {
- "System.Console": "4.0.0-*"
- }
}
}
}
View
15 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs
@@ -1,18 +1,23 @@
using System;
using System.IO;
using System.Linq;
+using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json.Linq;
namespace Microsoft.AspNetCore.Server.Kestrel.LibuvCopier
{
public class Program
{
- public void Main(string[] args)
+ public static void Main(string[] args)
{
try
{
- var packagesFolder = Environment.GetEnvironmentVariable("DNX_PACKAGES") ??
- Path.Combine(GetHome(), ".nuget", "packages");
+ var packagesFolder = Environment.GetEnvironmentVariable("NUGET_PACKAGES");
+
+ if (string.IsNullOrEmpty(packagesFolder))
+ {
+ packagesFolder = Path.Combine(GetHome(), ".nuget", "packages");
+ }
packagesFolder = Environment.ExpandEnvironmentVariables(packagesFolder);
@@ -39,12 +44,12 @@ public void Main(string[] args)
}
// Copied from DNX's DnuEnvironment.cs
- private string GetHome()
+ private static string GetHome()
{
#if DNX451
return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
#else
- var runtimeEnv = Extensions.PlatformAbstractions.PlatformServices.Default.Runtime;
+ var runtimeEnv = PlatformServices.Default.Runtime;
if (runtimeEnv.OperatingSystem == "Windows")
{
return Environment.GetEnvironmentVariable("USERPROFILE") ??
View
26 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json
@@ -1,31 +1,19 @@
{
"version": "1.0.0-*",
- "description": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier Console Application",
- "authors": [ "pawelka" ],
- "tags": [ "" ],
- "projectUrl": "",
- "licenseUrl": "",
-
+ "compilationOptions": {
+ "emitEntryPoint": true
+ },
"dependencies": {
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
"Newtonsoft.Json": "7.0.1"
},
-
- "commands": {
- "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier"
- },
-
"frameworks": {
- "dnx451": { },
"dnxcore50": {
"dependencies": {
- "Microsoft.CSharp": "4.0.1-*",
- "System.Collections": "4.0.11-*",
- "System.Console": "4.0.0-*",
- "System.Linq": "4.0.1-*",
- "System.Threading": "4.0.11-*",
- "System.IO.FileSystem": "4.0.1-*"
+ "NETStandard.Library": "1.0.0-*",
+ "System.Dynamic.Runtime": "4.0.11-*"
}
- }
+ },
+ "dnx451": { }
}
}
View
20 tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj
@@ -1,20 +0,0 @@
-<?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>82295647-7c1c-4671-bab6-0fef58f949ec</ProjectGuid>
- <RootNamespace>Microsoft.StandardsPolice</RootNamespace>
- <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
- <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
- </PropertyGroup>
-
- <PropertyGroup>
- <SchemaVersion>2.0</SchemaVersion>
- </PropertyGroup>
- <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
-</Project>
View
49 tools/Microsoft.StandardsPolice/Program.cs
@@ -1,49 +0,0 @@
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Microsoft.StandardsPolice
-{
- public class Program
- {
- public int Main(string[] args)
- {
- var tree = CSharpSyntaxTree.ParseText(@"
-public class Hello { public Hello(int foo){}; protected int _foo; int _bar; }
-public class World { public World(int foo){}; protected int _foo; int _bar; static int _quux = 4; enum Blah{} class Clazz{} }
-");
- var diags = new List<Diagnostic>();
-
- var comp = CSharpCompilation.Create("Comp", new[] { tree });
-
- StandardsPoliceCompileModule.ScanCompilation(diags, comp);
-
- var hello = comp.GetTypeByMetadataName("Hello");
- foreach (var f in hello.GetMembers().OfType<IFieldSymbol>())
- {
- var syntax = f.DeclaringSyntaxReferences.Single().GetSyntax();
- Console.WriteLine($"{syntax.ToFullString()}");
-
- var fds = syntax.Parent.Parent as FieldDeclarationSyntax;
- var toks = syntax.DescendantTokens().ToArray();
- var nods = syntax.DescendantNodesAndSelf().ToArray();
- var mods = fds.Modifiers;
-
- foreach (var mod in fds.Modifiers)
- {
- Console.WriteLine($"{mod.Kind()} {mod.ToFullString()}");
- }
- var locs = f.Locations.ToArray();
- }
-
- foreach(var d in diags)
- {
- Console.WriteLine(d);
- }
- return 0;
- }
- }
-}
View
292 tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs
@@ -1,292 +0,0 @@
-using Microsoft.Dnx.Compilation.CSharp;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Microsoft.CodeAnalysis.CSharp;
-using System;
-
-namespace Microsoft.StandardsPolice
-{
- public class StandardsPoliceCompileModule : ICompileModule
- {
- public void BeforeCompile(BeforeCompileContext context)
- {
- ScanCompilation(context.Diagnostics, context.Compilation);
- }
-
- internal static void ScanCompilation(IList<Diagnostic> diagnostics, CSharpCompilation compilation)
- {
- ScanNamespace(diagnostics, compilation.GlobalNamespace);
-
- foreach (var st in compilation.SyntaxTrees)
- {
- if (!st.FilePath.EndsWith(".Generated.cs"))
- {
- ScanSyntaxTree(diagnostics, st);
- }
- }
- }
-
- internal static void ScanSyntaxTree(IList<Diagnostic> diagnostics, SyntaxTree syntaxTree)
- {
- var root = syntaxTree.GetRoot();
-
- var typeDeclarations = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax))
- .OfType<TypeDeclarationSyntax>()
- .ToArray();
-
- if (typeDeclarations.Length > 1)
- {
- foreach (var typeDeclaration in typeDeclarations)
- {
- diagnostics.Add(Diagnostic.Create(
- "SP1002", "StandardsPolice", "more than one type per file",
- DiagnosticSeverity.Warning,
- DiagnosticSeverity.Warning,
- false,
- 3,
- location: typeDeclaration.GetLocation()));
- }
- }
-
- var usingDirectives = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax))
- .OfType<UsingDirectiveSyntax>()
- .ToArray();
-
- var priorUsingDirective = default(UsingDirectiveSyntax);
- foreach (var usingDirective in usingDirectives)
- {
- var acceptableOrder = false;
- if (!acceptableOrder && priorUsingDirective == null)
- {
- acceptableOrder = true;
- }
- if (!acceptableOrder && string.Compare(priorUsingDirective.Name.ToString(), usingDirective.Name.ToString(), StringComparison.OrdinalIgnoreCase) < 0)
- {
- acceptableOrder = true;
- }
- if (!acceptableOrder && priorUsingDirective.Name.ToString() == "System")
- {
- acceptableOrder = true;
- }
- if (!acceptableOrder &&
- priorUsingDirective.Name.ToString().StartsWith("System") &&
- !usingDirective.Name.ToString().StartsWith("System"))
- {
- acceptableOrder = true;
- }
- if (!acceptableOrder)
- {
- diagnostics.Add(Diagnostic.Create(
- "SP1004", "StandardsPolice", "namespaces not alphabetized",
- DiagnosticSeverity.Warning,
- DiagnosticSeverity.Warning,
- false,
- 3,
- location: usingDirective.GetLocation()));
- }
- priorUsingDirective = usingDirective;
- }
- }
-
- private static void ScanNamespace(IList<Diagnostic> diagnostics, INamespaceSymbol namespaceSymbol)
- {
- foreach (var member in namespaceSymbol.GetNamespaceMembers())
- {
- ScanNamespace(diagnostics, member);
- }
- foreach (var member in namespaceSymbol.GetTypeMembers())
- {
- ScanType(diagnostics, member);
- }
- }
-
- private static void ScanType(IList<Diagnostic> diagnostics, INamedTypeSymbol typeSymbol)
- {
- if (typeSymbol.Locations.Any(location => location.IsInSource))
- {
- RuleFieldPrivateKeyword(diagnostics, typeSymbol);
- RuleMembersAreInCorrectOrder(diagnostics, typeSymbol, MapClassMembers);
- }
-
- foreach (var member in typeSymbol.GetTypeMembers())
- {
- ScanType(diagnostics, member);
- }
- }
-
-
- private static void RuleFieldPrivateKeyword(IList<Diagnostic> diagnostics, INamedTypeSymbol typeSymbol)
- {
- foreach (var member in typeSymbol.GetMembers().OfType<IFieldSymbol>())
- {
- if (member.DeclaredAccessibility != Accessibility.Private)
- {
- continue;
- }
-
- foreach (var syntaxReference in member.DeclaringSyntaxReferences)
- {
- var fieldHasPrivateKeyword = false;
- var syntax = syntaxReference.GetSyntax();
- var fds = syntax?.Parent?.Parent as FieldDeclarationSyntax;
- if (fds == null)
- {
- continue;
- }
- foreach (var mod in fds.Modifiers)
- {
- if (mod.IsKind(CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword))
- {
- fieldHasPrivateKeyword = true;
- }
- }
- if (!fieldHasPrivateKeyword)
- {
- diagnostics.Add(Diagnostic.Create(
- "SP1001", "StandardsPolice", "private keyword missing",
- DiagnosticSeverity.Warning,
- DiagnosticSeverity.Warning,
- false,
- 3,
- location: member.Locations.SingleOrDefault()));
- }
- }
- }
- }
-
- private static void RuleMembersAreInCorrectOrder(IList<Diagnostic> diagnostics, INamedTypeSymbol typeSymbol, Func<ISymbol, ClassZone> mapZone)
- {
- if (typeSymbol.Locations.Length >= 2 || typeSymbol.Name == "Libuv")
- {
- // Don't apply to partial classes. All members are enumerated, but are not merged by zone order.
- return;
- }
-
- var currentZone = ClassZone.BeforeStart;
- var currentZoneExample = default(ISymbol);
- foreach (var member in typeSymbol.GetMembers())
- {
- var memberZone = mapZone(member);
- if (memberZone == ClassZone.Ignored)
- {
- continue;
- }
- if (currentZone <= memberZone)
- {
- currentZone = memberZone;
- currentZoneExample = member;
- }
- if (memberZone >= ClassZone.OtherThings)
- {
- continue;
- }
- if (memberZone < currentZone)
- {
- if (member.Locations.Count() == 1)
- {
- diagnostics.Add(Diagnostic.Create(
- "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be after {currentZone} like {currentZoneExample.Name}",
- DiagnosticSeverity.Warning,
- DiagnosticSeverity.Warning,
- false,
- 3,
- location: member.Locations.Single(),
- additionalLocations: currentZoneExample.Locations));
- }
- }
- }
- currentZone = ClassZone.AfterEnd;
- currentZoneExample = null;
- foreach (var member in typeSymbol.GetMembers().Reverse())
- {
- var memberZone = mapZone(member);
- if (memberZone == ClassZone.Ignored)
- {
- continue;
- }
- if (currentZone >= memberZone)
- {
- currentZone = memberZone;
- currentZoneExample = member;
- }
- if (memberZone <= ClassZone.OtherThings)
- {
- continue;
- }
- if (memberZone > currentZone)
- {
- if (member.Locations.Count() == 1)
- {
- diagnostics.Add(Diagnostic.Create(
- "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be before {currentZone} like {currentZoneExample.Name}",
- DiagnosticSeverity.Warning,
- DiagnosticSeverity.Warning,
- false,
- 3,
- location: member.Locations.Single(),
- additionalLocations: currentZoneExample.Locations));
- }
- }
- }
- }
-
- private static ClassZone MapClassMembers(ISymbol member)
- {
- if (member.IsImplicitlyDeclared)
- {
- return ClassZone.Ignored;
- }
- if (member.Kind == SymbolKind.Field)
- {
- return ClassZone.Fields;
- }
- if (member.Kind == SymbolKind.Method)
- {
- var method = (IMethodSymbol)member;
- if (method.MethodKind == MethodKind.Constructor ||
- method.MethodKind == MethodKind.StaticConstructor)
- {
- return ClassZone.Constructors;
- }
- if (method.MethodKind == MethodKind.PropertyGet ||
- method.MethodKind == MethodKind.PropertySet)
- {
- return ClassZone.Properties;
- }
- }
- if (member.Kind == SymbolKind.Property)
- {
- return ClassZone.Properties;
- }
- if (member.Kind == SymbolKind.NamedType)
- {
- var namedType = (INamedTypeSymbol)member;
- if (namedType.TypeKind == TypeKind.Class ||
- namedType.TypeKind == TypeKind.Enum ||
- namedType.TypeKind == TypeKind.Struct)
- {
- return ClassZone.NestedTypes;
- }
- }
- return ClassZone.OtherThings;
- }
-
- public void AfterCompile(AfterCompileContext context)
- {
- }
-
- private enum ClassZone
- {
- Ignored,
- BeforeStart,
- Fields,
- Constructors,
- Properties,
- OtherThings,
- NestedTypes,
- AfterEnd
- }
- }
-}
View
44 tools/Microsoft.StandardsPolice/project.json
@@ -1,44 +0,0 @@
-{
- "version": "1.0.0-*",
-
- "compilationOptions": {
- "keyFile": "../../tools/Key.snk"
- },
-
- "description": "Microsoft.StandardsPolice Class Library",
-
- "dependencies": {
- "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*"
- },
-
- "commands": {
- "Microsoft.StandardsPolice": "Microsoft.StandardsPolice"
- },
-
- "frameworks": {
- "net451": {
- "frameworkAssemblies": {
- "System.Runtime": "",
- "System.Text.Encoding": "",
- "System.Threading.Tasks": ""
- }
- },
- "dnx451": {
- "frameworkAssemblies": {
- "System.Runtime": "",
- "System.Text.Encoding": "",
- "System.Threading.Tasks": ""
- }
- },
- "dotnet5.4": {
- "dependencies": {
- "System.Console": "4.0.0-*"
- }
- },
- "dnxcore50": {
- "dependencies": {
- "System.Console": "4.0.0-*"
- }
- }
- }
-}

0 comments on commit 6757a31

Please sign in to comment.