Skip to content

Commit

Permalink
chore(generator): Response and Request (microsoft#1270)
Browse files Browse the repository at this point in the history
* chore(generator): Response and Request
introducing ResourceTypes constant
  • Loading branch information
avodovnik authored Mar 11, 2021
1 parent 69ebad3 commit 6bd24d1
Show file tree
Hide file tree
Showing 36 changed files with 729 additions and 511 deletions.
2 changes: 1 addition & 1 deletion src/PlaywrightSharp.Tests/BrowserContextBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public async Task ShouldWorkWithOfflineOption()
await Assert.ThrowsAsync<PlaywrightSharpException>(() => page.GoToAsync(TestConstants.EmptyPage));
await context.SetOfflineAsync(false);
var response = await page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("browsercontext-basic.spec.ts", "should emulate navigator.onLine")]
Expand Down
12 changes: 6 additions & 6 deletions src/PlaywrightSharp.Tests/BrowserContextHttpCredentialsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task ShouldFailWithoutCredentials()
await using var context = await Browser.NewContextAsync();
var page = await context.NewPageAsync();
var response = await page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.Unauthorized, response.Status);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}

[PlaywrightTest("browsercontext-credentials.spec.ts", "should work with setHTTPCredentials")]
Expand All @@ -34,14 +34,14 @@ public async Task ShouldWorkWithSetHTTPCredentials()
await using var context = await Browser.NewContextAsync();
var page = await context.NewPageAsync();
var response = await page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.Unauthorized, response.Status);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
await context.SetHttpCredentialsAsync(new Credentials
{
Username = "user",
Password = "pass"
});
response = await page.ReloadAsync();
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("browsercontext-credentials.spec.ts", "should work with correct credentials")]
Expand All @@ -61,7 +61,7 @@ public async Task ShouldWorkWithCorrectCredentials()

var page = await context.NewPageAsync();
var response = await page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("browsercontext-credentials.spec.ts", "should fail if wrong credentials")]
Expand All @@ -81,7 +81,7 @@ public async Task ShouldFailIfWrongCredentials()

var page = await context.NewPageAsync();
var response = await page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.Unauthorized, response.Status);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}

[PlaywrightTest("browsercontext-credentials.spec.ts", "should return resource body")]
Expand All @@ -100,7 +100,7 @@ public async Task ShouldReturnResourceBody()

var page = await context.NewPageAsync();
var response = await page.GoToAsync(TestConstants.ServerUrl + "/playground.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Playground", await page.GetTitleAsync());
Assert.Contains("Playground", await response.GetTextAsync());
}
Expand Down
7 changes: 4 additions & 3 deletions src/PlaywrightSharp.Tests/BrowserContextRouteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using PlaywrightSharp.Contracts.Constants;
using PlaywrightSharp.Tests.BaseTests;
using PlaywrightSharp.Xunit;
using Xunit;
Expand Down Expand Up @@ -32,11 +33,11 @@ await context.RouteAsync("**/empty.html", (route, _) =>
intercepted = true;

Assert.Contains("empty.html", route.Request.Url);
Assert.False(string.IsNullOrEmpty(route.Request.Headers["user-agent"]));
Assert.Equal(HttpMethod.Get, route.Request.Method);
Assert.False(string.IsNullOrEmpty(route.Request.GetHeaderValue("user-agent")));
Assert.Equal(HttpMethod.Get.Method, route.Request.Method);
Assert.Null(route.Request.PostData);
Assert.True(route.Request.IsNavigationRequest);
Assert.Equal(ResourceType.Document, route.Request.ResourceType);
Assert.Equal(ResourceTypes.Document, route.Request.ResourceType, false);
Assert.Same(page.MainFrame, route.Request.Frame);
Assert.Equal("about:blank", page.MainFrame.Url);

Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp.Tests/DefaultBrowserContext1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public async Task ShouldRupportHttpCredentialsOption()

Server.SetAuth("/playground.html", "user", "pass");
var response = await page.GoToAsync(TestConstants.ServerUrl + "/playground.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

tmp.Dispose();
await context.DisposeAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp.Tests/FrameGoToTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task ShouldNavigateSubFrames()
Assert.Single(Page.Frames.Where(f => f.Url.Contains("/frames/frame.html")));
var childFrame = Page.FirstChildFrame();
var response = await childFrame.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Same(response.Frame, childFrame);
}

Expand Down
4 changes: 2 additions & 2 deletions src/PlaywrightSharp.Tests/IgnoreHttpsErrorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ await TaskUtils.WhenAll(
responseTask);

var response = responseTask.Result;
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("ignorehttpserrors.spec.ts", "should isolate contexts")]
Expand All @@ -49,7 +49,7 @@ public async Task ShouldIsolateContexts()
var page = await context.NewPageAsync();
var response = await page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");

Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

await using (var context = await Browser.NewContextAsync())
Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp.Tests/InterceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task ShouldWorkWitIgnoreHTTPSErrors()

await page.RouteAsync("**/*", (route, _) => route.ContinueAsync());
var response = await page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}


Expand Down
8 changes: 4 additions & 4 deletions src/PlaywrightSharp.Tests/NetworkPostDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task ShouldReturnCorrectPostdataBufferForUtf8Body()

var request = task.Result.Request;
Assert.Equal(expectedJsonValue, request.PostData);
Assert.Equal(value, request.GetPostDataJson().RootElement.GetString());
Assert.Equal(value, request.GetPayloadAsJson().RootElement.GetString());
}

/// <playwright-file>network-post-data.spec.ts</playwright-file>
Expand All @@ -70,7 +70,7 @@ public async Task ShouldReturnPostDataWOContentType()
Task.WaitAll(task, actualTask);

var request = task.Result.Request;
Assert.Equal(42, request.GetPostDataJson().RootElement.GetProperty("value").GetInt32());
Assert.Equal(42, request.GetPayloadAsJson().RootElement.GetProperty("value").GetInt32());
}

/// <playwright-file>network-post-data.spec.ts</playwright-file>
Expand All @@ -92,7 +92,7 @@ public async Task ShouldThrowOnInvalidJSONInPostData()
Task.WaitAll(task, actualTask);

var request = task.Result.Request;
Assert.ThrowsAny<JsonException>(() => request.GetPostDataJson());
Assert.ThrowsAny<JsonException>(() => request.GetPayloadAsJson());
}

/// <playwright-file>network-post-data.spec.ts</playwright-file>
Expand All @@ -114,7 +114,7 @@ public async Task ShouldReturnPostDataForPUTRequests()
Task.WaitAll(task, actualTask);

var request = task.Result.Request;
Assert.Equal(42, request.GetPostDataJson().RootElement.GetProperty("value").GetInt32());
Assert.Equal(42, request.GetPayloadAsJson().RootElement.GetProperty("value").GetInt32());
}
}
}
15 changes: 8 additions & 7 deletions src/PlaywrightSharp.Tests/PageEventNetworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using PlaywrightSharp.Contracts.Constants;
using PlaywrightSharp.Tests.BaseTests;
using PlaywrightSharp.TestServer;
using PlaywrightSharp.Xunit;
Expand All @@ -27,8 +28,8 @@ public async Task PageEventsRequest()
await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Single(requests);
Assert.Equal(TestConstants.EmptyPage, requests[0].Url);
Assert.Equal(ResourceType.Document, requests[0].ResourceType);
Assert.Equal(HttpMethod.Get, requests[0].Method);
Assert.Equal(ResourceTypes.Document, requests[0].ResourceType, true);
Assert.Equal(HttpMethod.Get.Method, requests[0].Method);
Assert.NotNull(await requests[0].GetResponseAsync());
Assert.Equal(Page.MainFrame, requests[0].Frame);
Assert.Equal(TestConstants.EmptyPage, requests[0].Frame.Url);
Expand All @@ -43,7 +44,7 @@ public async Task PageEventsResponse()
await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Single(responses);
Assert.Equal(TestConstants.EmptyPage, responses[0].Url);
Assert.Equal(HttpStatusCode.OK, responses[0].Status);
Assert.Equal(HttpStatusCode.OK, responses[0].StatusCode);
Assert.True(responses[0].Ok);
Assert.NotNull(responses[0].Request);
}
Expand All @@ -69,7 +70,7 @@ public async Task PageEventsRequestFailed()
Assert.Single(failedRequests);
Assert.Contains("one-style.css", failedRequests[0].Url);
Assert.Null(await failedRequests[0].GetResponseAsync());
Assert.Equal(ResourceType.StyleSheet, failedRequests[0].ResourceType);
Assert.Equal(ResourceTypes.Stylesheet, failedRequests[0].ResourceType, true);

string error = string.Empty;

Expand All @@ -89,7 +90,7 @@ public async Task PageEventsRequestFinished()
var request = response.Request;
Assert.Equal(TestConstants.EmptyPage, request.Url);
Assert.NotNull(await request.GetResponseAsync());
Assert.Equal(HttpMethod.Get, request.Method);
Assert.Equal(HttpMethod.Get.Method, request.Method);
Assert.Equal(Page.MainFrame, request.Frame);
Assert.Equal(TestConstants.EmptyPage, request.Frame.Url);
}
Expand All @@ -102,7 +103,7 @@ public async Task ShouldFireEventsInProperOrder()
Page.Request += (_, _) => events.Add("request");
Page.Response += (_, _) => events.Add("response");
var response = await Page.GoToAsync(TestConstants.EmptyPage);
await response.FinishedAsync();
await response.GetFinishedAsync();
events.Add("requestfinished");
Assert.Equal(new[] { "request", "response", "requestfinished" }, events);
}
Expand All @@ -119,7 +120,7 @@ public async Task ShouldSupportRedirects()
Server.SetRedirect("/foo.html", "/empty.html");
const string FOO_URL = TestConstants.ServerUrl + "/foo.html";
var response = await Page.GoToAsync(FOO_URL);
await response.FinishedAsync();
await response.GetFinishedAsync();
Assert.Equal(new[] {
$"GET {FOO_URL}",
$"302 {FOO_URL}",
Expand Down
18 changes: 9 additions & 9 deletions src/PlaywrightSharp.Tests/PageGoToTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task ShouldWorkWithRedirects()
Server.SetRedirect("/redirect/2.html", "/empty.html");

var response = await Page.GoToAsync(TestConstants.ServerUrl + "/redirect/1.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
await Page.GoToAsync(TestConstants.EmptyPage);
}

Expand All @@ -155,7 +155,7 @@ public async Task ShouldNavigateToAboutBlank()
public async Task ShouldReturnResponseWhenPageChangesItsURLAfterLoad()
{
var response = await Page.GoToAsync(TestConstants.ServerUrl + "/historyapi.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("page-goto.spec.ts", "should work with subframes return 204")]
Expand Down Expand Up @@ -201,7 +201,7 @@ public async Task ShouldFailWhenServerReturns204()
public async Task ShouldNavigateToEmptyPageWithDOMContentLoaded()
{
var response = await Page.GoToAsync(TestConstants.EmptyPage, LifecycleEvent.DOMContentLoaded);
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("page-goto.spec.ts", "should work when page calls history API in beforeunload")]
Expand All @@ -214,7 +214,7 @@ await Page.EvaluateAsync(@"() =>
window.addEventListener('beforeunload', () => history.replaceState(null, 'initial', window.location.href), false);
}");
var response = await Page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("page-goto.spec.ts", "should fail when navigating to bad url")]
Expand Down Expand Up @@ -420,7 +420,7 @@ public async Task ShouldFailWhenReplacedByAnotherNavigation()
public async Task ShouldWorkWhenNavigatingToValidUrl()
{
var response = await Page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("page-goto.spec.ts", "should work when navigating to data url")]
Expand All @@ -436,7 +436,7 @@ public async Task ShouldWorkWhenNavigatingToDataUrl()
public async Task ShouldWorkWhenNavigatingTo404()
{
var response = await Page.GoToAsync(TestConstants.ServerUrl + "/not-found");
Assert.Equal(HttpStatusCode.NotFound, response.Status);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}

[PlaywrightTest("page-goto.spec.ts", "should return last response in redirect chain")]
Expand All @@ -448,7 +448,7 @@ public async Task ShouldReturnLastResponseInRedirectChain()
Server.SetRedirect("/redirect/3.html", TestConstants.EmptyPage);

var response = await Page.GoToAsync(TestConstants.ServerUrl + "/redirect/1.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(TestConstants.EmptyPage, response.Url);
}

Expand Down Expand Up @@ -488,7 +488,7 @@ public async Task ShouldNavigateToURLWithHashAndFireRequestsWithoutHash()
Page.Request += (_, e) => requests.Add(e.Request);

var response = await Page.GoToAsync(TestConstants.EmptyPage + "#hash");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(TestConstants.EmptyPage, response.Url);
Assert.Single(requests);
Assert.Equal(TestConstants.EmptyPage, requests[0].Url);
Expand All @@ -499,7 +499,7 @@ public async Task ShouldNavigateToURLWithHashAndFireRequestsWithoutHash()
public async Task ShouldWorkWithSelfRequestingPage()
{
var response = await Page.GoToAsync(TestConstants.ServerUrl + "/self-request.html");
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Contains("self-request.html", response.Url);
}

Expand Down
4 changes: 2 additions & 2 deletions src/PlaywrightSharp.Tests/PageNetworkIdleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PageNetworkIdleTests(ITestOutputHelper output) : base(output)
public async Task ShouldNavigateToEmptyPageWithNetworkIdle()
{
var response = await Page.GoToAsync(TestConstants.EmptyPage, LifecycleEvent.Networkidle);
Assert.Equal(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[PlaywrightTest("page-network-idle.spec.ts", "should wait for networkidle to succeed navigation")]
Expand Down Expand Up @@ -195,7 +195,7 @@ async Task RequestDelegate(HttpContext context)
lastResponseFinished.Stop();
if (!isSetContent)
{
Assert.Equal(HttpStatusCode.OK, navigationResponse.Status);
Assert.Equal(HttpStatusCode.OK, navigationResponse.StatusCode);
}
}
}
Expand Down
Loading

0 comments on commit 6bd24d1

Please sign in to comment.