Skip to content

Commit

Permalink
Cleaned up solution and bugfix (#7) (#8)
Browse files Browse the repository at this point in the history
* New HttpMessageOptions class and AppVeyor changes.
- New HttpMessageOptions class so we can now also test for the HttpMethod (GET/POST, etc).
- Updated the AppVeyor settings to be more automated and helpful.
- Fix up badges.
- Moved files to standard folder names.
- Dependency version is exact, not a range.
- Code cleanup.
- 🐛 Fixed string.Format(..) bug.
- Updated AppVeyor notes.
  • Loading branch information
PureKrome authored Nov 7, 2016
1 parent 7d1fef9 commit 82af344
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 213 deletions.
221 changes: 182 additions & 39 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,39 +1,182 @@
*.obj
*.pdb
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
*.lib
*.sbr
*.scc
[Bb]in
[Dd]ebug*/
obj/
[Rr]elease*/
_ReSharper*/
*.[Pp]ublish.xml
*.resharper*
AppData/
App_Data/
*.log.*
[Ll]ogs/
[Dd]ata/
[Pp]ackages/
[Tt]humbs.db
[Tt]est[Rr]esult*
[Bb]uild[Ll]og.*
*.sln.DotSettings.*
*.ncrunchproject
*.ncrunchsolution
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# DNX
project.lock.json
project.fragment.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# Web workbench (sass)
.sass-cache/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat
4 changes: 2 additions & 2 deletions HttpClient.Helpers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers", "Code\HttpClient.Helpers\HttpClient.Helpers.csproj", "{CD2C1552-4AF1-4DC2-B0E6-90CE48D38F27}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers", "src\HttpClient.Helpers\HttpClient.Helpers.csproj", "{CD2C1552-4AF1-4DC2-B0E6-90CE48D38F27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers.Tests", "Code\HttpClient.Helpers.Tests\HttpClient.Helpers.Tests.csproj", "{B3672F4D-77A9-4E91-83FC-E017E38A0762}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers.Tests", "tests\HttpClient.Helpers.Tests\HttpClient.Helpers.Tests.csproj", "{B3672F4D-77A9-4E91-83FC-E017E38A0762}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# - All development is done in a fork.
# - Pull requests are merged into dev and it auto publishes
# to the myget pre-release 'pk-development' feed.
# - When publishing to master we just merge dev to master.
# - ASKJDHAKJSDHASj
# - When publishing to master we just merge dev to master -but- no NuGet is made.
# - To publish a live NuGet package, create a tag on master branch.
#


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace WorldDomination.Net.Http
public class FakeHttpMessageHandler : HttpClientHandler
{
private readonly HttpRequestException _exception;
private readonly IDictionary<string, HttpMessageOptions> _lotsOfOptions = new Dictionary<string, HttpMessageOptions>();

private readonly IDictionary<string, HttpMessageOptions> _lotsOfOptions =
new Dictionary<string, HttpMessageOptions>();

/// <summary>
/// A fake message handler.
Expand Down Expand Up @@ -48,8 +50,7 @@ public FakeHttpMessageHandler(string requestUri, HttpResponseMessage httpRespons

// _responses = httpResponseMessages;
//}

public FakeHttpMessageHandler(HttpMessageOptions options) : this(new List<HttpMessageOptions> { options})
public FakeHttpMessageHandler(HttpMessageOptions options) : this(new List<HttpMessageOptions> {options})
{
}

Expand All @@ -71,12 +72,12 @@ public FakeHttpMessageHandler(IDictionary<string, HttpResponseMessage> responses
HttpResponseMessage = item.Value
});

Initialize(options);
Initialize(options.ToArray());
}

public FakeHttpMessageHandler(IEnumerable<HttpMessageOptions> lotsOfOptions)
{
Initialize(lotsOfOptions);
Initialize(lotsOfOptions.ToArray());
}

/// <summary>
Expand All @@ -101,7 +102,7 @@ public FakeHttpMessageHandler(HttpRequestException exception)
{
if (exception == null)
{
throw new ArgumentNullException("exception");
throw new ArgumentNullException(nameof(exception));
}

_exception = exception;
Expand All @@ -124,7 +125,7 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
var tcs = new TaskCompletionSource<HttpResponseMessage>();

HttpMessageOptions options;
var requestUri = request.RequestUri.ToString();
var requestUri = request.RequestUri.AbsoluteUri;

// If we don't care
var uniqueKey = CreateDictionaryKey(requestUri, request.Method);
Expand Down Expand Up @@ -155,14 +156,7 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
: string.Join(";", _lotsOfOptions.Values);

var errorMessage =
string.Format(
"No HttpResponseMessage found for the Request Uri: {0}. Please provide one in the FakeHttpMessageHandler constructor Or use a '*' for any request uri. Search-Key: '{1}. Setup: {2} responses: {3}",
request.RequestUri,
requestUri,
!_lotsOfOptions.Any()
? "- no responses -"
: _lotsOfOptions.Count.ToString(),
responsesText);
$"No HttpResponseMessage found for the Request Uri: {request.RequestUri}. Please provide one in the FakeHttpMessageHandler constructor Or use a '*' for any request uri. Search-Key: '{requestUri}. Setup: {(!_lotsOfOptions.Any() ? "- no responses -" : _lotsOfOptions.Count.ToString())} responses: {responsesText}";
throw new InvalidOperationException(errorMessage);
}
}
Expand All @@ -185,7 +179,7 @@ public static HttpResponseMessage GetStringHttpResponseMessage(string content,
};
}

private void Initialize(IEnumerable<HttpMessageOptions> lotsOfOptions)
private void Initialize(ICollection<HttpMessageOptions> lotsOfOptions)
{
if (lotsOfOptions == null)
{
Expand All @@ -207,7 +201,7 @@ private void Initialize(IEnumerable<HttpMessageOptions> lotsOfOptions)
private static string CreateDictionaryKey(string requestUri, HttpMethod httpMethod)
{
var httpMethodText = httpMethod?.ToString() ?? "*";
return string.Format($"{requestUri}||{httpMethodText}");
return $"{requestUri}||{httpMethodText}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<language>en-AU</language>
<tags>httpclient worlddomination worldomination unicorn magicalunicorn magical-unicorn</tags>
<dependencies>
<dependency id="Microsoft.Net.Http" version="[2.2.29, 3.0.0)" />
<dependency id="Microsoft.Net.Http" version="2.2.29" />
</dependencies>
</metadata>
<files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class HttpClientFactory
private static readonly Lazy<Dictionary<string, MessageHandlerItem>> MessageHandlers =
new Lazy<Dictionary<string, MessageHandlerItem>>();

public static void AddMessageHandler(HttpMessageHandler messageHandler,
public static void AddMessageHandler(HttpMessageHandler messageHandler,
string key,
bool disposeHandler = true)
{
Expand All @@ -25,7 +25,8 @@ public static void AddMessageHandler(HttpMessageHandler messageHandler,

if (MessageHandlers.Value.ContainsKey(key))
{
var errorMessage = string.Format($"Unable to add the MessageHandler instance because the key '{key}' -already- exists. Please use another key.");
var errorMessage =
$"Unable to add the MessageHandler instance because the key '{key}' -already- exists. Please use another key.";
throw new Exception(errorMessage);
}

Expand Down
File renamed without changes.
Loading

0 comments on commit 82af344

Please sign in to comment.