Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.

Commit 9c5e78b

Browse files
committed
Make tests run on CoreCLR
- Added dnxcore50 target - Removed Shouldly reference - Used CoreCLR-compatible APIs
1 parent dd3bb68 commit 9c5e78b

File tree

6 files changed

+46
-51
lines changed

6 files changed

+46
-51
lines changed

test/Microsoft.AspNet.StaticFiles.Tests/CacheHeaderTests.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Threading.Tasks;
77
using Microsoft.AspNet.Builder;
88
using Microsoft.AspNet.TestHost;
9-
using Shouldly;
109
using Xunit;
1110

1211
namespace Microsoft.AspNet.StaticFiles
@@ -19,8 +18,8 @@ public async Task ServerShouldReturnETag()
1918
TestServer server = TestServer.Create(app => app.UseFileServer());
2019

2120
HttpResponseMessage response = await server.CreateClient().GetAsync("http://localhost/SubFolder/Extra.xml");
22-
response.Headers.ETag.ShouldNotBe(null);
23-
response.Headers.ETag.Tag.ShouldNotBe(null);
21+
Assert.NotNull(response.Headers.ETag);
22+
Assert.NotNull(response.Headers.ETag.Tag);
2423
}
2524

2625
[Fact]
@@ -30,7 +29,7 @@ public async Task SameETagShouldBeReturnedAgain()
3029

3130
HttpResponseMessage response1 = await server.CreateClient().GetAsync("http://localhost/SubFolder/Extra.xml");
3231
HttpResponseMessage response2 = await server.CreateClient().GetAsync("http://localhost/SubFolder/Extra.xml");
33-
response1.Headers.ETag.ShouldBe(response2.Headers.ETag);
32+
Assert.Equal(response2.Headers.ETag, response1.Headers.ETag);
3433
}
3534

3635
// 14.24 If-Match
@@ -48,7 +47,7 @@ public async Task IfMatchShouldReturn412WhenNotListed()
4847
var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Extra.xml");
4948
req.Headers.Add("If-Match", "\"fake\"");
5049
HttpResponseMessage resp = await server.CreateClient().SendAsync(req);
51-
resp.StatusCode.ShouldBe(HttpStatusCode.PreconditionFailed);
50+
Assert.Equal(HttpStatusCode.PreconditionFailed, resp.StatusCode);
5251
}
5352

5453
[Fact]
@@ -60,7 +59,7 @@ public async Task IfMatchShouldBeServedWhenListed()
6059
var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Extra.xml");
6160
req.Headers.Add("If-Match", original.Headers.ETag.ToString());
6261
HttpResponseMessage resp = await server.CreateClient().SendAsync(req);
63-
resp.StatusCode.ShouldBe(HttpStatusCode.OK);
62+
Assert.Equal(HttpStatusCode.OK, resp.StatusCode);
6463
}
6564

6665
[Fact]
@@ -70,7 +69,7 @@ public async Task IfMatchShouldBeServedForAstrisk()
7069
var req = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Extra.xml");
7170
req.Headers.Add("If-Match", "*");
7271
HttpResponseMessage resp = await server.CreateClient().SendAsync(req);
73-
resp.StatusCode.ShouldBe(HttpStatusCode.OK);
72+
Assert.Equal(HttpStatusCode.OK, resp.StatusCode);
7473
}
7574

7675
// 14.26 If-None-Match
@@ -96,12 +95,12 @@ public async Task IfNoneMatchShouldReturn304ForMatchingOnGetAndHeadMethod()
9695
var req2 = new HttpRequestMessage(HttpMethod.Get, "http://localhost/SubFolder/Extra.xml");
9796
req2.Headers.Add("If-None-Match", resp1.Headers.ETag.ToString());
9897
HttpResponseMessage resp2 = await server.CreateClient().SendAsync(req2);
99-
resp2.StatusCode.ShouldBe(HttpStatusCode.NotModified);
98+
Assert.Equal(HttpStatusCode.NotModified, resp2.StatusCode);
10099

101100
var req3 = new HttpRequestMessage(HttpMethod.Head, "http://localhost/SubFolder/Extra.xml");
102101
req3.Headers.Add("If-None-Match", resp1.Headers.ETag.ToString());
103102
HttpResponseMessage resp3 = await server.CreateClient().SendAsync(req3);
104-
resp3.StatusCode.ShouldBe(HttpStatusCode.NotModified);
103+
Assert.Equal(HttpStatusCode.NotModified, resp3.StatusCode);
105104
}
106105

107106
[Fact]
@@ -113,12 +112,12 @@ public async Task IfNoneMatchShouldBeIgnoredForNonTwoHundredAnd304Responses()
113112
var req2 = new HttpRequestMessage(HttpMethod.Post, "http://localhost/SubFolder/Extra.xml");
114113
req2.Headers.Add("If-None-Match", resp1.Headers.ETag.ToString());
115114
HttpResponseMessage resp2 = await server.CreateClient().SendAsync(req2);
116-
resp2.StatusCode.ShouldBe(HttpStatusCode.NotFound);
115+
Assert.Equal(HttpStatusCode.NotFound, resp2.StatusCode);
117116

118117
var req3 = new HttpRequestMessage(HttpMethod.Put, "http://localhost/SubFolder/Extra.xml");
119118
req3.Headers.Add("If-None-Match", resp1.Headers.ETag.ToString());
120119
HttpResponseMessage resp3 = await server.CreateClient().SendAsync(req3);
121-
resp3.StatusCode.ShouldBe(HttpStatusCode.NotFound);
120+
Assert.Equal(HttpStatusCode.NotFound, resp3.StatusCode);
122121
}
123122

124123
// 14.26 If-None-Match
@@ -137,7 +136,7 @@ public async Task ServerShouldReturnLastModified()
137136
TestServer server = TestServer.Create(app => app.UseFileServer());
138137

139138
HttpResponseMessage response = await server.CreateClient().GetAsync("http://localhost/SubFolder/Extra.xml");
140-
response.Content.Headers.LastModified.ShouldNotBe(null);
139+
Assert.NotNull(response.Content.Headers.LastModified);
141140
}
142141

143142
// 13.3.4
@@ -163,7 +162,7 @@ public async Task MatchingBothConditionsReturnsNotModified()
163162
.And(req => req.Headers.IfModifiedSince = resp1.Content.Headers.LastModified)
164163
.GetAsync();
165164

166-
resp2.StatusCode.ShouldBe(HttpStatusCode.NotModified);
165+
Assert.Equal(HttpStatusCode.NotModified, resp2.StatusCode);
167166
}
168167

169168
[Fact]
@@ -196,9 +195,9 @@ public async Task MissingEitherOrBothConditionsReturnsNormally()
196195
.And(req => req.Headers.IfModifiedSince = furtureDate)
197196
.GetAsync();
198197

199-
resp2.StatusCode.ShouldBe(HttpStatusCode.OK);
200-
resp3.StatusCode.ShouldBe(HttpStatusCode.OK);
201-
resp4.StatusCode.ShouldBe(HttpStatusCode.OK);
198+
Assert.Equal(HttpStatusCode.OK, resp2.StatusCode);
199+
Assert.Equal(HttpStatusCode.OK, resp3.StatusCode);
200+
Assert.Equal(HttpStatusCode.OK, resp4.StatusCode);
202201
}
203202

204203
// 14.25 If-Modified-Since
@@ -223,7 +222,7 @@ public async Task InvalidIfModifiedSinceDateFormatGivesNormalGet()
223222
.AddHeader("If-Modified-Since", "bad-date")
224223
.GetAsync();
225224

226-
res.StatusCode.ShouldBe(HttpStatusCode.OK);
225+
Assert.Equal(HttpStatusCode.OK, res.StatusCode);
227226
}
228227

229228
// b) If the variant has been modified since the If-Modified-Since
@@ -247,7 +246,7 @@ public async Task IfModifiedSinceDateEqualsLastModifiedShouldReturn304()
247246
.And(req => req.Headers.IfModifiedSince = res1.Content.Headers.LastModified)
248247
.GetAsync();
249248

250-
res2.StatusCode.ShouldBe(HttpStatusCode.NotModified);
249+
Assert.Equal(HttpStatusCode.NotModified, res2.StatusCode);
251250
}
252251
}
253252
}
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) .NET Foundation. All rights reserved. See License.txt in the project root for license information.
22

3-
using Shouldly;
43
using Xunit;
54

65
namespace Microsoft.AspNet.StaticFiles
@@ -12,55 +11,55 @@ public void UnknownExtensionsReturnFalse()
1211
{
1312
var provider = new FileExtensionContentTypeProvider();
1413
string contentType;
15-
provider.TryGetContentType("unknown.ext", out contentType).ShouldBe(false);
14+
Assert.False(provider.TryGetContentType("unknown.ext", out contentType));
1615
}
1716

1817
[Fact]
1918
public void KnownExtensionsReturnTrye()
2019
{
2120
var provider = new FileExtensionContentTypeProvider();
2221
string contentType;
23-
provider.TryGetContentType("known.txt", out contentType).ShouldBe(true);
24-
contentType.ShouldBe("text/plain");
22+
Assert.True(provider.TryGetContentType("known.txt", out contentType));
23+
Assert.Equal("text/plain", contentType);
2524
}
2625

2726
[Fact]
2827
public void DoubleDottedExtensionsAreNotSupported()
2928
{
3029
var provider = new FileExtensionContentTypeProvider();
3130
string contentType;
32-
provider.TryGetContentType("known.exe.config", out contentType).ShouldBe(false);
31+
Assert.False(provider.TryGetContentType("known.exe.config", out contentType));
3332
}
3433

3534
[Fact]
3635
public void DashedExtensionsShouldBeMatched()
3736
{
3837
var provider = new FileExtensionContentTypeProvider();
3938
string contentType;
40-
provider.TryGetContentType("known.dvr-ms", out contentType).ShouldBe(true);
41-
contentType.ShouldBe("video/x-ms-dvr");
39+
Assert.True(provider.TryGetContentType("known.dvr-ms", out contentType));
40+
Assert.Equal("video/x-ms-dvr", contentType);
4241
}
4342

4443
[Fact]
4544
public void BothSlashFormatsAreUnderstood()
4645
{
4746
var provider = new FileExtensionContentTypeProvider();
4847
string contentType;
49-
provider.TryGetContentType(@"/first/example.txt", out contentType).ShouldBe(true);
50-
contentType.ShouldBe("text/plain");
51-
provider.TryGetContentType(@"\second\example.txt", out contentType).ShouldBe(true);
52-
contentType.ShouldBe("text/plain");
48+
Assert.True(provider.TryGetContentType(@"/first/example.txt", out contentType));
49+
Assert.Equal("text/plain", contentType);
50+
Assert.True(provider.TryGetContentType(@"\second\example.txt", out contentType));
51+
Assert.Equal("text/plain", contentType);
5352
}
5453

5554
[Fact]
5655
public void DotsInDirectoryAreIgnored()
5756
{
5857
var provider = new FileExtensionContentTypeProvider();
5958
string contentType;
60-
provider.TryGetContentType(@"/first.css/example.txt", out contentType).ShouldBe(true);
61-
contentType.ShouldBe("text/plain");
62-
provider.TryGetContentType(@"\second.css\example.txt", out contentType).ShouldBe(true);
63-
contentType.ShouldBe("text/plain");
59+
Assert.True(provider.TryGetContentType(@"/first.css/example.txt", out contentType));
60+
Assert.Equal("text/plain", contentType);
61+
Assert.True(provider.TryGetContentType(@"\second.css\example.txt", out contentType));
62+
Assert.Equal("text/plain", contentType);
6463
}
6564
}
6665
}

test/Microsoft.AspNet.StaticFiles.Tests/DefaultFilesMiddlewareTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task NoMatch_PassesThrough(string baseUrl, string baseDir, string r
4141
app.UseDefaultFiles(new DefaultFilesOptions()
4242
{
4343
RequestPath = new PathString(baseUrl),
44-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
44+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
4545
});
4646
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
4747
});
@@ -62,7 +62,7 @@ public async Task FoundDirectoryWithDefaultFile_PathModified(string baseUrl, str
6262
app.UseDefaultFiles(new DefaultFilesOptions()
6363
{
6464
RequestPath = new PathString(baseUrl),
65-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
65+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
6666
});
6767
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
6868
});
@@ -81,7 +81,7 @@ public async Task NearMatch_RedirectAddSlash(string baseUrl, string baseDir, str
8181
TestServer server = TestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions()
8282
{
8383
RequestPath = new PathString(baseUrl),
84-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
84+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
8585
}));
8686
HttpResponseMessage response = await server.CreateRequest(requestUrl + queryString).GetAsync();
8787

@@ -100,7 +100,7 @@ public async Task PostDirectory_PassesThrough(string baseUrl, string baseDir, st
100100
TestServer server = TestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions()
101101
{
102102
RequestPath = new PathString(baseUrl),
103-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
103+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
104104
}));
105105
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
106106

test/Microsoft.AspNet.StaticFiles.Tests/DirectoryBrowserMiddlewareTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task NoMatch_PassesThrough(string baseUrl, string baseDir, string r
4949
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
5050
{
5151
RequestPath = new PathString(baseUrl),
52-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
52+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
5353
}),
5454
services => services.AddDirectoryBrowser());
5555
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
@@ -68,7 +68,7 @@ public async Task FoundDirectory_Served(string baseUrl, string baseDir, string r
6868
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
6969
{
7070
RequestPath = new PathString(baseUrl),
71-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
71+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
7272
}),
7373
services => services.AddDirectoryBrowser());
7474
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
@@ -92,7 +92,7 @@ public async Task NearMatch_RedirectAddSlash(string baseUrl, string baseDir, str
9292
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
9393
{
9494
RequestPath = new PathString(baseUrl),
95-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
95+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
9696
}),
9797
services => services.AddDirectoryBrowser());
9898

@@ -114,7 +114,7 @@ public async Task PostDirectory_PassesThrough(string baseUrl, string baseDir, st
114114
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
115115
{
116116
RequestPath = new PathString(baseUrl),
117-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
117+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
118118
}),
119119
services => services.AddDirectoryBrowser());
120120

@@ -133,7 +133,7 @@ public async Task HeadDirectory_HeadersButNotBodyServed(string baseUrl, string b
133133
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
134134
{
135135
RequestPath = new PathString(baseUrl),
136-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
136+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
137137
}),
138138
services => services.AddDirectoryBrowser());
139139

test/Microsoft.AspNet.StaticFiles.Tests/StaticFileMiddlewareTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task NoMatch_PassesThrough(string baseUrl, string baseDir, string r
4040
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
4141
{
4242
RequestPath = new PathString(baseUrl),
43-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
43+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
4444
}));
4545
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
4646
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@@ -58,7 +58,7 @@ public async Task FoundFile_Served(string baseUrl, string baseDir, string reques
5858
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
5959
{
6060
RequestPath = new PathString(baseUrl),
61-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
61+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
6262
}));
6363
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
6464

@@ -80,7 +80,7 @@ public async Task PostFile_PassesThrough(string baseUrl, string baseDir, string
8080
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
8181
{
8282
RequestPath = new PathString(baseUrl),
83-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
83+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
8484
}));
8585
HttpResponseMessage response = await server.CreateRequest(requestUrl).PostAsync();
8686
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@@ -98,7 +98,7 @@ public async Task HeadFile_HeadersButNotBodyServed(string baseUrl, string baseDi
9898
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
9999
{
100100
RequestPath = new PathString(baseUrl),
101-
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
101+
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir))
102102
}));
103103
HttpResponseMessage response = await server.CreateRequest(requestUrl).SendAsync("HEAD");
104104

test/Microsoft.AspNet.StaticFiles.Tests/project.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
"test": "xunit.runner.aspnet"
1010
},
1111
"frameworks": {
12-
"dnx451": {
13-
"dependencies": {
14-
"Shouldly": "1.1.1.1"
15-
}
16-
}
12+
"dnx451": { },
13+
"dnxcore50": { }
1714
}
1815
}

0 commit comments

Comments
 (0)