Skip to content

Commit

Permalink
Restored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed May 31, 2022
1 parent 7094abc commit 7bcd0d4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
11 changes: 6 additions & 5 deletions src/AngleSharp.Io.Tests/Cookie/ClassicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public async Task SettingThreeCookiesInOneRequestAreTransportedToNextRequest()
""test"": ""baz""
}
}
".Replace(Environment.NewLine, "\n");
".Replace("\r\n", "\n");

Assert.AreEqual(expected, document.Body.TextContent);
}
Expand All @@ -275,7 +275,7 @@ public async Task SettingCookieIsPreservedViaRedirect()
""test"": ""baz""
}
}
".Replace(Environment.NewLine, "\n"), document.Body.TextContent);
".Replace("\r\n", "\n"), document.Body.TextContent);
}
}

Expand Down Expand Up @@ -429,13 +429,14 @@ public void ShouldChangeSelectedCookiesOnRedirect_Issue548()
var mcp = new MemoryCookieProvider();
var config = Configuration.Default.With(mcp).With(requester).WithDefaultLoader();
var context = BrowsingContext.New(config);
var receivedCookieHeader = "THECOOKIE=value1";
var setCookie = "THECOOKIE=value1";
var receivedCookieHeader = "";
var url = new Url("http://example.com/path1");
//request 1: /path1, set a cookie THECOOKIE=value1
requester.BuildResponse(req => VirtualResponse.Create(r => r
.Address("http://example.com/path1")
.Content("")
.Header(HeaderNames.SetCookie, receivedCookieHeader)));
.Header(HeaderNames.SetCookie, setCookie)));
context.OpenAsync("http://example.com/path1");
//request 2: /path1/somefile.jsp redirects to /path2/file2.jsp
requester.BuildResponses(new Func<Request, IResponse>[] {
Expand All @@ -452,7 +453,7 @@ public void ShouldChangeSelectedCookiesOnRedirect_Issue548()
}
});
context.OpenAsync("http://example.com/path1/somefile.jsp");
Assert.AreEqual(String.Empty, receivedCookieHeader);
Assert.AreEqual(setCookie, receivedCookieHeader);
}

private static Task<IDocument> LoadDocumentWithFakeRequesterAndCookie(IResponse initialResponse,
Expand Down
6 changes: 3 additions & 3 deletions src/AngleSharp.Io.Tests/Network/CookieHandlingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task SettingThreeCookiesInOneRequestAreTransportedToNextRequest()
""test"": ""baz""
}
}
".Replace(Environment.NewLine, "\n"), document.Body.TextContent);
".Replace("\r\n", "\n"), document.Body.TextContent);
}
}

Expand All @@ -92,7 +92,7 @@ public async Task SettingCookieIsPreservedViaRedirect()
""test"": ""baz""
}
}
".Replace(Environment.NewLine, "\n"), document.Body.TextContent);
".Replace("\r\n", "\n"), document.Body.TextContent);
}
}

Expand All @@ -114,7 +114,7 @@ public async Task SettingCookieIsPreservedViaRedirectToDifferentProtocol()
""test"": ""baz""
}
}
".Replace(Environment.NewLine, "\n"), document.Body.TextContent);
".Replace("\r\n", "\n"), document.Body.TextContent);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/AngleSharp.Io.Tests/Network/HttpClientRequesterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task ResponseWithContent()
// ASSERT
response.Address.Should().BeEquivalentTo(ts.Request.Address);
response.StatusCode.Should().Be(ts.HttpResponseMessage.StatusCode);
response.Headers.Keys.Should().BeEquivalentTo(new[] {"Server", "X-Powered-By", "X-CSV", "Content-Type"});
response.Headers.Keys.Should().BeEquivalentTo(new[] {"Server", "X-Powered-By", "X-CSV", "Content-Type", "Content-Length"});
response.Headers["Server"].Should().Be("Fake");
response.Headers["X-Powered-By"].Should().Be("Magic");
response.Headers["X-CSV"].Should().Be("foo, bar");
Expand All @@ -91,11 +91,11 @@ public async Task ResponseWithoutContent()
// ASSERT
response.Address.Should().BeEquivalentTo(ts.Request.Address);
response.StatusCode.Should().Be(ts.HttpResponseMessage.StatusCode);
response.Headers.Keys.Should().BeEquivalentTo(new[] {"Server", "X-Powered-By", "X-CSV"});
response.Headers.Keys.Should().BeEquivalentTo(new[] {"Server", "X-Powered-By", "X-CSV", "Content-Length"});
response.Headers["Server"].Should().Be("Fake");
response.Headers["X-Powered-By"].Should().Be("Magic");
response.Headers["X-CSV"].Should().Be("foo, bar");
response.Content.Should().BeNull();
new StreamReader(response.Content, Encoding.UTF8).ReadToEnd().Should().Be("");
}

[Test]
Expand Down
26 changes: 19 additions & 7 deletions src/AngleSharp.Io.Tests/Network/WebSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,37 @@ public async Task ConnectToWebSocketEcho()
var haserror = false;
var messages = new List<String>();
var closed = new TaskCompletionSource<Boolean>();
var document = await BrowsingContext.New().OpenNewAsync("https://www.websocket.org/echo.html");
var ws = new WebSocket(document.DefaultView, "ws://echo.websocket.org");
var document = await BrowsingContext.New().OpenNewAsync("https://echo.websocket.events/.ws");
var ws = new WebSocket(document.DefaultView, "wss://echo.websocket.events/");

// ACT
ws.Opened += (s, ev) => ws.Send(message);
ws.Message += (s, ev) =>
{
var msg = ev as MessageEvent;
messages.Add(msg.Data.ToString());

if (messages.Count == 2)
{
ws.Close();
}
};
ws.Closed += (s, ev) =>
{
closed.SetResult(true);
};
ws.Error += (s, ev) =>
{
haserror = true;
ws.Close();
};
ws.Closed += (s, ev) => closed.SetResult(true);
ws.Error += (s, ev) => haserror = true;
await closed.Task;

// ASSERT
haserror.Should().BeFalse();
messages.Count.Should().Be(1);
messages[0].Should().Be(message);
messages.Count.Should().Be(2);
messages[0].Should().Be("echo.websocket.events sponsored by Lob.com");
messages[1].Should().Be(message);
}
}
}
Expand Down

0 comments on commit 7bcd0d4

Please sign in to comment.