Skip to content

Commit

Permalink
@dmetzgar Enables Bridge Test. Fixes dotnet#43
Browse files Browse the repository at this point in the history
  • Loading branch information
sajayantony committed Jul 13, 2015
1 parent 7c49c66 commit 6307e5f
Show file tree
Hide file tree
Showing 109 changed files with 2,944 additions and 315 deletions.
2 changes: 1 addition & 1 deletion BuildWCFTestService.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if not defined VisualStudioVersion (
:EnvSet

:: Log build command line
set _buildproj=src\System.Private.ServiceModel\tests\Scenarios\SelfHostWcfService\wcfservice.csproj
set _buildproj=tools\Bridge\Bridge.sln
set _buildlog=%~dp0msbuildWCFTestService.log
set _buildprefix=echo
set _buildpostfix=^> "%_buildlog%"
Expand Down
2 changes: 1 addition & 1 deletion setupfiles/SetupWCFTestService.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pushd %1
certutil -addstore -f root RootCATest.cer
certutil -f -p test -importpfx "WcfTestServer.pfx"
netsh http add sslcert ipport=0.0.0.0:44285 certhash=1d85a3f6cd2c022c5ca54e5cb200a47f89ba0d3d appid={00000000-0000-0000-0000-000000000000}
start ..\src\System.Private.ServiceModel\tests\Scenarios\SelfHostWcfService\bin\Debug\wcfservice.exe
start powershell -ExecutionPolicy Bypass -File ..\tools\Bridge\bin\ensureBridge.ps1
exit
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

public static class BaseAddress
{
// base address never used for end-to-end communication
Expand Down Expand Up @@ -52,8 +50,8 @@ public static class BaseAddress
#endif

// Base address for Net.TCP endpoints
public const string TcpBaseAddress = "net.tcp://localhost:809/WindowsCommunicationFoundation";
public const string TcpDuplexAddress = "net.tcp://localhost:810/WindowsCommunicationFoundation";
public static string TcpBaseAddress = "net.tcp://localhost:809/WindowsCommunicationFoundation";
}


148 changes: 148 additions & 0 deletions src/System.Private.ServiceModel/tests/Common/src/BridgeClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;

namespace System.ServiceModel.Tests.Common
{
public static class BridgeClient
{
private static Dictionary<string, string> _Resources = new Dictionary<string, string>();
private static BridgeState _BridgeStatus = BridgeState.NotStarted;
private static Dictionary<string, string> _BaseAddresses = null;

private static string BridgeBaseAddress
{
// TODO: Pull this address from msbuild props, env vars, or config passed into xunit.
get { return "http://localhost:44283"; }
}

static BridgeClient()
{
if (_BridgeStatus == BridgeState.NotStarted)
{
MakeConfigRequest();
}
else if (_BridgeStatus == BridgeState.Faulted)
{
throw new Exception("Bridge is not running");
}
}

public static string GetResourceAddress(string resourceName)
{
string resourceAddress = null;
if (_BridgeStatus == BridgeState.Started && !_Resources.TryGetValue(resourceName, out resourceAddress))
{
resourceAddress = MakeResourcePutRequest(resourceName);
_Resources.Add(resourceName, resourceAddress);
}

return resourceAddress;
}

public static string GetBaseAddress(string resourceName, string name)
{
string resourceAddress = null;
if (_BridgeStatus == BridgeState.Started)
{
if (_BaseAddresses == null)
{
_BaseAddresses = new Dictionary<string, string>();
string response = MakeResourceGetRequest(resourceName);

var reader = new JsonTextReader(new StringReader(response));
while (reader.Read())
{
if (reader.TokenType == JsonToken.String)
{
_BaseAddresses.Add(reader.Path, reader.Value as string);
}
}
}

_BaseAddresses.TryGetValue(name, out resourceAddress);
}

return resourceAddress;
}

private static void MakeConfigRequest()
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(BridgeBaseAddress);
var content = new StringContent(
@"{ resourcesDirectory : ""WcfService"" }",
Encoding.UTF8,
"application/json");
try
{
var response = httpClient.PostAsync("/config/", content).Result;
if (!response.IsSuccessStatusCode)
throw new Exception("Unexpected status code: " + response.StatusCode);
_BridgeStatus = BridgeState.Started;
}
catch (Exception exc)
{
_BridgeStatus = BridgeState.Faulted;
throw new Exception("Bridge is not running", exc);
}
}
}

private static string MakeResourcePutRequest(string resourceName)
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(BridgeBaseAddress);
var content = new StringContent(
string.Format(@"{{ name : ""{0}"" }}", resourceName),
Encoding.UTF8,
"application/json");
try
{
var response = httpClient.PutAsync("/resource/", content).Result;
if (!response.IsSuccessStatusCode)
throw new Exception("Unexpected status code: " + response.StatusCode);

var reader = new JsonTextReader(new StringReader(response.Content.ReadAsStringAsync().Result));
while (reader.Read())
{
if (reader.TokenType == JsonToken.String && reader.Path == "details")
{
return reader.Value as string;
}
}
}
catch (Exception exc)
{
throw new Exception("Unable to start resource: " + resourceName, exc);
}
}

return null;
}

private static string MakeResourceGetRequest(string resourceName)
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(BridgeBaseAddress);
var response = httpClient.GetAsync("/resource/" + resourceName).Result;
if (!response.IsSuccessStatusCode)
throw new Exception("Unexpected status code: " + response.StatusCode);

return response.Content.ReadAsStringAsync().Result;
}
}

enum BridgeState
{
NotStarted,
Started,
Faulted,
}
}
}
41 changes: 24 additions & 17 deletions src/System.Private.ServiceModel/tests/Common/src/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,96 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.ServiceModel.Tests.Common;

public static partial class Endpoints
{
// HTTP Addresses
public static string DefaultCustomHttp_Address
{
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.DefaultCustomHttpResource"); }
}

public static string HttpBaseAddress_Basic
{
get { return BaseAddress.HttpBaseAddress + "/Basic"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.BasicHttpResource"); }
}

public static string HttpBaseAddress_NetHttp
{
get { return BaseAddress.HttpBaseAddress + "/NetHttp"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.NetHttpResource"); }
}

public static string HttpSoap11_Address
{
get { return BaseAddress.HttpBaseAddress + "/http-soap11"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpSoap11Resource"); }
}

public static string HttpSoap12_Address
{
get { return BaseAddress.HttpBaseAddress + "/http-soap12"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpSoap12Resource"); }
}

public static string HttpBinary_Address
{
get { return BaseAddress.HttpBaseAddress + "/http-binary"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpBinaryResource"); }
}

// HTTPS Addresses
public static string Https_BasicAuth_Address
{
get { return BaseAddress.HttpsBasicBaseAddress + "/CustomerUserName/https-basic"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.BasicAuthResource"); }
}

public static string Https_DigestAuth_Address
{
get { return BaseAddress.HttpsDigestBaseAddress + "/https-digest"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpsDigestResource"); }
}

public static string Https_NtlmAuth_Address
{
get { return BaseAddress.HttpsNtlmBaseAddress + "/https-ntlm"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpsNtlmResource"); }
}

public static string Https_WindowsAuth_Address
{
get { return BaseAddress.HttpsWindowsBaseAddress + "/https-windows"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpsWindowsResource"); }
}

public static string Https_DefaultBinding_Address
{
get { return BaseAddress.HttpsBaseAddress + "/basicHttps"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.BasicHttpsResource"); }
}

public static string HttpsSoap11_Address
{
get { return BaseAddress.HttpsBaseAddress + "/https-soap11"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpsSoap11Resource"); }
}

public static string HttpsSoap12_Address
{
get { return BaseAddress.HttpsBaseAddress + "/https-soap12"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.HttpsSoap12Resource"); }
}

public static string HttpUrlNotFound_Address
{
get { return BaseAddress.HttpServerBaseAddress + "/UnknownUrl.htm"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.EndpointNotFoundResource") + "/UnknownUrl.htm"; }
}

public static string HttpProtocolError_Address
{
get { return BaseAddress.HttpBaseAddress + "/UnknownProtocolUrl.htm"; }
get { return Endpoints.DefaultCustomHttp_Address + "/UnknownProtocolUrl.htm"; }
}

// net.tcp Addresses
public static string Tcp_DefaultBinding_Address
{
get { return BaseAddress.TcpBaseAddress + "/tcp-default"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.TcpDefaultResource"); }
}

public static string Tcp_NoSecurity_Address
{
get { return BaseAddress.TcpBaseAddress + "/tcp-nosecurity"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.TcpNoSecurityResource"); }
}

public static string Tcp_NoSecurity_Callback_Address
Expand All @@ -94,6 +101,6 @@ public static string Tcp_NoSecurity_Callback_Address

public static string Tcp_CustomBinding_NoSecurity_Text_Address
{
get { return BaseAddress.TcpBaseAddress + "/tcp-custombinding-nosecurity-text"; }
get { return BridgeClient.GetResourceAddress("WcfService.TestResources.TcpNoSecurityTextResource"); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProjectGuid>{E896294A-AB4A-4AF5-A01C-A19E3972EFF9}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(UseFiddler)' == 'true'">
<DefineConstants>$(DefineConstants);USE_FIDDLER</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"xunit": "2.0.0-beta5-build2785",
"xunit.abstractions.netcore": "1.0.0-prerelease",
"xunit.assert": "2.0.0-beta5-build2785",
"xunit.core.netcore": "1.0.1-prerelease"
"xunit.core.netcore": "1.0.1-prerelease",
"Newtonsoft.Json": "6.0.6"
},
"frameworks": {
"dnxcore50": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/6.0.6": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+aspnetcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+aspnetcore50/Newtonsoft.Json.dll": {}
}
},
"System.Collections/4.0.10-beta-23024": {
"dependencies": {
"System.Runtime": "4.0.20-beta-23024"
Expand Down Expand Up @@ -1114,6 +1122,29 @@
"ref/net46/Microsoft.Win32.Primitives.dll"
]
},
"Newtonsoft.Json/6.0.6": {
"sha512": "w26uZNyCG5VeoKiEOJ4+9/o8koSofLKwHl7WLreIcp0U6r57L7WiRXmjp8MTKFw6dYNZ9AE0lw69WYbIhUsU9Q==",
"files": [
"Newtonsoft.Json.6.0.6.nupkg",
"Newtonsoft.Json.6.0.6.nupkg.sha512",
"Newtonsoft.Json.nuspec",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/netcore45/Newtonsoft.Json.dll",
"lib/netcore45/Newtonsoft.Json.xml",
"lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll",
"lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml",
"lib/portable-net45+wp80+win8+wpa81+aspnetcore50/Newtonsoft.Json.dll",
"lib/portable-net45+wp80+win8+wpa81+aspnetcore50/Newtonsoft.Json.xml",
"tools/install.ps1"
]
},
"System.Collections/4.0.10-beta-23024": {
"serviceable": true,
"sha512": "2ISUf3MQt7JbeT6kXg36qY3fnkjykPXccHcBP0qyTc5vEjbLihC7KCxkHPFJWteKR8lvvSF3+8ES5J34VqezmQ==",
Expand Down Expand Up @@ -2894,7 +2925,8 @@
"xunit >= 2.0.0-beta5-build2785",
"xunit.abstractions.netcore >= 1.0.0-prerelease",
"xunit.assert >= 2.0.0-beta5-build2785",
"xunit.core.netcore >= 1.0.1-prerelease"
"xunit.core.netcore >= 1.0.1-prerelease",
"Newtonsoft.Json >= 6.0.6"
],
"DNXCore,Version=v5.0": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestCategories>OuterLoop</TestCategories>
</PropertyGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
Expand All @@ -9,7 +12,6 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Binding.Custom.Tests</RootNamespace>
<AssemblyName>Binding.Custom.Tests</AssemblyName>
<TestCategories>OuterLoop</TestCategories>
<SignAssembly>false</SignAssembly>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProjectGuid>{EDC88742-E7BF-4B7A-9DE2-55055B81B8F2}</ProjectGuid>
Expand Down
Loading

0 comments on commit 6307e5f

Please sign in to comment.