├── tools └── nuget.exe ├── test └── IisExpressTestKit.Tests │ ├── App.config │ ├── outbound.html │ ├── outbound.txt │ ├── packages.config │ ├── Rewrite.config │ ├── Transform.config │ ├── Properties │ └── AssemblyInfo.cs │ ├── RewriteRuleTest.cs │ └── IisExpressTestKit.Tests.csproj ├── src └── IisExpressTestKit │ ├── IisRewriteTestBase.cs │ ├── IisExpressRequestOptions.cs │ ├── packages.config │ ├── IisExpressTestKit.nuspec │ ├── IisExpressFixture.cs │ ├── EchoHttpModule.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── EchoHttpHandler.cs │ ├── IisExpressResponse.cs │ ├── IisExpressTestKit.csproj │ └── IisExpress.cs ├── .gitattributes ├── README.md ├── IisExpressTestKit.sln ├── .gitignore └── LICENSE /tools/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shibayan/iisexpress-testkit/HEAD/tools/nuget.exe -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/outbound.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | hoge 10 | 11 | -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/outbound.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | hoge 10 | 11 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/IisRewriteTestBase.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace IisExpressTestKit 4 | { 5 | public abstract class IisRewriteTestBase : IClassFixture 6 | { 7 | protected IisRewriteTestBase(IisExpressFixture fixture) 8 | { 9 | Iis = fixture.Iis; 10 | } 11 | 12 | protected IisExpress Iis { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/IisExpressRequestOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Specialized; 2 | using System.Net; 3 | 4 | namespace IisExpressTestKit 5 | { 6 | public class IisExpressRequestOptions 7 | { 8 | internal IisExpressRequestOptions() { } 9 | 10 | public HttpStatusCode StatusCode { get; set; } = HttpStatusCode.OK; 11 | public NameValueCollection Headers { get; set; } = new NameValueCollection(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/IisExpressTestKit.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | IisExpressTestKit 5 | $version$ 6 | IIS Express TestKit 7 | shibayan 8 | shibayan 9 | https://github.com/shibayan/iisexpress-testkit/blob/master/LICENSE 10 | https://github.com/shibayan/iisexpress-testkit 11 | false 12 | IIS Express unit test kit for xUnit.net 13 | iis unittest xunit 14 | 15 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/IisExpressFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.IO; 4 | 5 | namespace IisExpressTestKit 6 | { 7 | public class IisExpressFixture : IDisposable 8 | { 9 | public IisExpressFixture() 10 | { 11 | Iis = new IisExpress 12 | { 13 | ConfigTransformPath = ConfigurationManager.AppSettings["ConfigTransformPath"] ?? Path.Combine("Transform.config") 14 | }; 15 | 16 | Iis.Start(); 17 | } 18 | 19 | public void Dispose() 20 | { 21 | Iis.Stop(); 22 | } 23 | 24 | public IisExpress Iis { get; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/Rewrite.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/EchoHttpModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web; 3 | 4 | namespace IisExpressTestKit 5 | { 6 | public class EchoHttpModule : IHttpModule 7 | { 8 | public void Init(HttpApplication context) 9 | { 10 | _context = context; 11 | 12 | context.PreSendRequestHeaders += OnPreSendRequestHeaders; 13 | } 14 | 15 | private HttpApplication _context; 16 | 17 | public void Dispose() 18 | { 19 | _context.PreSendRequestHeaders -= OnPreSendRequestHeaders; 20 | } 21 | 22 | private void OnPreSendRequestHeaders(object sender, EventArgs e) 23 | { 24 | var context = HttpContext.Current; 25 | 26 | context.Response.Headers["X-IIS-RealHost"] = context.Request.Url.Host; 27 | context.Response.Headers["X-IIS-RealPath"] = context.Request.Url.PathAndQuery; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/Transform.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 5 | // アセンブリに関連付けられている情報を変更するには、 6 | // これらの属性値を変更してください。 7 | [assembly: AssemblyTitle("IisExpressTestKit")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("IisExpressTestKit")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 17 | // 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 18 | // その型の ComVisible 属性を true に設定してください。 19 | [assembly: ComVisible(false)] 20 | 21 | // このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります 22 | [assembly: Guid("c22c6598-6b1c-4d74-a49c-85ed2a329f6f")] 23 | 24 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 25 | // 26 | // メジャー バージョン 27 | // マイナー バージョン 28 | // ビルド番号 29 | // Revision 30 | // 31 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 32 | // 既定値にすることができます: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("0.6.0")] -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 6 | // アセンブリに関連付けられている情報を変更するには、 7 | // これらの属性値を変更してください。 8 | [assembly: AssemblyTitle("IisExpressTestKit.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("IisExpressTestKit.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 18 | // 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 19 | // その型の ComVisible 属性を true に設定してください。 20 | [assembly: ComVisible(false)] 21 | 22 | // このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります 23 | [assembly: Guid("fe3bd555-aa4a-4073-a2e2-2c3d8387933a")] 24 | 25 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 26 | // 27 | // メジャー バージョン 28 | // マイナー バージョン 29 | // ビルド番号 30 | // Revision 31 | // 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 33 | // 既定値にすることができます: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | IIS Express TestKit 2 | ================ 3 | [![Build status](https://ci.appveyor.com/api/projects/status/v5kgu9runa70wum1?svg=true)](https://ci.appveyor.com/project/shibayan/iisexpress-testkit) 4 | [![License](https://img.shields.io/github/license/shibayan/iisexpress-testkit.svg)](https://github.com/shibayan/iisexpress-testkit/blob/master/LICENSE) 5 | [![NuGet Version](https://img.shields.io/nuget/v/IisExpressTestKit.svg)](https://www.nuget.org/packages/IisExpressTestKit/) 6 | 7 | ## Getting Started 8 | 9 | - Create new xUnit test project 10 | - Install package from NuGet 11 | 12 | ``` 13 | Install-Package IisExpressTestKit 14 | ``` 15 | 16 | - Write test case 17 | 18 | ```csharp 19 | [Fact] 20 | public void RewriteRulesTest() 21 | { 22 | Iis.Request("/hoge") 23 | .IsPath("/translated/hoge") 24 | .IsStatusCode(HttpStatusCode.OK); 25 | 26 | Iis.Request("/hoge/foo/bar/baz") 27 | .IsPath("/translated/hoge/foo/bar/baz") 28 | .IsStatusCode(HttpStatusCode.OK); 29 | } 30 | ``` 31 | 32 | - Make happy :) 33 | 34 | ![Test Result](http://cdn-ak.f.st-hatena.com/images/fotolife/s/shiba-yan/20160619/20160619175112.png) 35 | 36 | - Running AppVeyor CI 37 | 38 | ![AppVeyor](http://cdn-ak.f.st-hatena.com/images/fotolife/s/shiba-yan/20160713/20160713235842.png) 39 | 40 | ## License 41 | 42 | [Apache License 2.0](https://github.com/shibayan/iisexpress-testkit/blob/master/LICENSE) 43 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/EchoHttpHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace IisExpressTestKit 7 | { 8 | public class EchoHttpHandler : IHttpHandler 9 | { 10 | public void ProcessRequest(HttpContext context) 11 | { 12 | context.Response.TrySkipIisCustomErrors = true; 13 | 14 | if (File.Exists(context.Request.PhysicalPath) || Directory.Exists(context.Request.PhysicalPath)) 15 | { 16 | var type = typeof(HttpApplication).Assembly.GetType("System.Web.StaticFileHandler", true); 17 | var handler = (IHttpHandler)Activator.CreateInstance(type, true); 18 | 19 | handler.ProcessRequest(context); 20 | } 21 | else 22 | { 23 | var originalFile = context.Request.Headers["X-OriginalFile"]; 24 | 25 | if (!string.IsNullOrEmpty(originalFile)) 26 | { 27 | context.Response.ContentType = MimeMapping.GetMimeMapping(originalFile); 28 | context.Response.WriteFile(originalFile); 29 | } 30 | 31 | context.Response.StatusCode = int.TryParse(context.Request.Headers["X-IIS-StatusCode"], out var statusCode) ? statusCode : 200; 32 | 33 | foreach (var key in context.Request.Headers.AllKeys.Where(x => x.StartsWith("X-IIS-Header-"))) 34 | { 35 | var headerKey = key.Substring(13); 36 | 37 | if (headerKey == "Content-Type") 38 | { 39 | context.Response.ContentType = context.Request.Headers[key]; 40 | } 41 | else 42 | { 43 | context.Response.Headers[headerKey] = context.Request.Headers[key]; 44 | } 45 | } 46 | } 47 | } 48 | 49 | public bool IsReusable => true; 50 | } 51 | } -------------------------------------------------------------------------------- /IisExpressTestKit.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B6B7C899-1E20-4305-A5ED-363A28E7A79D}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A8B975B7-4C6E-49EA-AF46-7432300220BA}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IisExpressTestKit", "src\IisExpressTestKit\IisExpressTestKit.csproj", "{C22C6598-6B1C-4D74-A49C-85ED2A329F6F}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IisExpressTestKit.Tests", "test\IisExpressTestKit.Tests\IisExpressTestKit.Tests.csproj", "{FE3BD555-AA4A-4073-A2E2-2C3D8387933A}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {C22C6598-6B1C-4D74-A49C-85ED2A329F6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {C22C6598-6B1C-4D74-A49C-85ED2A329F6F}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {C22C6598-6B1C-4D74-A49C-85ED2A329F6F}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {C22C6598-6B1C-4D74-A49C-85ED2A329F6F}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {FE3BD555-AA4A-4073-A2E2-2C3D8387933A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {FE3BD555-AA4A-4073-A2E2-2C3D8387933A}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {FE3BD555-AA4A-4073-A2E2-2C3D8387933A}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {FE3BD555-AA4A-4073-A2E2-2C3D8387933A}.Release|Any CPU.Build.0 = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | GlobalSection(NestedProjects) = preSolution 33 | {C22C6598-6B1C-4D74-A49C-85ED2A329F6F} = {B6B7C899-1E20-4305-A5ED-363A28E7A79D} 34 | {FE3BD555-AA4A-4073-A2E2-2C3D8387933A} = {A8B975B7-4C6E-49EA-AF46-7432300220BA} 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/IisExpressResponse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Specialized; 2 | using System.Net; 3 | using System.Text.RegularExpressions; 4 | 5 | using Xunit; 6 | 7 | namespace IisExpressTestKit 8 | { 9 | public class IisExpressResponse 10 | { 11 | internal IisExpressResponse() { } 12 | 13 | public string Host { get; set; } 14 | public string Path { get; set; } 15 | public HttpStatusCode StatusCode { get; set; } 16 | public NameValueCollection Headers { get; set; } 17 | public string Body { get; set; } 18 | 19 | public IisExpressResponse IsPath(string expectedPath) 20 | { 21 | Assert.Equal(expectedPath, Path); 22 | 23 | return this; 24 | } 25 | 26 | public IisExpressResponse IsRedirect(string expectedUrl) 27 | { 28 | Assert.Equal(expectedUrl, Headers["Location"]); 29 | 30 | return this; 31 | } 32 | 33 | public IisExpressResponse IsStatusCode(HttpStatusCode expectedStatusCode) 34 | { 35 | Assert.Equal(expectedStatusCode, StatusCode); 36 | 37 | return this; 38 | } 39 | 40 | public IisExpressResponse IsHeaderValue(string headerName, string expectedValue) 41 | { 42 | Assert.Equal(expectedValue, Headers[headerName]); 43 | 44 | return this; 45 | } 46 | 47 | public IisExpressResponse Contains(string expectedSubstring) 48 | { 49 | Assert.Contains(expectedSubstring, Body); 50 | 51 | return this; 52 | } 53 | 54 | public IisExpressResponse DoesNotContain(string expectedSubstring) 55 | { 56 | Assert.DoesNotContain(expectedSubstring, Body); 57 | 58 | return this; 59 | } 60 | 61 | public IisExpressResponse HtmlAttribute(string tagName, string attributeName, string expectedValue) 62 | { 63 | var tagMatch = Regex.Match(Body, $"<{tagName}.*?>"); 64 | 65 | Assert.True(tagMatch.Success); 66 | 67 | var content = tagMatch.Value; 68 | 69 | var attributeMatch = Regex.Match(content, $"{Regex.Escape(attributeName)}=\"?([^\"]*)\"?"); 70 | 71 | Assert.True(attributeMatch.Success); 72 | 73 | Assert.Contains(expectedValue, attributeMatch.Groups[1].Value); 74 | 75 | return this; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/RewriteRuleTest.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | using Xunit; 4 | 5 | namespace IisExpressTestKit.Tests 6 | { 7 | public class RewriteRuleTest : IisRewriteTestBase 8 | { 9 | public RewriteRuleTest(IisExpressFixture fixture) 10 | : base(fixture) 11 | { 12 | } 13 | 14 | [Fact] 15 | public void Rewriteルールのテスト() 16 | { 17 | Iis.Request("/hoge") 18 | .IsPath("/translated/hoge") 19 | .IsStatusCode(HttpStatusCode.OK); 20 | 21 | Iis.Request("/hoge/foo/bar/baz") 22 | .IsPath("/translated/hoge/foo/bar/baz") 23 | .IsStatusCode(HttpStatusCode.OK); 24 | } 25 | 26 | [Fact] 27 | public void Redirectのテスト() 28 | { 29 | Iis.Request("/found") 30 | .IsRedirect("http://www.google.co.jp"); 31 | } 32 | 33 | [Fact] 34 | public void PermanentRedirectのテスト() 35 | { 36 | Iis.Request("/redirect") 37 | .IsRedirect("http://www.google.co.jp") 38 | .IsStatusCode(HttpStatusCode.MovedPermanently); 39 | } 40 | 41 | [Fact] 42 | public void LocalRedirectのテスト() 43 | { 44 | Iis.Request("/local") 45 | .IsRedirect("/local/redirect"); 46 | } 47 | 48 | [Fact] 49 | public void StatusCodeのテスト() 50 | { 51 | Iis.Request("/404") 52 | .IsStatusCode(HttpStatusCode.NotFound); 53 | } 54 | 55 | [Fact] 56 | public void StatusCodeのテスト2() 57 | { 58 | Iis.Request("/statuscode", options: options => options.StatusCode = HttpStatusCode.BadRequest) 59 | .IsStatusCode(HttpStatusCode.BadRequest); 60 | 61 | Iis.Request("/statuscode", options: options => options.StatusCode = HttpStatusCode.InternalServerError) 62 | .IsStatusCode(HttpStatusCode.InternalServerError); 63 | } 64 | 65 | [Fact] 66 | public void CustomHeaderのテスト() 67 | { 68 | Iis.Request("/customheader", options: options => { options.Headers["Content-Type"] = "application/json"; }) 69 | .IsHeaderValue("Content-Type", "application/json") 70 | .IsStatusCode(HttpStatusCode.OK); 71 | } 72 | 73 | [Fact] 74 | public void StaticFileのテスト() 75 | { 76 | Iis.Request("/test", "outbound.html") 77 | .IsHeaderValue("Content-Type", "text/html") 78 | .IsStatusCode(HttpStatusCode.OK); 79 | } 80 | 81 | [Fact] 82 | public void OutboundRuleのテスト() 83 | { 84 | Iis.Request("/outboundtest", @".\outbound.html") 85 | .IsHeaderValue("Content-Type", "text/html") 86 | .HtmlAttribute("a", "href", "/translated/hoge") 87 | .IsStatusCode(HttpStatusCode.OK); 88 | } 89 | 90 | [Fact] 91 | public void OutboundRuleのテスト2() 92 | { 93 | Iis.Request("/outboundtest", @".\outbound.html") 94 | .Contains("") 95 | .IsStatusCode(HttpStatusCode.OK); 96 | 97 | Iis.Request("/outboundtest", @".\outbound.txt", options => options.Headers["Content-Type"] = "text/html") 98 | .Contains("") 99 | .IsStatusCode(HttpStatusCode.OK); 100 | } 101 | 102 | [Fact] 103 | public void OutboundRuleのテスト3() 104 | { 105 | Iis.Request("/outboundtest", @".\outbound.html", options => options.Headers["Content-Type"] = "text/plain") 106 | .DoesNotContain("") 107 | .IsStatusCode(HttpStatusCode.OK); 108 | 109 | Iis.Request("/outboundtest", @".\outbound.txt") 110 | .DoesNotContain("") 111 | .IsStatusCode(HttpStatusCode.OK); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/IisExpressTestKit.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {C22C6598-6B1C-4D74-A49C-85ED2A329F6F} 9 | Library 10 | Properties 11 | IisExpressTestKit 12 | IisExpressTestKit 13 | v4.6 14 | 512 15 | 16 | 17 | 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | ..\..\packages\Microsoft.Web.Xdt.2.1.2\lib\net40\Microsoft.Web.XmlTransform.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll 48 | 49 | 50 | ..\..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll 51 | 52 | 53 | ..\..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll 54 | 55 | 56 | ..\..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。 76 | 77 | 78 | 79 | 80 | 81 | 88 | -------------------------------------------------------------------------------- /test/IisExpressTestKit.Tests/IisExpressTestKit.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | {FE3BD555-AA4A-4073-A2E2-2C3D8387933A} 10 | Library 11 | Properties 12 | IisExpressTestKit.Tests 13 | IisExpressTestKit.Tests 14 | v4.6.1 15 | 512 16 | 17 | 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | ..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll 42 | 43 | 44 | ..\..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll 45 | 46 | 47 | ..\..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll 48 | 49 | 50 | ..\..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | PreserveNewest 62 | 63 | 64 | 65 | 66 | 67 | {c22c6598-6b1c-4d74-a49c-85ed2a329f6f} 68 | IisExpressTestKit 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | PreserveNewest 77 | 78 | 79 | PreserveNewest 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。 89 | 90 | 91 | 92 | 93 | 94 | 95 | 102 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | 254 | # ========================= 255 | # Operating System Files 256 | # ========================= 257 | 258 | # OSX 259 | # ========================= 260 | 261 | .DS_Store 262 | .AppleDouble 263 | .LSOverride 264 | 265 | # Thumbnails 266 | ._* 267 | 268 | # Files that might appear in the root of a volume 269 | .DocumentRevisions-V100 270 | .fseventsd 271 | .Spotlight-V100 272 | .TemporaryItems 273 | .Trashes 274 | .VolumeIcon.icns 275 | 276 | # Directories potentially created on remote AFP share 277 | .AppleDB 278 | .AppleDesktop 279 | Network Trash Folder 280 | Temporary Items 281 | .apdisk 282 | 283 | # Windows 284 | # ========================= 285 | 286 | # Windows image file caches 287 | Thumbs.db 288 | ehthumbs.db 289 | 290 | # Folder config file 291 | Desktop.ini 292 | 293 | # Recycle Bin used on file shares 294 | $RECYCLE.BIN/ 295 | 296 | # Windows Installer files 297 | *.cab 298 | *.msi 299 | *.msm 300 | *.msp 301 | 302 | # Windows shortcuts 303 | *.lnk 304 | -------------------------------------------------------------------------------- /src/IisExpressTestKit/IisExpress.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Specialized; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.NetworkInformation; 8 | using System.Threading; 9 | using System.Xml; 10 | 11 | using Microsoft.Web.XmlTransform; 12 | 13 | namespace IisExpressTestKit 14 | { 15 | public class IisExpress : IDisposable 16 | { 17 | public IisExpress() 18 | { 19 | _port = GetPortNumber(); 20 | _wwwroot = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); 21 | 22 | ServicePointManager.Expect100Continue = false; 23 | } 24 | 25 | private readonly int _port; 26 | private readonly string _wwwroot; 27 | private Process _process; 28 | 29 | private static readonly Random _random = new Random(); 30 | 31 | private const string IisExpressExe = @"IIS Express\iisexpress.exe"; 32 | private const string WebConfigTemplate = @" 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | "; 43 | 44 | public string ConfigTransformPath { get; set; } 45 | 46 | public void Start() 47 | { 48 | PrepareForStart(); 49 | 50 | var iisExpress = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), IisExpressExe); 51 | 52 | _process = Process.Start(new ProcessStartInfo(iisExpress, $"/path:\"{_wwwroot}\" /port:{_port} /systray:false") 53 | { 54 | CreateNoWindow = true, 55 | UseShellExecute = false 56 | }); 57 | 58 | WaitForStartup(); 59 | } 60 | 61 | public void Stop() 62 | { 63 | _process?.Kill(); 64 | _process?.Dispose(); 65 | 66 | _process = null; 67 | } 68 | 69 | public void Dispose() 70 | { 71 | Stop(); 72 | } 73 | 74 | public IisExpressResponse Request(string path, string originalFile = null, Action options = null) 75 | { 76 | var response = ExecuteRequest(FormatAbsoluteUrl(path), originalFile, options); 77 | 78 | var data = new IisExpressResponse 79 | { 80 | Host = response.Headers["X-IIS-RealHost"], 81 | Path = response.Headers["X-IIS-RealPath"], 82 | StatusCode = response.StatusCode, 83 | Headers = new NameValueCollection(response.Headers) 84 | }; 85 | 86 | if (!string.IsNullOrEmpty(data.Headers["Location"])) 87 | { 88 | data.Headers["Location"] = data.Headers["Location"].Replace(FormatAbsoluteUrl(), ""); 89 | } 90 | 91 | using (var reader = new StreamReader(response.GetResponseStream())) 92 | { 93 | data.Body = reader.ReadToEnd(); 94 | } 95 | 96 | return data; 97 | } 98 | 99 | private void PrepareForStart() 100 | { 101 | if (!Directory.Exists(_wwwroot)) 102 | { 103 | Directory.CreateDirectory(_wwwroot); 104 | } 105 | 106 | var binDirectory = Path.Combine(_wwwroot, "bin"); 107 | 108 | if (!Directory.Exists(binDirectory)) 109 | { 110 | Directory.CreateDirectory(binDirectory); 111 | } 112 | 113 | CopyFileToDirectory(ConfigTransformPath, _wwwroot); 114 | CopyFileToDirectory(typeof(IisExpress).Assembly.Location, binDirectory); 115 | 116 | var document = new XmlTransformableDocument(); 117 | 118 | document.LoadXml(WebConfigTemplate); 119 | 120 | using (var transform = new XmlTransformation(ConfigTransformPath)) 121 | { 122 | transform.Apply(document); 123 | } 124 | 125 | var list = document.SelectNodes("//*[@configSource]"); 126 | 127 | if (list != null) 128 | { 129 | foreach (var node in list.Cast()) 130 | { 131 | var source = document.CreateDocumentFragment(); 132 | 133 | source.InnerXml = File.ReadAllText(node.Attributes["configSource"].Value); 134 | 135 | var newNode = source.ChildNodes.Cast().First(x => x.NodeType == XmlNodeType.Element); 136 | 137 | node.ParentNode.ReplaceChild(newNode, node); 138 | } 139 | } 140 | 141 | document.Save(Path.Combine(_wwwroot, "Web.config")); 142 | } 143 | 144 | private void WaitForStartup() 145 | { 146 | var client = new WebClient(); 147 | 148 | while (true) 149 | { 150 | try 151 | { 152 | client.DownloadString(FormatAbsoluteUrl()); 153 | 154 | break; 155 | } 156 | catch (WebException ex) 157 | { 158 | if (ex.Status == WebExceptionStatus.ProtocolError) 159 | { 160 | var response = (HttpWebResponse)ex.Response; 161 | 162 | if (response.StatusCode == HttpStatusCode.InternalServerError) 163 | { 164 | Stop(); 165 | 166 | throw; 167 | } 168 | 169 | break; 170 | } 171 | } 172 | 173 | Thread.Sleep(100); 174 | } 175 | } 176 | 177 | private string FormatAbsoluteUrl(string path = "") 178 | { 179 | return $"http://localhost:{_port}{path}"; 180 | } 181 | 182 | private static HttpWebResponse ExecuteRequest(string url, string originalFile, Action options) 183 | { 184 | var request = (HttpWebRequest)WebRequest.Create(url); 185 | 186 | request.AllowAutoRedirect = false; 187 | 188 | if (!string.IsNullOrEmpty(originalFile)) 189 | { 190 | request.Headers["X-OriginalFile"] = Path.GetFullPath(originalFile); 191 | } 192 | 193 | if (options != null) 194 | { 195 | var optionsValue = new IisExpressRequestOptions(); 196 | 197 | options(optionsValue); 198 | 199 | request.Headers["X-IIS-StatusCode"] = ((int)optionsValue.StatusCode).ToString(); 200 | 201 | foreach (var key in optionsValue.Headers.AllKeys) 202 | { 203 | request.Headers["X-IIS-Header-" + key] = optionsValue.Headers[key]; 204 | } 205 | } 206 | 207 | try 208 | { 209 | return (HttpWebResponse)request.GetResponse(); 210 | } 211 | catch (WebException ex) 212 | { 213 | return (HttpWebResponse)ex.Response; 214 | } 215 | } 216 | 217 | private static void CopyFileToDirectory(string sourceFilePath, string destinationDirectory) 218 | { 219 | var fileName = Path.GetFileName(sourceFilePath); 220 | 221 | File.Copy(sourceFilePath, Path.Combine(destinationDirectory, fileName), true); 222 | } 223 | 224 | private static int GetPortNumber() 225 | { 226 | int port; 227 | 228 | do 229 | { 230 | port = _random.Next(1025, 65535); 231 | } while (!IsPortAvailable(port)); 232 | 233 | return port; 234 | } 235 | 236 | private static bool IsPortAvailable(int port) 237 | { 238 | var connections = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections(); 239 | 240 | return connections.All(x => x.LocalEndPoint.Port != port); 241 | } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2015 Tatsuro Shibamura 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------