Permalink
Browse files

Use ILMerge to pull IronFoundry.dll dependencies into the dll so they…

… don't collide with other versions in consuming projects. This required removing the InternalVisiblesTo attribute that exposed internals to IronFoundry.Test( because otherwise the ilmerged code would collide with public versions), which in turn required refactoring some of the code and tests to not rely on internal access.
  • Loading branch information...
1 parent 0c13ca1 commit ae83274c147ce437df281fb781b3a054ae428224 @SaintGimp SaintGimp committed Mar 11, 2013
@@ -130,7 +130,9 @@
</ItemGroup>
<ItemGroup>
<None Include="IronFoundry.snk" />
- <None Include="packages.config" />
+ <None Include="packages.config">
+ <SubType>Designer</SubType>
+ </None>
</ItemGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
@@ -146,6 +148,7 @@
<HintPath>..\..\lib\RestSharp\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
@@ -158,4 +161,12 @@
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
+ <PropertyGroup>
+ <PostBuildEvent>copy "$(TargetPath)" "$(TargetDir)premerge.dll"
+$(SolutionDir)packages\ilmerge.2.13.0307\ilmerge.exe /internalize /targetplatform:v4 /keyfile:$(SolutionDir)common\IronFoundry.snk /out:$(TargetDir)IronFoundry.dll $(TargetDir)premerge.dll $(TargetDir)ICSharpCode.SharpZipLib.dll $(TargetDir)Newtonsoft.Json.dll $(TargetDir)RestSharp.dll
+del $(TargetDir)premerge.dll
+del $(TargetDir)ICSharpCode.SharpZipLib.*
+del $(TargetDir)Newtonsoft.Json.*
+del $(TargetDir)RestSharp.*</PostBuildEvent>
+ </PropertyGroup>
</Project>
@@ -44,9 +44,9 @@ public VcapClient(Cloud cloud)
this.cloud = cloud;
}
- public VcapClient(Uri uri, IPAddress ipAddress)
+ public VcapClient(Uri uri, IPAddress ipAddress, int port = 80)
{
- credMgr = new VcapCredentialManager(uri, ipAddress);
+ credMgr = new VcapCredentialManager(uri, ipAddress, port);
}
public void ProxyAs(VcapUser user)
@@ -70,13 +70,6 @@ public Info GetInfo()
return helper.GetInfo();
}
- // TODO: we need a different DI-based design that doesn't require this method for testing
- public VcapRequest GetRequestForTesting()
- {
- var helper = new MiscHelper(proxyUser, credMgr);
- return helper.BuildInfoRequest();
- }
-
public void Target(string uri)
{
Target(uri, null);
@@ -30,6 +30,7 @@ public class VcapCredentialManager
private Uri currentTarget;
private IPAddress currentTargetIP;
+ private int currentTargetPort = 80;
public static Func<string, string> FileReaderFunc = fileName => File.ReadAllText(fileName);
public static Action<string, string> FileWriterAction = (fileName, text) => File.WriteAllText(fileName, text);
@@ -54,7 +55,7 @@ public VcapCredentialManager(Uri currentTarget) : this()
SetTarget(currentTarget);
}
- public VcapCredentialManager(Uri currentTarget, IPAddress currentTargetIP) : this()
+ public VcapCredentialManager(Uri currentTarget, IPAddress currentTargetIP, int currentTargetPort = 80) : this()
{
if (null == currentTarget)
{
@@ -65,6 +66,7 @@ public VcapCredentialManager(Uri currentTarget, IPAddress currentTargetIP) : thi
throw new ArgumentNullException("currentTargetIP");
}
SetTarget(currentTarget, currentTargetIP);
+ this.currentTargetPort = currentTargetPort;
}
public Uri CurrentTarget
@@ -77,6 +79,11 @@ public IPAddress CurrentTargetIP
get { return currentTargetIP; }
}
+ public int CurrentTargetPort
+ {
+ get { return currentTargetPort; }
+ }
+
public string CurrentToken
{
get
@@ -118,7 +118,7 @@ private RestClient BuildClient(bool useAuth, Uri uri = null)
string baseUrl = currentTargetUri.AbsoluteUri;
if (null != credentialManager.CurrentTargetIP)
{
- baseUrl = String.Format("{0}://{1}", Uri.UriSchemeHttp, credentialManager.CurrentTargetIP.ToString());
+ baseUrl = String.Format("{0}://{1}:{2}", Uri.UriSchemeHttp, credentialManager.CurrentTargetIP.ToString(), credentialManager.CurrentTargetPort);
requestHostHeader = currentTargetUri.Host;
}
@@ -219,21 +219,6 @@ private static RestRequest ProcessRequestArgs(RestRequest request, params object
}
return request;
}
-
- public RestClient Client
- {
- get { return client; }
- }
-
- public RestRequest Request
- {
- get { return request; }
- }
-
- public string RequestHostHeader
- {
- get { return requestHostHeader; }
- }
}
public class VcapRequest : VcapRequestBase
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="ilmerge" version="2.13.0307" targetFramework="net40-Client" />
<package id="Newtonsoft.Json" version="4.5.5" />
<package id="SharpZipLib" version="0.86.0" />
</packages>
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<configuration>
<startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
@@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IronFoundry.Test</RootNamespace>
<AssemblyName>IronFoundry.Test</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\ironfoundry\</SolutionDir>
<RestorePackages>true</RestorePackages>
+ <TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -24,6 +25,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -33,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
@@ -44,9 +47,6 @@
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.4.5.8\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
- <Reference Include="RestSharp, Version=103.1.0.0, Culture=neutral, PublicKeyToken=aed551a8db69a9bd, processorArchitecture=MSIL">
- <HintPath>..\..\lib\RestSharp\RestSharp.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
@@ -2,46 +2,43 @@
{
using System;
using System.Net;
- using IronFoundry.Utilities;
+ using System.Threading.Tasks;
using IronFoundry.Vcap;
- using RestSharp;
using Xunit;
public class VcapClientTests
{
+ private HttpListener httpListener;
+
[Fact]
public void Test_Using_Host_And_IPAddress()
{
- string ipStr = "10.0.0.1";
- string host = "api.vcap.me";
-
- var uri = new Uri("http://" + host);
- IPAddress ip;
- IPAddress.TryParse(ipStr, out ip);
- var client = new VcapClient(uri, ip);
- VcapRequest infoRequest = client.GetRequestForTesting();
-
- RestClient restClient = infoRequest.Client;
- RestRequest restRequest = infoRequest.Request;
+ IPAddress ip = IPAddress.Parse("127.0.0.1");
+ string host = "localhost";
- Assert.Equal("http://" + ipStr, restClient.BaseUrl);
- Assert.Equal(host, infoRequest.RequestHostHeader);
+ var listenTask = StartWebServer();
+ listenTask.ContinueWith(context =>
+ {
+ Assert.Equal(context.Result.Request.Headers["host"], host);
+ context.Result.Response.OutputStream.Close();
+ }).ContinueWith(context => StopWebServer());
- Assert.NotNull(restRequest.JsonSerializer);
- Assert.IsType<NewtonsoftJsonSerializer>(restRequest.JsonSerializer);
+ var uri = new Uri("http://" + host);
+ var client = new VcapClient(uri, ip, 12345);
+ client.GetInfo();
}
- [Fact(Skip="MANUAL")]
- public void Test_Using_Host_And_IPAddress_Against_Local()
+ private Task<HttpListenerContext> StartWebServer()
{
- string ipStr = "172.21.114.11";
- string host = "api.vcap.me";
+ httpListener = new HttpListener();
+ httpListener.Prefixes.Add("http://localhost:12345/");
+ httpListener.Start();
+ return httpListener.GetContextAsync();
+ }
- var uri = new Uri("http://" + host);
- IPAddress ip;
- IPAddress.TryParse(ipStr, out ip);
- var client = new VcapClient(uri, ip);
- client.Login("user@foo.com", "Password");
+ private void StopWebServer()
+ {
+ httpListener.Stop();
}
}
}

0 comments on commit ae83274

Please sign in to comment.