From 346c23253a96c19b788d09c2428f8f7493a59e46 Mon Sep 17 00:00:00 2001
From: Damian Hickey <57436+damianh@users.noreply.github.com>
Date: Sun, 1 Dec 2024 20:55:30 +0100
Subject: [PATCH 1/2] Remove csquery package refrence and unused code
---
Directory.Build.targets | 2 +-
test/Duende.Bff.Tests/Duende.Bff.Tests.csproj | 1 -
.../TestFramework/TestBrowserClient.cs | 198 +-----------------
3 files changed, 2 insertions(+), 199 deletions(-)
diff --git a/Directory.Build.targets b/Directory.Build.targets
index d7730b74..0729acc2 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -38,7 +38,7 @@
-
+
diff --git a/test/Duende.Bff.Tests/Duende.Bff.Tests.csproj b/test/Duende.Bff.Tests/Duende.Bff.Tests.csproj
index 3506f590..e6ad1916 100644
--- a/test/Duende.Bff.Tests/Duende.Bff.Tests.csproj
+++ b/test/Duende.Bff.Tests/Duende.Bff.Tests.csproj
@@ -16,7 +16,6 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
diff --git a/test/Duende.Bff.Tests/TestFramework/TestBrowserClient.cs b/test/Duende.Bff.Tests/TestFramework/TestBrowserClient.cs
index a3648cf0..4a64c20d 100644
--- a/test/Duende.Bff.Tests/TestFramework/TestBrowserClient.cs
+++ b/test/Duende.Bff.Tests/TestFramework/TestBrowserClient.cs
@@ -1,11 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.
-using CsQuery;
-using FluentAssertions;
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
@@ -67,209 +63,17 @@ private TestBrowserClient(CookieHandler handler)
_handler = handler;
}
- public Cookie GetCookie(string name)
- {
- return GetCookie(_handler.CurrentUri.ToString(), name);
- }
- public Cookie GetCookie(string uri, string name)
- {
- return _handler.CookieContainer.GetCookies(new Uri(uri)).Cast().Where(x => x.Name == name).FirstOrDefault();
- }
-
public void RemoveCookie(string name)
{
RemoveCookie(CurrentUri.ToString(), name);
}
public void RemoveCookie(string uri, string name)
{
- var cookie = CookieContainer.GetCookies(new Uri(uri)).Cast().Where(x => x.Name == name).FirstOrDefault();
+ var cookie = CookieContainer.GetCookies(new Uri(uri)).FirstOrDefault(x => x.Name == name);
if (cookie != null)
{
cookie.Expired = true;
}
}
-
- public async Task FollowRedirectAsync()
- {
- LastResponse.StatusCode.Should().Be(HttpStatusCode.Redirect);
- var location = LastResponse.Headers.Location.ToString();
- await GetAsync(location);
- }
-
- public Task PostFormAsync(HtmlForm form)
- {
- return PostAsync(form.Action, new FormUrlEncodedContent(form.Inputs));
- }
-
- public Task ReadFormAsync(string selector = null)
- {
- return ReadFormAsync(LastResponse, selector);
- }
- public async Task ReadFormAsync(HttpResponseMessage response, string selector = null)
- {
- response.StatusCode.Should().Be(HttpStatusCode.OK);
-
- var htmlForm = new HtmlForm
- {
-
- };
-
- var html = await response.Content.ReadAsStringAsync();
-
- var dom = new CQ(html);
- var form = dom.Find(selector ?? "form");
- form.Length.Should().Be(1);
-
- var postUrl = form.Attr("action");
- if (!postUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
- {
- if (postUrl.StartsWith("/"))
- {
- postUrl = CurrentUri.Scheme + "://" + CurrentUri.Authority + postUrl;
- }
- else
- {
- postUrl = CurrentUri + postUrl;
- }
- }
- htmlForm.Action = postUrl;
-
-
- var data = new Dictionary();
-
- var inputs = form.Find("input");
- foreach (var input in inputs)
- {
- var name = input.GetAttribute("name");
- var value = input.GetAttribute("value");
-
- if (!data.ContainsKey(name))
- {
- data.Add(name, value);
- }
- else
- {
- data[name] = value;
- }
- }
- htmlForm.Inputs = data;
-
- return htmlForm;
- }
-
-
- public Task ReadElementTextAsync(string selector)
- {
- return ReadElementTextAsync(LastResponse, selector);
- }
- public async Task ReadElementTextAsync(HttpResponseMessage response, string selector)
- {
- var html = await response.Content.ReadAsStringAsync();
-
- var dom = new CQ(html);
- var element = dom.Find(selector);
- return element.Text();
- }
-
- public Task ReadElementAttributeAsync(string selector, string attribute)
- {
- return ReadElementAttributeAsync(LastResponse, selector, attribute);
- }
- public async Task ReadElementAttributeAsync(HttpResponseMessage response, string selector, string attribute)
- {
- var html = await response.Content.ReadAsStringAsync();
-
- var dom = new CQ(html);
- var element = dom.Find(selector);
- return element.Attr(attribute);
- }
-
- public Task AssertExistsAsync(string selector)
- {
- return AssertExistsAsync(LastResponse, selector);
- }
-
- public async Task AssertExistsAsync(HttpResponseMessage response, string selector)
- {
- response.StatusCode.Should().Be(HttpStatusCode.OK);
-
- var html = await response.Content.ReadAsStringAsync();
-
- var dom = new CQ(html);
- var element = dom.Find(selector);
- element.Length.Should().BeGreaterThan(0);
- }
-
- public Task AssertNotExistsAsync(string selector)
- {
- return AssertNotExistsAsync(selector);
- }
- public async Task AssertNotExistsAsync(HttpResponseMessage response, string selector)
- {
- response.StatusCode.Should().Be(HttpStatusCode.OK);
-
- var html = await response.Content.ReadAsStringAsync();
-
- var dom = new CQ(html);
- var element = dom.Find(selector);
- element.Length.Should().Be(0);
- }
-
- public Task AssertErrorPageAsync(string error = null)
- {
- return AssertErrorPageAsync(LastResponse, error);
- }
- public async Task AssertErrorPageAsync(HttpResponseMessage response, string error = null)
- {
- response.StatusCode.Should().Be(HttpStatusCode.OK);
- await AssertExistsAsync(response, ".error-page");
-
- if (!String.IsNullOrWhiteSpace(error))
- {
- var errorText = await ReadElementTextAsync(response, ".alert.alert-danger");
- errorText.Should().Contain(error);
- }
- }
-
- public Task AssertValidationErrorAsync(string error = null)
- {
- return AssertValidationErrorAsync(error);
- }
- public async Task AssertValidationErrorAsync(HttpResponseMessage response, string error = null)
- {
- response.StatusCode.Should().Be(HttpStatusCode.OK);
- await AssertExistsAsync(response, ".validation-summary-errors");
-
- if (!String.IsNullOrWhiteSpace(error))
- {
- var errorText = await ReadElementTextAsync(response, ".validation-summary-errors");
- errorText.ToLowerInvariant().Should().Contain(error.ToLowerInvariant());
- }
- }
- }
-
- [DebuggerDisplay("{Action}, Inputs: {Inputs.Count}")]
- public class HtmlForm
- {
- public HtmlForm(string action = null)
- {
- Action = action;
- }
-
- public string Action { get; set; }
- public Dictionary Inputs { get; set; } = new Dictionary();
-
- public string this[string key]
- {
- get
- {
- if (Inputs.ContainsKey(key)) return Inputs[key];
- return null;
- }
- set
- {
- Inputs[key] = value;
- }
- }
}
}
\ No newline at end of file
From 63076190e102b8c9fd06b70eeacd018cc168f3e5 Mon Sep 17 00:00:00 2001
From: Joe DeCock
Date: Mon, 16 Dec 2024 13:46:35 -0600
Subject: [PATCH 2/2] Remove unused anglesharp
---
Directory.Build.targets | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/Directory.Build.targets b/Directory.Build.targets
index 0729acc2..7b7fefe4 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -38,7 +38,6 @@
-
@@ -57,4 +56,4 @@
$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).0
-
\ No newline at end of file
+