Skip to content

Commit 82af344

Browse files
authored
Cleaned up solution and bugfix (#7) (#8)
* 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.
1 parent 7d1fef9 commit 82af344

16 files changed

+389
-213
lines changed

.gitignore

Lines changed: 182 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,182 @@
1-
*.obj
2-
*.pdb
3-
*.user
4-
*.aps
5-
*.pch
6-
*.vspscc
7-
*.vssscc
8-
*_i.c
9-
*_p.c
10-
*.ncb
11-
*.suo
12-
*.tlb
13-
*.tlh
14-
*.bak
15-
*.cache
16-
*.ilk
17-
*.log
18-
*.lib
19-
*.sbr
20-
*.scc
21-
[Bb]in
22-
[Dd]ebug*/
23-
obj/
24-
[Rr]elease*/
25-
_ReSharper*/
26-
*.[Pp]ublish.xml
27-
*.resharper*
28-
AppData/
29-
App_Data/
30-
*.log.*
31-
[Ll]ogs/
32-
[Dd]ata/
33-
[Pp]ackages/
34-
[Tt]humbs.db
35-
[Tt]est[Rr]esult*
36-
[Bb]uild[Ll]og.*
37-
*.sln.DotSettings.*
38-
*.ncrunchproject
39-
*.ncrunchsolution
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+
# DNX
31+
project.lock.json
32+
project.fragment.lock.json
33+
artifacts/
34+
35+
*_i.c
36+
*_p.c
37+
*_i.h
38+
*.ilk
39+
*.meta
40+
*.obj
41+
*.pch
42+
*.pdb
43+
*.pgc
44+
*.pgd
45+
*.rsp
46+
*.sbr
47+
*.tlb
48+
*.tli
49+
*.tlh
50+
*.tmp
51+
*.tmp_proj
52+
*.log
53+
*.vspscc
54+
*.vssscc
55+
.builds
56+
*.pidb
57+
*.svclog
58+
*.scc
59+
60+
# Visual Studio profiler
61+
*.psess
62+
*.vsp
63+
*.vspx
64+
*.sap
65+
66+
# ReSharper is a .NET coding add-in
67+
_ReSharper*/
68+
*.[Rr]e[Ss]harper
69+
*.DotSettings.user
70+
71+
# DotCover is a Code Coverage Tool
72+
*.dotCover
73+
74+
# NCrunch
75+
_NCrunch_*
76+
.*crunch*.local.xml
77+
nCrunchTemp_*
78+
79+
# Web workbench (sass)
80+
.sass-cache/
81+
82+
# DocProject is a documentation generator add-in
83+
DocProject/buildhelp/
84+
DocProject/Help/*.HxT
85+
DocProject/Help/*.HxC
86+
DocProject/Help/*.hhc
87+
DocProject/Help/*.hhk
88+
DocProject/Help/*.hhp
89+
DocProject/Help/Html2
90+
DocProject/Help/html
91+
92+
# Click-Once directory
93+
publish/
94+
95+
# Publish Web Output
96+
*.[Pp]ublish.xml
97+
*.azurePubxml
98+
# TODO: Comment the next line if you want to checkin your web deploy settings
99+
# but database connection strings (with potential passwords) will be unencrypted
100+
*.pubxml
101+
*.publishproj
102+
103+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
104+
# checkin your Azure Web App publish settings, but sensitive information contained
105+
# in these scripts will be unencrypted
106+
PublishScripts/
107+
108+
# NuGet Packages
109+
*.nupkg
110+
# The packages folder can be ignored because of Package Restore
111+
**/packages/*
112+
# except build/, which is used as an MSBuild target.
113+
!**/packages/build/
114+
# Uncomment if necessary however generally it will be regenerated when needed
115+
#!**/packages/repositories.config
116+
# NuGet v3's project.json files produces more ignoreable files
117+
*.nuget.props
118+
*.nuget.targets
119+
120+
# Microsoft Azure Build Output
121+
csx/
122+
*.build.csdef
123+
124+
# Microsoft Azure Emulator
125+
ecf/
126+
rcf/
127+
128+
# Windows Store app package directories and files
129+
AppPackages/
130+
BundleArtifacts/
131+
Package.StoreAssociation.xml
132+
_pkginfo.txt
133+
134+
# Visual Studio cache files
135+
# files ending in .cache can be ignored
136+
*.[Cc]ache
137+
# but keep track of directories ending in .cache
138+
!*.[Cc]ache/
139+
140+
# Others
141+
ClientBin/
142+
~$*
143+
*~
144+
*.dbmdl
145+
*.dbproj.schemaview
146+
*.pfx
147+
*.publishsettings
148+
node_modules/
149+
orleans.codegen.cs
150+
151+
# Since there are multiple workflows, uncomment next line to ignore bower_components
152+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
153+
#bower_components/
154+
155+
# RIA/Silverlight projects
156+
Generated_Code/
157+
158+
# Backup & report files from converting an old project file
159+
# to a newer Visual Studio version. Backup files are not needed,
160+
# because we have git ;-)
161+
_UpgradeReport_Files/
162+
Backup*/
163+
UpgradeLog*.XML
164+
UpgradeLog*.htm
165+
166+
# SQL Server files
167+
*.mdf
168+
*.ldf
169+
170+
# Business Intelligence projects
171+
*.rdl.data
172+
*.bim.layout
173+
*.bim_*.settings
174+
175+
# Microsoft Fakes
176+
FakesAssemblies/
177+
178+
# GhostDoc plugin setting file
179+
*.GhostDoc.xml
180+
181+
# Node.js Tools for Visual Studio
182+
.ntvs_analysis.dat

HttpClient.Helpers.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers", "Code\HttpClient.Helpers\HttpClient.Helpers.csproj", "{CD2C1552-4AF1-4DC2-B0E6-90CE48D38F27}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers", "src\HttpClient.Helpers\HttpClient.Helpers.csproj", "{CD2C1552-4AF1-4DC2-B0E6-90CE48D38F27}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers.Tests", "Code\HttpClient.Helpers.Tests\HttpClient.Helpers.Tests.csproj", "{B3672F4D-77A9-4E91-83FC-E017E38A0762}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Helpers.Tests", "tests\HttpClient.Helpers.Tests\HttpClient.Helpers.Tests.csproj", "{B3672F4D-77A9-4E91-83FC-E017E38A0762}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# - All development is done in a fork.
55
# - Pull requests are merged into dev and it auto publishes
66
# to the myget pre-release 'pk-development' feed.
7-
# - When publishing to master we just merge dev to master.
8-
# - ASKJDHAKJSDHASj
7+
# - When publishing to master we just merge dev to master -but- no NuGet is made.
8+
# - To publish a live NuGet package, create a tag on master branch.
99
#
1010

1111

Code/HttpClient.Helpers/FakeMessageHandler.cs renamed to src/HttpClient.Helpers/FakeMessageHandler.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ namespace WorldDomination.Net.Http
1212
public class FakeHttpMessageHandler : HttpClientHandler
1313
{
1414
private readonly HttpRequestException _exception;
15-
private readonly IDictionary<string, HttpMessageOptions> _lotsOfOptions = new Dictionary<string, HttpMessageOptions>();
15+
16+
private readonly IDictionary<string, HttpMessageOptions> _lotsOfOptions =
17+
new Dictionary<string, HttpMessageOptions>();
1618

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

4951
// _responses = httpResponseMessages;
5052
//}
51-
52-
public FakeHttpMessageHandler(HttpMessageOptions options) : this(new List<HttpMessageOptions> { options})
53+
public FakeHttpMessageHandler(HttpMessageOptions options) : this(new List<HttpMessageOptions> {options})
5354
{
5455
}
5556

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

74-
Initialize(options);
75+
Initialize(options.ToArray());
7576
}
7677

7778
public FakeHttpMessageHandler(IEnumerable<HttpMessageOptions> lotsOfOptions)
7879
{
79-
Initialize(lotsOfOptions);
80+
Initialize(lotsOfOptions.ToArray());
8081
}
8182

8283
/// <summary>
@@ -101,7 +102,7 @@ public FakeHttpMessageHandler(HttpRequestException exception)
101102
{
102103
if (exception == null)
103104
{
104-
throw new ArgumentNullException("exception");
105+
throw new ArgumentNullException(nameof(exception));
105106
}
106107

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

126127
HttpMessageOptions options;
127-
var requestUri = request.RequestUri.ToString();
128+
var requestUri = request.RequestUri.AbsoluteUri;
128129

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

157158
var errorMessage =
158-
string.Format(
159-
"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}",
160-
request.RequestUri,
161-
requestUri,
162-
!_lotsOfOptions.Any()
163-
? "- no responses -"
164-
: _lotsOfOptions.Count.ToString(),
165-
responsesText);
159+
$"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}";
166160
throw new InvalidOperationException(errorMessage);
167161
}
168162
}
@@ -185,7 +179,7 @@ public static HttpResponseMessage GetStringHttpResponseMessage(string content,
185179
};
186180
}
187181

188-
private void Initialize(IEnumerable<HttpMessageOptions> lotsOfOptions)
182+
private void Initialize(ICollection<HttpMessageOptions> lotsOfOptions)
189183
{
190184
if (lotsOfOptions == null)
191185
{
@@ -207,7 +201,7 @@ private void Initialize(IEnumerable<HttpMessageOptions> lotsOfOptions)
207201
private static string CreateDictionaryKey(string requestUri, HttpMethod httpMethod)
208202
{
209203
var httpMethodText = httpMethod?.ToString() ?? "*";
210-
return string.Format($"{requestUri}||{httpMethodText}");
204+
return $"{requestUri}||{httpMethodText}";
211205
}
212206
}
213207
}

Code/HttpClient.Helpers/HttpClient.Helpers.nuspec renamed to src/HttpClient.Helpers/HttpClient.Helpers.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<language>en-AU</language>
1717
<tags>httpclient worlddomination worldomination unicorn magicalunicorn magical-unicorn</tags>
1818
<dependencies>
19-
<dependency id="Microsoft.Net.Http" version="[2.2.29, 3.0.0)" />
19+
<dependency id="Microsoft.Net.Http" version="2.2.29" />
2020
</dependencies>
2121
</metadata>
2222
<files>

Code/HttpClient.Helpers/HttpClientFactory.cs renamed to src/HttpClient.Helpers/HttpClientFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class HttpClientFactory
99
private static readonly Lazy<Dictionary<string, MessageHandlerItem>> MessageHandlers =
1010
new Lazy<Dictionary<string, MessageHandlerItem>>();
1111

12-
public static void AddMessageHandler(HttpMessageHandler messageHandler,
12+
public static void AddMessageHandler(HttpMessageHandler messageHandler,
1313
string key,
1414
bool disposeHandler = true)
1515
{
@@ -25,7 +25,8 @@ public static void AddMessageHandler(HttpMessageHandler messageHandler,
2525

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

0 commit comments

Comments
 (0)