Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 0908510

Browse files
authored
Merge pull request #213 from damianh/dh/remove-cs-query
Remove csquery package refrence and unused code
2 parents 6aa132d + 6307619 commit 0908510

File tree

3 files changed

+2
-200
lines changed

3 files changed

+2
-200
lines changed

Directory.Build.targets

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
<PackageReference Update="Duende.IdentityServer" Version="$(IdentityServerVersion)" />
4040

41-
<PackageReference Update="CsQuery.NETStandard" Version="1.3.6.1" />
4241
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.12.0" />
4342
<PackageReference Update="xunit" Version="2.9.2" />
4443
<PackageReference Update="xunit.runner.visualstudio" Version="2.8.2">
@@ -57,4 +56,4 @@
5756
<AssemblyVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).0</AssemblyVersion>
5857
</PropertyGroup>
5958
</Target>
60-
</Project>
59+
</Project>

test/Duende.Bff.Tests/Duende.Bff.Tests.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>
19-
<PackageReference Include="CsQuery.NETStandard" />
2019

2120
<PackageReference Include="Duende.IdentityServer" />
2221
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// Copyright (c) Duende Software. All rights reserved.
22
// See LICENSE in the project root for license information.
33

4-
using CsQuery;
5-
using FluentAssertions;
64
using System;
7-
using System.Collections.Generic;
8-
using System.Diagnostics;
95
using System.Linq;
106
using System.Net;
117
using System.Net.Http;
@@ -67,209 +63,17 @@ private TestBrowserClient(CookieHandler handler)
6763
_handler = handler;
6864
}
6965

70-
public Cookie GetCookie(string name)
71-
{
72-
return GetCookie(_handler.CurrentUri.ToString(), name);
73-
}
74-
public Cookie GetCookie(string uri, string name)
75-
{
76-
return _handler.CookieContainer.GetCookies(new Uri(uri)).Cast<Cookie>().Where(x => x.Name == name).FirstOrDefault();
77-
}
78-
7966
public void RemoveCookie(string name)
8067
{
8168
RemoveCookie(CurrentUri.ToString(), name);
8269
}
8370
public void RemoveCookie(string uri, string name)
8471
{
85-
var cookie = CookieContainer.GetCookies(new Uri(uri)).Cast<Cookie>().Where(x => x.Name == name).FirstOrDefault();
72+
var cookie = CookieContainer.GetCookies(new Uri(uri)).FirstOrDefault(x => x.Name == name);
8673
if (cookie != null)
8774
{
8875
cookie.Expired = true;
8976
}
9077
}
91-
92-
public async Task FollowRedirectAsync()
93-
{
94-
LastResponse.StatusCode.Should().Be(HttpStatusCode.Redirect);
95-
var location = LastResponse.Headers.Location.ToString();
96-
await GetAsync(location);
97-
}
98-
99-
public Task<HttpResponseMessage> PostFormAsync(HtmlForm form)
100-
{
101-
return PostAsync(form.Action, new FormUrlEncodedContent(form.Inputs));
102-
}
103-
104-
public Task<HtmlForm> ReadFormAsync(string selector = null)
105-
{
106-
return ReadFormAsync(LastResponse, selector);
107-
}
108-
public async Task<HtmlForm> ReadFormAsync(HttpResponseMessage response, string selector = null)
109-
{
110-
response.StatusCode.Should().Be(HttpStatusCode.OK);
111-
112-
var htmlForm = new HtmlForm
113-
{
114-
115-
};
116-
117-
var html = await response.Content.ReadAsStringAsync();
118-
119-
var dom = new CQ(html);
120-
var form = dom.Find(selector ?? "form");
121-
form.Length.Should().Be(1);
122-
123-
var postUrl = form.Attr("action");
124-
if (!postUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
125-
{
126-
if (postUrl.StartsWith("/"))
127-
{
128-
postUrl = CurrentUri.Scheme + "://" + CurrentUri.Authority + postUrl;
129-
}
130-
else
131-
{
132-
postUrl = CurrentUri + postUrl;
133-
}
134-
}
135-
htmlForm.Action = postUrl;
136-
137-
138-
var data = new Dictionary<string, string>();
139-
140-
var inputs = form.Find("input");
141-
foreach (var input in inputs)
142-
{
143-
var name = input.GetAttribute("name");
144-
var value = input.GetAttribute("value");
145-
146-
if (!data.ContainsKey(name))
147-
{
148-
data.Add(name, value);
149-
}
150-
else
151-
{
152-
data[name] = value;
153-
}
154-
}
155-
htmlForm.Inputs = data;
156-
157-
return htmlForm;
158-
}
159-
160-
161-
public Task<string> ReadElementTextAsync(string selector)
162-
{
163-
return ReadElementTextAsync(LastResponse, selector);
164-
}
165-
public async Task<string> ReadElementTextAsync(HttpResponseMessage response, string selector)
166-
{
167-
var html = await response.Content.ReadAsStringAsync();
168-
169-
var dom = new CQ(html);
170-
var element = dom.Find(selector);
171-
return element.Text();
172-
}
173-
174-
public Task<string> ReadElementAttributeAsync(string selector, string attribute)
175-
{
176-
return ReadElementAttributeAsync(LastResponse, selector, attribute);
177-
}
178-
public async Task<string> ReadElementAttributeAsync(HttpResponseMessage response, string selector, string attribute)
179-
{
180-
var html = await response.Content.ReadAsStringAsync();
181-
182-
var dom = new CQ(html);
183-
var element = dom.Find(selector);
184-
return element.Attr(attribute);
185-
}
186-
187-
public Task AssertExistsAsync(string selector)
188-
{
189-
return AssertExistsAsync(LastResponse, selector);
190-
}
191-
192-
public async Task AssertExistsAsync(HttpResponseMessage response, string selector)
193-
{
194-
response.StatusCode.Should().Be(HttpStatusCode.OK);
195-
196-
var html = await response.Content.ReadAsStringAsync();
197-
198-
var dom = new CQ(html);
199-
var element = dom.Find(selector);
200-
element.Length.Should().BeGreaterThan(0);
201-
}
202-
203-
public Task AssertNotExistsAsync(string selector)
204-
{
205-
return AssertNotExistsAsync(selector);
206-
}
207-
public async Task AssertNotExistsAsync(HttpResponseMessage response, string selector)
208-
{
209-
response.StatusCode.Should().Be(HttpStatusCode.OK);
210-
211-
var html = await response.Content.ReadAsStringAsync();
212-
213-
var dom = new CQ(html);
214-
var element = dom.Find(selector);
215-
element.Length.Should().Be(0);
216-
}
217-
218-
public Task AssertErrorPageAsync(string error = null)
219-
{
220-
return AssertErrorPageAsync(LastResponse, error);
221-
}
222-
public async Task AssertErrorPageAsync(HttpResponseMessage response, string error = null)
223-
{
224-
response.StatusCode.Should().Be(HttpStatusCode.OK);
225-
await AssertExistsAsync(response, ".error-page");
226-
227-
if (!String.IsNullOrWhiteSpace(error))
228-
{
229-
var errorText = await ReadElementTextAsync(response, ".alert.alert-danger");
230-
errorText.Should().Contain(error);
231-
}
232-
}
233-
234-
public Task AssertValidationErrorAsync(string error = null)
235-
{
236-
return AssertValidationErrorAsync(error);
237-
}
238-
public async Task AssertValidationErrorAsync(HttpResponseMessage response, string error = null)
239-
{
240-
response.StatusCode.Should().Be(HttpStatusCode.OK);
241-
await AssertExistsAsync(response, ".validation-summary-errors");
242-
243-
if (!String.IsNullOrWhiteSpace(error))
244-
{
245-
var errorText = await ReadElementTextAsync(response, ".validation-summary-errors");
246-
errorText.ToLowerInvariant().Should().Contain(error.ToLowerInvariant());
247-
}
248-
}
249-
}
250-
251-
[DebuggerDisplay("{Action}, Inputs: {Inputs.Count}")]
252-
public class HtmlForm
253-
{
254-
public HtmlForm(string action = null)
255-
{
256-
Action = action;
257-
}
258-
259-
public string Action { get; set; }
260-
public Dictionary<string, string> Inputs { get; set; } = new Dictionary<string, string>();
261-
262-
public string this[string key]
263-
{
264-
get
265-
{
266-
if (Inputs.ContainsKey(key)) return Inputs[key];
267-
return null;
268-
}
269-
set
270-
{
271-
Inputs[key] = value;
272-
}
273-
}
27478
}
27579
}

0 commit comments

Comments
 (0)