├── korebuild-lock.txt
├── NuGetPackageVerifier.json
├── korebuild.json
├── CONTRIBUTING.md
├── NuGet.config
├── README.md
├── run.cmd
├── CODE-OF-CONDUCT.md
├── .vsts-pipelines
└── builds
│ ├── ci-internal.yml
│ └── ci-public.yml
├── test
├── Directory.Build.props
└── Microsoft.VisualStudio.Web.BrowserLink.Test
│ ├── Microsoft.VisualStudio.Web.BrowserLink.Test.csproj
│ ├── AssertWithMessage.cs
│ ├── PathUtilTest.cs
│ ├── MockScriptInjectionFilterContext.cs
│ ├── MockResponseHandler.cs
│ ├── MockHttpSocketAdapter.cs
│ ├── TaskAssert.cs
│ ├── ContentTypeUtilTest.cs
│ ├── MockSocketAdapter.cs
│ ├── TaskHelpersTest.cs
│ └── DelayConnectingHttpSocketAdapterTest.cs
├── .gitignore
├── src
└── Microsoft.VisualStudio.Web.BrowserLink
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── StaticTaskResult.cs
│ ├── Microsoft.VisualStudio.Web.BrowserLink.csproj
│ ├── BrowserLinkMiddlewareFactory.cs
│ ├── SendFilesWrapper.cs
│ ├── PathUtil.cs
│ ├── NativeMethods.cs
│ ├── FailedConnectionHttpSocketAdapter.cs
│ ├── ScriptInjectionFilterContext.cs
│ ├── ContentTypeUtil.cs
│ ├── PageExecutionContext.cs
│ ├── BrowserLinkExtensions.cs
│ ├── HostConnectionData.cs
│ ├── TaskHelpers.cs
│ ├── HttpAdapterRequestStream.cs
│ ├── PageExecutionListenerFeature.cs
│ ├── BrowserLinkMiddleWareUtil.cs
│ ├── MappingDataWriter.cs
│ ├── DelayConnectingHttpSocketAdapter.cs
│ ├── baseline.netcore.json
│ ├── SocketAdapter.cs
│ ├── Common
│ └── ArteryConstants.cs
│ ├── SocketReader.cs
│ ├── TextWriterDecorator.cs
│ ├── BrowserLinkMiddleWare.cs
│ ├── ScriptInjectionFilterStream.cs
│ └── RevolvingBuffers.cs
├── Directory.Build.targets
├── version.props
├── SECURITY.md
├── .gitattributes
├── Directory.Build.props
├── BrowserLink.sln
├── run.ps1
├── run.sh
└── LICENSE.txt
/korebuild-lock.txt:
--------------------------------------------------------------------------------
1 | version:3.0.0-alpha1-20181004.7
2 | commithash:27fabdaf2b1d4753c3d2749581694ca65d78f7f2
3 |
--------------------------------------------------------------------------------
/NuGetPackageVerifier.json:
--------------------------------------------------------------------------------
1 | {
2 | "Default": {
3 | "rules": [
4 | "DefaultCompositeRule"
5 | ]
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/korebuild.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/master/tools/korebuild.schema.json",
3 | "channel": "master"
4 | }
5 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ======
3 |
4 | Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo.
5 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | BrowserLink
2 | =====
3 |
4 | This project is part of ASP.NET Core and Visual Studio. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo.
5 |
--------------------------------------------------------------------------------
/run.cmd:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' %*; exit $LASTEXITCODE"
3 |
--------------------------------------------------------------------------------
/CODE-OF-CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | This project has adopted the code of conduct defined by the Contributor Covenant
4 | to clarify expected behavior in our community.
5 |
6 | For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).
7 |
--------------------------------------------------------------------------------
/.vsts-pipelines/builds/ci-internal.yml:
--------------------------------------------------------------------------------
1 | trigger:
2 | - main
3 | - release/*
4 |
5 | resources:
6 | repositories:
7 | - repository: buildtools
8 | type: git
9 | name: aspnet-BuildTools
10 | ref: refs/heads/master
11 |
12 | phases:
13 | - template: .vsts-pipelines/templates/project-ci.yml@buildtools
14 |
--------------------------------------------------------------------------------
/.vsts-pipelines/builds/ci-public.yml:
--------------------------------------------------------------------------------
1 | trigger:
2 | - main
3 | - release/*
4 |
5 | # See https://github.com/aspnet/BuildTools
6 | resources:
7 | repositories:
8 | - repository: buildtools
9 | type: github
10 | endpoint: DotNet-Bot GitHub Connection
11 | name: aspnet/BuildTools
12 | ref: refs/heads/master
13 |
14 | phases:
15 | - template: .vsts-pipelines/templates/project-ci.yml@buildtools
16 |
--------------------------------------------------------------------------------
/test/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | netcoreapp2.2
6 | $(DeveloperBuildTestTfms)
7 |
8 | $(StandardTestTfms);net461
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Oo]bj/
2 | [Bb]in/
3 | TestResults/
4 | .nuget/
5 | .testPublish/
6 | *.sln.ide/
7 | _ReSharper.*/
8 | packages/
9 | artifacts/
10 | .build/
11 | PublishProfiles/
12 | *.user
13 | *.suo
14 | *.cache
15 | *.docstates
16 | _ReSharper.*
17 | nuget.exe
18 | project.lock.json
19 | *net45.csproj
20 | *net451.csproj
21 | *k10.csproj
22 | *.psess
23 | *.vsp
24 | *.pidb
25 | *.userprefs
26 | *DS_Store
27 | *.ncrunchsolution
28 | *.*sdf
29 | *.ipch
30 | .vs/
31 | global.json
32 |
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Runtime.CompilerServices;
5 |
6 | [assembly: InternalsVisibleTo("Microsoft.VisualStudio.Web.BrowserLink.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
7 |
8 |
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/StaticTaskResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.VisualStudio.Web.BrowserLink
7 | {
8 | internal static class StaticTaskResult
9 | {
10 | public static readonly Task True = Task.FromResult(true);
11 | public static readonly Task False = Task.FromResult(false);
12 | public static readonly Task NullString = Task.FromResult((string)null);
13 | public static readonly Task Complete = True;
14 |
15 | public static readonly Task HttpInternalServerError = Task.FromResult(500);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(MicrosoftNETCoreApp20PackageVersion)
4 | $(MicrosoftNETCoreApp21PackageVersion)
5 | $(MicrosoftNETCoreApp22PackageVersion)
6 | $(NETStandardLibrary20PackageVersion)
7 |
8 | 99.9
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/Microsoft.VisualStudio.Web.BrowserLink.Test/Microsoft.VisualStudio.Web.BrowserLink.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(StandardTestTfms)
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/version.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 3.0.0
4 | alpha1
5 | $(VersionPrefix)
6 | $(VersionPrefix)-$(VersionSuffix)-final
7 | t000
8 | a-
9 | $(FeatureBranchVersionPrefix)$(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-'))
10 | $(VersionSuffix)-$(BuildNumber)
11 |
12 |
13 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | The .NET Core and ASP.NET Core support policy, including supported versions can be found at the [.NET Core Support Policy Page](https://dotnet.microsoft.com/platform/support/policy/dotnet-core).
6 |
7 | ## Reporting a Vulnerability
8 |
9 | Security issues and bugs should be reported privately to the Microsoft Security Response Center (MSRC), either by emailing secure@microsoft.com or via the portal at https://msrc.microsoft.com.
10 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your
11 | original message. Further information, including the MSRC PGP key, can be found in the [MSRC Report an Issue FAQ](https://www.microsoft.com/en-us/msrc/faqs-report-an-issue).
12 |
13 | Reports via MSRC may qualify for the .NET Core Bug Bounty. Details of the .NET Core Bug Bounty including terms and conditions are at [https://aka.ms/corebounty](https://aka.ms/corebounty).
14 |
15 | Please do not open issues for anything you think might have a security implication.
16 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.doc diff=astextplain
2 | *.DOC diff=astextplain
3 | *.docx diff=astextplain
4 | *.DOCX diff=astextplain
5 | *.dot diff=astextplain
6 | *.DOT diff=astextplain
7 | *.pdf diff=astextplain
8 | *.PDF diff=astextplain
9 | *.rtf diff=astextplain
10 | *.RTF diff=astextplain
11 |
12 | *.jpg binary
13 | *.png binary
14 | *.gif binary
15 |
16 | *.cs text=auto diff=csharp
17 | *.vb text=auto
18 | *.resx text=auto
19 | *.c text=auto
20 | *.cpp text=auto
21 | *.cxx text=auto
22 | *.h text=auto
23 | *.hxx text=auto
24 | *.py text=auto
25 | *.rb text=auto
26 | *.java text=auto
27 | *.html text=auto
28 | *.htm text=auto
29 | *.css text=auto
30 | *.scss text=auto
31 | *.sass text=auto
32 | *.less text=auto
33 | *.js text=auto
34 | *.lisp text=auto
35 | *.clj text=auto
36 | *.sql text=auto
37 | *.php text=auto
38 | *.lua text=auto
39 | *.m text=auto
40 | *.asm text=auto
41 | *.erl text=auto
42 | *.fs text=auto
43 | *.fsx text=auto
44 | *.hs text=auto
45 |
46 | *.csproj text=auto
47 | *.vbproj text=auto
48 | *.fsproj text=auto
49 | *.dbproj text=auto
50 | *.sln text=auto eol=crlf
51 |
52 | *.sh eol=lf
53 |
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/Microsoft.VisualStudio.Web.BrowserLink.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | A middleware that supports creating a communication channel between the development environment and one or more web browsers.
5 | netstandard2.0
6 | true
7 | aspnetcore;browserlink
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Microsoft Visual Studio
12 | https://github.com/aspnet/BrowserLink
13 | git
14 | $(MSBuildThisFileDirectory)
15 | $(MSBuildThisFileDirectory)build\Key.snk
16 | true
17 | true
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/BrowserLinkMiddlewareFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Http;
5 |
6 | namespace Microsoft.VisualStudio.Web.BrowserLink
7 | {
8 | ///
9 | /// An instance of this class is created when Browser Link is registered
10 | /// in an application. It's job is to remember the base path of the
11 | /// application, so it can be passed on to the BrowserLinkMiddleware.
12 | ///
13 | internal class BrowserLinkMiddlewareFactory
14 | {
15 | private string _applicationBasePath;
16 |
17 | internal BrowserLinkMiddlewareFactory(string applicationBasePath)
18 | {
19 | _applicationBasePath = applicationBasePath;
20 | }
21 |
22 | public RequestDelegate CreateBrowserLinkMiddleware(RequestDelegate next)
23 | {
24 | BrowserLinkMiddleware middleware = new BrowserLinkMiddleware(_applicationBasePath, next);
25 |
26 | return middleware.Invoke;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/SendFilesWrapper.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Microsoft.AspNetCore.Http;
5 | using Microsoft.AspNetCore.Http.Features;
6 |
7 | namespace Microsoft.VisualStudio.Web.BrowserLink
8 | {
9 | internal class SendFilesWrapper : IHttpSendFileFeature
10 | {
11 | private HttpResponse _response;
12 | private IHttpSendFileFeature _wrapped;
13 |
14 | internal SendFilesWrapper(IHttpSendFileFeature wrapped, HttpResponse response)
15 | {
16 | _wrapped = wrapped;
17 | _response = response;
18 | }
19 |
20 | async Task IHttpSendFileFeature.SendFileAsync(string path, long offset, long? count, CancellationToken cancellation)
21 | {
22 | // TODO: Send mapping data to VS
23 |
24 | if (_wrapped != null)
25 | {
26 | await _wrapped.SendFileAsync(path, offset, count, cancellation);
27 | return;
28 | }
29 |
30 | using (Stream readStream = File.OpenRead(path))
31 | {
32 | readStream.Seek(offset, SeekOrigin.Begin);
33 |
34 | await readStream.CopyToAsync(_response.Body, 4096, cancellation);
35 | }
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/test/Microsoft.VisualStudio.Web.BrowserLink.Test/AssertWithMessage.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Microsoft.VisualStudio.Web.BrowserLink
4 | {
5 | ///
6 | /// These wrappers accept useful messages about Assert failures, but I'm
7 | /// not sure how to output them to Xunit.
8 | ///
9 | internal static class AssertWithMessage
10 | {
11 | public static void Equal(string expected, string actual, string messageFormat, params object[] messageArgs)
12 | {
13 | Assert.Equal(expected, actual);
14 | }
15 |
16 | public static void Equal(int expected, int actual, string messageFormat, params object[] messageArgs)
17 | {
18 | Assert.Equal(expected, actual);
19 | }
20 |
21 | public static void Equal(bool expected, bool actual, string messageFormat, params object[] messageArgs)
22 | {
23 | Assert.Equal(expected, actual);
24 | }
25 |
26 | public static void Null(object @object, string messageFormat, params object[] messageArgs)
27 | {
28 | Assert.Null(@object);
29 | }
30 |
31 | public static void NotNull(object @object, string messageFormat, params object[] messageArgs)
32 | {
33 | Assert.NotNull(@object);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/PathUtil.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 |
6 | namespace Microsoft.VisualStudio.Web.BrowserLink
7 | {
8 | ///
9 | /// Helpers for dealing with file paths
10 | ///
11 | internal static class PathUtil
12 | {
13 | ///
14 | /// Takes a path, and returns an equivalent path in a format that can
15 | /// be used for comparisons.
16 | ///
17 | public static string NormalizeDirectoryPath(string path)
18 | {
19 | if (path.Contains("/"))
20 | {
21 | path = path.Replace('/', '\\');
22 | }
23 |
24 | if (!path.EndsWith("\\"))
25 | {
26 | path += "\\";
27 | }
28 |
29 | return path.ToLowerInvariant();
30 | }
31 |
32 | ///
33 | /// Compares two paths, assuming they were both produced by NormalizeDirectoryPath
34 | ///
35 | /// True if the paths are equivalent
36 | public static bool CompareNormalizedPaths(string path1, string path2)
37 | {
38 | return String.Equals(path1, path2, StringComparison.Ordinal);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Runtime.InteropServices;
6 |
7 | namespace Microsoft.VisualStudio.Web.BrowserLink
8 | {
9 | internal static class NativeMethods
10 | {
11 |
12 | [DllImport("urlmon.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
13 | internal static extern int FindMimeFromData(
14 | IntPtr pBC,
15 | [MarshalAs(UnmanagedType.LPWStr)] string pwzUrl,
16 | [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1, SizeParamIndex = 3)]
17 | byte[] pBuffer,
18 | int cbSize,
19 | [MarshalAs(UnmanagedType.LPWStr)] string pwzMimeProposed,
20 | int dwMimeFlags,
21 | out IntPtr ppwzMimeOut,
22 | int dwReserved);
23 |
24 |
25 | [DllImport("kernel32.dll", SetLastError = false, CharSet = CharSet.Unicode)]
26 | internal static extern IntPtr OpenFileMapping(
27 | uint dwDesiredAccess,
28 | bool bInheritHandle,
29 | string lpName);
30 |
31 | [DllImport("kernel32.dll", SetLastError = false)]
32 | internal static extern bool CloseHandle(
33 | IntPtr hHandle);
34 |
35 | }
36 | }
--------------------------------------------------------------------------------
/test/Microsoft.VisualStudio.Web.BrowserLink.Test/PathUtilTest.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Microsoft.VisualStudio.Web.BrowserLink
4 | {
5 | public class PathUtilTest
6 | {
7 | [Fact]
8 | public void NormalizeDirectoryPath_ChangesSlashesToBackslashes()
9 | {
10 | // Arrange
11 | string input = @"c:/my/project/path/";
12 | string expected = @"c:\my\project\path\";
13 |
14 | // Act
15 | string result = PathUtil.NormalizeDirectoryPath(input);
16 |
17 | // Assert
18 | Assert.Equal(expected, result);
19 | }
20 |
21 | [Fact]
22 | public void NormalizeDirectoryPath_AddsTrailingSlash()
23 | {
24 | // Arrange
25 | string input = @"c:/my/project/path";
26 | string expected = @"c:\my\project\path\";
27 |
28 | // Act
29 | string result = PathUtil.NormalizeDirectoryPath(input);
30 |
31 | // Assert
32 | Assert.Equal(expected, result);
33 | }
34 |
35 | [Fact]
36 | public void NormalizeDirectoryPath_ChangesToLowercase()
37 | {
38 | // Arrange
39 | string input = @"C:/My/Project/Path/";
40 | string expected = @"c:\my\project\path\";
41 |
42 | // Act
43 | string result = PathUtil.NormalizeDirectoryPath(input);
44 |
45 | // Assert
46 | Assert.Equal(expected, result);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Microsoft.VisualStudio.Web.BrowserLink/FailedConnectionHttpSocketAdapter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Threading.Tasks;
6 |
7 | namespace Microsoft.VisualStudio.Web.BrowserLink
8 | {
9 | ///
10 | /// Null-object implementation of a connection, which stands in for a connection
11 | /// that could not be created.
12 | ///
13 | internal class FailedConnectionHttpSocketAdapter : IHttpSocketAdapter
14 | {
15 | void IHttpSocketAdapter.AddRequestHeader(string name, string value)
16 | {
17 | }
18 |
19 | Task IHttpSocketAdapter.CompleteRequest()
20 | {
21 | return StaticTaskResult.Complete;
22 | }
23 |
24 | void IDisposable.Dispose()
25 | {
26 | }
27 |
28 | Task IHttpSocketAdapter.GetResponseHeader(string headerName)
29 | {
30 | return StaticTaskResult.NullString;
31 | }
32 |
33 | Task IHttpSocketAdapter.GetResponseStatusCode()
34 | {
35 | return StaticTaskResult.HttpInternalServerError;
36 | }
37 |
38 | void IHttpSocketAdapter.SetResponseHandler(ResponseHandler handler)
39 | {
40 | }
41 |
42 | Task IHttpSocketAdapter.WaitForResponseComplete()
43 | {
44 | return StaticTaskResult.Complete;
45 | }
46 |
47 | Task IHttpSocketAdapter.WriteToRequestAsync(byte[] buffer, int offset, int count)
48 | {
49 | return StaticTaskResult.Complete;
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/test/Microsoft.VisualStudio.Web.BrowserLink.Test/MockScriptInjectionFilterContext.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Text;
3 |
4 | namespace Microsoft.VisualStudio.Web.BrowserLink
5 | {
6 | public class MockScriptInjectionFilterContext : IScriptInjectionFilterContext
7 | {
8 | private MemoryStream _responseBody = new MemoryStream();
9 | private string _requestPath;
10 | private string _contentType;
11 |
12 | public MockScriptInjectionFilterContext(string requestPath = "http://localhost:2468/Default.html", string contentType = "text/html")
13 | {
14 | _requestPath = requestPath;
15 | _contentType = contentType;
16 | }
17 |
18 | public string GetResponseBody(Encoding encoding)
19 | {
20 | long originalPosition = _responseBody.Position;
21 |
22 | try
23 | {
24 | _responseBody.Seek(0, SeekOrigin.Begin);
25 |
26 | byte[] buffer = new byte[_responseBody.Length];
27 | _responseBody.Read(buffer, 0, buffer.Length);
28 |
29 | return encoding.GetString(buffer, 0, buffer.Length);
30 | }
31 | finally
32 | {
33 | _responseBody.Position = originalPosition;
34 | }
35 | }
36 |
37 | string IScriptInjectionFilterContext.RequestPath
38 | {
39 | get { return _requestPath; }
40 | }
41 |
42 | Stream IScriptInjectionFilterContext.ResponseBody
43 | {
44 | get { return _responseBody; }
45 | }
46 |
47 | string IScriptInjectionFilterContext.ResponseContentType
48 | {
49 | get { return _contentType; }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/test/Microsoft.VisualStudio.Web.BrowserLink.Test/MockResponseHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Threading.Tasks;
4 | using Xunit;
5 |
6 | namespace Microsoft.VisualStudio.Web.BrowserLink
7 | {
8 | internal class MockResponseHandler
9 | {
10 | private StringBuilder _response = new StringBuilder();
11 | private Encoding _encoding = Encoding.ASCII;
12 |
13 | private TaskCompletionSource