Skip to content

Commit aff8f2d

Browse files
Merge pull request #477 from EvotecIT/AOT
2 parents 25718c9 + f312264 commit aff8f2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+586
-622
lines changed

Directory.Build.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<!-- Fail builds on any compiler warning to keep the codebase clean -->
4+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
5+
<!-- Avoid Windows-specific fallback paths that don't exist in WSL/CI -->
6+
<RestoreAdditionalProjectFallbackFolders></RestoreAdditionalProjectFallbackFolders>
7+
<RestoreFallbackFolders></RestoreFallbackFolders>
8+
</PropertyGroup>
9+
</Project>

DnsClientX.Examples/DemoQuery.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static async Task ExampleSystemDns() {
109109

110110
public static async Task ExampleTLSA() {
111111
var domains = "_25._tcp.mail.ietf.org";
112-
foreach (DnsEndpoint endpoint in Enum.GetValues(typeof(DnsEndpoint))) {
112+
foreach (DnsEndpoint endpoint in Enum.GetValues<DnsEndpoint>()) {
113113
HelpersSpectre.AddLine("QueryDns", domains, DnsRecordType.TLSA, endpoint);
114114
var data = await ClientX.QueryDns(domains, DnsRecordType.TLSA, endpoint);
115115
data.DisplayTable();
@@ -118,7 +118,7 @@ public static async Task ExampleTLSA() {
118118

119119
public static async Task ExampleDS() {
120120
const string domain = "evotec.pl";
121-
foreach (DnsEndpoint endpoint in Enum.GetValues(typeof(DnsEndpoint))) {
121+
foreach (DnsEndpoint endpoint in Enum.GetValues<DnsEndpoint>()) {
122122
HelpersSpectre.AddLine("QueryDns", domain, DnsRecordType.DS, endpoint);
123123
var data = await ClientX.QueryDns(domain, DnsRecordType.DS, endpoint);
124124
data.DisplayTable();
@@ -127,7 +127,7 @@ public static async Task ExampleDS() {
127127

128128
public static async Task ExampleTXTAll() {
129129
var domains = new[] { "disneyplus.com" };
130-
foreach (DnsEndpoint endpoint in Enum.GetValues(typeof(DnsEndpoint))) {
130+
foreach (DnsEndpoint endpoint in Enum.GetValues<DnsEndpoint>()) {
131131
HelpersSpectre.AddLine("QueryDns", "disneyplus.com", DnsRecordType.TXT, endpoint);
132132
var data = await ClientX.QueryDns(domains, DnsRecordType.TXT, endpoint);
133133
foreach (var d in data[0].Answers) {
@@ -197,7 +197,7 @@ public static async Task ExampleSPFQuad() {
197197
Settings.Logger.WriteInformation(data.Answers[0].Data);
198198
}
199199

200-
foreach (DnsEndpoint endpoint in Enum.GetValues(typeof(DnsEndpoint))) {
200+
foreach (DnsEndpoint endpoint in Enum.GetValues<DnsEndpoint>()) {
201201
HelpersSpectre.AddLine("QueryDns", "disneyplus.com", DnsRecordType.SPF, endpoint);
202202
using (var client1 = new ClientX(endpoint, DnsSelectionStrategy.First) {
203203
Debug = false

DnsClientX.Examples/DemoResolveParallelDNSBL.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static async Task Example() {
136136
string ipAddress = "89.74.48.96";
137137

138138
// Reverse the IP address and append the DNSBL list
139-
string reversedIp = string.Join(".", ipAddress.Split('.').Reverse());
139+
string reversedIp = string.Join(".", Enumerable.Reverse(ipAddress.Split('.')));
140140

141141
List<string> queries = new List<string>();
142142
foreach (var dnsbl in dnsBlacklist) {

DnsClientX.Tests/CompareProvidersResolve.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task CompareRecordsImproved(string name, DnsRecordType resourceReco
4949
output.WriteLine($"Testing record: {name}, type: {resourceRecordType}");
5050

5151
var primaryEndpoint = DnsEndpoint.Cloudflare;
52-
var allEndpoints = Enum.GetValues(typeof(DnsEndpoint)).Cast<DnsEndpoint>()
52+
var allEndpoints = EndpointTestHelpers.AllEndpoints()
5353
.Where(e => e != primaryEndpoint && (excludedEndpoints == null || !excludedEndpoints.Contains(e)))
5454
.ToArray();
5555

@@ -216,7 +216,7 @@ public async Task CompareRecords(string name, DnsRecordType resourceRecordType,
216216
using var Client = new ClientX(primaryEndpoint);
217217
DnsResponse aAnswersPrimary = await Client.Resolve(name, resourceRecordType);
218218

219-
foreach (var endpointCompare in Enum.GetValues(typeof(DnsEndpoint)).Cast<DnsEndpoint>()) {
219+
foreach (var endpointCompare in EndpointTestHelpers.AllEndpoints()) {
220220
if (endpointCompare == primaryEndpoint) {
221221
continue;
222222
}

DnsClientX.Tests/CompareProvidersResolveAll.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task CompareRecordsImproved(string name, DnsRecordType resourceReco
3939
output.WriteLine($"Testing record: {name}, type: {resourceRecordType}");
4040

4141
var primaryEndpoint = DnsEndpoint.Cloudflare;
42-
var allEndpoints = Enum.GetValues(typeof(DnsEndpoint)).Cast<DnsEndpoint>()
42+
var allEndpoints = EndpointTestHelpers.AllEndpoints()
4343
.Where(e => e != primaryEndpoint && (excludedEndpoints == null || !excludedEndpoints.Contains(e)))
4444
.ToArray();
4545

@@ -193,7 +193,7 @@ public async Task CompareRecords(string name, DnsRecordType resourceRecordType,
193193
using var Client = new ClientX(primaryEndpoint);
194194
DnsAnswer[] aAnswersPrimary = await Client.ResolveAll(name, resourceRecordType);
195195

196-
foreach (var endpointCompare in Enum.GetValues(typeof(DnsEndpoint)).Cast<DnsEndpoint>()) {
196+
foreach (var endpointCompare in EndpointTestHelpers.AllEndpoints()) {
197197
if (endpointCompare == primaryEndpoint) {
198198
continue;
199199
}

DnsClientX.Tests/CompareProvidersResolveFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task CompareRecordsImproved(string name, DnsRecordType resourceReco
2424

2525
string filter = "v=spf1";
2626
var primaryEndpoint = DnsEndpoint.Cloudflare;
27-
var allEndpoints = Enum.GetValues(typeof(DnsEndpoint)).Cast<DnsEndpoint>()
27+
var allEndpoints = EndpointTestHelpers.AllEndpoints()
2828
.Where(e => e != primaryEndpoint && (excludedEndpoints == null || !excludedEndpoints.Contains(e)))
2929
.ToArray();
3030

@@ -166,7 +166,7 @@ public async Task CompareRecords(string name, DnsRecordType resourceRecordType,
166166
using var Client = new ClientX(primaryEndpoint);
167167
DnsResponse aAnswersPrimary = await Client.ResolveFilter(name, resourceRecordType, filter);
168168

169-
foreach (var endpointCompare in Enum.GetValues(typeof(DnsEndpoint)).Cast<DnsEndpoint>()) {
169+
foreach (var endpointCompare in EndpointTestHelpers.AllEndpoints()) {
170170
if (endpointCompare == primaryEndpoint) {
171171
continue;
172172
}
@@ -262,7 +262,7 @@ public async Task CompareRecordsMulti(string[] names, DnsRecordType resourceReco
262262

263263
DnsResponse[] aAnswersPrimary = await Client.ResolveFilter(names, resourceRecordType, filter);
264264

265-
foreach (var endpointCompare in Enum.GetValues(typeof(DnsEndpoint)).Cast<DnsEndpoint>()) {
265+
foreach (var endpointCompare in EndpointTestHelpers.AllEndpoints()) {
266266
if (endpointCompare == primaryEndpoint) {
267267
continue;
268268
}

DnsClientX.Tests/DebuggingHelpersTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.IO;
23
using System.Reflection;
34
using Xunit;
@@ -9,10 +10,14 @@ namespace DnsClientX.Tests {
910
public class DebuggingHelpersTests {
1011
private class CapturingLogger : InternalLogger {
1112
public string? LastMessage { get; private set; }
13+
public List<string> Messages { get; } = new();
1214
private readonly EventHandler<LogEventArgs> _handler;
1315

1416
public CapturingLogger() {
15-
_handler = (_, e) => LastMessage = e.FullMessage;
17+
_handler = (_, e) => {
18+
LastMessage = e.FullMessage;
19+
Messages.Add(e.FullMessage);
20+
};
1621
OnDebugMessage += _handler;
1722
}
1823

@@ -51,7 +56,7 @@ public void TroubleshootingDnsWire4_ReadsValueAndLogs() {
5156
uint result = DebuggingHelpers.TroubleshootingDnsWire4(reader, "test");
5257
logger.Freeze();
5358
Assert.Equal(0x01020304u, result);
54-
Assert.Contains("01-02-03-04", logger.LastMessage);
59+
Assert.Contains(logger.Messages, m => m.Contains("01-02-03-04"));
5560
}
5661
}
5762
}

DnsClientX.Tests/DnsClientX.Tests.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
</PackageReference>
4141
<PackageReference Include="System.Net.Http" Version="4.3.4"
4242
Condition="'$(TargetFramework)' == 'net472'" />
43+
<PackageReference Include="System.Text.Json" Version="8.0.5"
44+
Condition="'$(TargetFramework)' == 'net472'" />
45+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0"
46+
Condition="'$(TargetFramework)' == 'net472'" />
4347
</ItemGroup>
4448

4549
<ItemGroup>
@@ -52,4 +56,4 @@
5256
</ItemGroup>
5357

5458

55-
</Project>
59+
</Project>

DnsClientX.Tests/DnsEndpointDescriptionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class DnsEndpointDescriptionTests {
1212
/// </summary>
1313
[Fact]
1414
public void AllEndpointsHaveDescriptions() {
15-
foreach (DnsEndpoint ep in Enum.GetValues(typeof(DnsEndpoint))) {
15+
foreach (DnsEndpoint ep in EndpointTestHelpers.AllEndpoints()) {
1616
string desc = ep.GetDescription();
1717
Assert.False(string.IsNullOrWhiteSpace(desc));
1818
}

DnsClientX.Tests/DnsEndpointExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class DnsEndpointExtensionsTests {
1313
[Fact]
1414
public void GetAllWithDescriptions_ReturnsAllEndpoints() {
1515
var all = DnsEndpointExtensions.GetAllWithDescriptions().ToList();
16-
int expectedCount = Enum.GetValues(typeof(DnsEndpoint)).Length;
16+
int expectedCount = EndpointTestHelpers.AllEndpoints().Length;
1717
Assert.Equal(expectedCount, all.Count);
1818
Assert.All(all, pair => Assert.False(string.IsNullOrWhiteSpace(pair.Description)));
1919
}

0 commit comments

Comments
 (0)