-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat(dns): ✨ Refactor DNS processing and JSON serialization #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7947dec
feat(dns): ✨ Refactor DNS processing and JSON serialization
PrzemyslawKlys 05d56aa
refactor(dns): 🔧 Update Enum.GetValues usage for DnsEndpoint
PrzemyslawKlys 8ab01db
test(dns): 🧪 Update tests for concurrency and error handling
PrzemyslawKlys ee3f32b
feat(tests): ✨ Add JSON serialization tests for request models
PrzemyslawKlys 78003d7
test(dns): 🧪 Enhance DNS tests with optional fields and error handling
PrzemyslawKlys f312264
feat(tests): ✨ Add System.Text.Json and Microsoft.Bcl.AsyncInterfaces…
PrzemyslawKlys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <!-- Fail builds on any compiler warning to keep the codebase clean --> | ||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
| <!-- Avoid Windows-specific fallback paths that don't exist in WSL/CI --> | ||
| <RestoreAdditionalProjectFallbackFolders></RestoreAdditionalProjectFallbackFolders> | ||
| <RestoreFallbackFolders></RestoreFallbackFolders> | ||
| </PropertyGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using System.Text.Json; | ||
| using DnsClientX; | ||
| using Xunit; | ||
|
|
||
| namespace DnsClientX.Tests { | ||
| /// <summary> | ||
| /// Verifies JSON serialization for request models used by DoH POST paths. | ||
| /// </summary> | ||
| public class DnsJsonModelsTests { | ||
| /// <summary> | ||
| /// ResolveRequest should serialize expected property names and omit null/zero values. | ||
| /// </summary> | ||
| [Fact] | ||
| public void ResolveRequest_Serializes_WithExpectedNames() { | ||
| var model = new ResolveRequest { Name = "example.com", Type = "A", Do = 1 }; | ||
| string json = DnsJson.Serialize(model, DnsJsonContext.Default.ResolveRequest); | ||
| using var doc = JsonDocument.Parse(json); | ||
| var root = doc.RootElement; | ||
| Assert.Equal("example.com", root.GetProperty("name").GetString()); | ||
| Assert.Equal("A", root.GetProperty("type").GetString()); | ||
| Assert.Equal(1, root.GetProperty("do").GetInt32()); | ||
| Assert.False(root.TryGetProperty("cd", out _)); // cd omitted when zero/null | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// ResolveRequest should omit null Name and Type and allow DO/CD toggles. | ||
| /// </summary> | ||
| [Fact] | ||
| public void ResolveRequest_Serializes_OptionalFields() { | ||
| var model = new ResolveRequest { Name = "example.com", Do = null, Cd = 1 }; | ||
| string json = DnsJson.Serialize(model, DnsJsonContext.Default.ResolveRequest); | ||
| using var doc = JsonDocument.Parse(json); | ||
| var root = doc.RootElement; | ||
| Assert.Equal("example.com", root.GetProperty("name").GetString()); | ||
| Assert.False(root.TryGetProperty("type", out _)); | ||
| Assert.False(root.TryGetProperty("do", out _)); | ||
| Assert.Equal(1, root.GetProperty("cd").GetInt32()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// UpdateRequest should serialize all fields with expected JSON property names. | ||
| /// </summary> | ||
| [Fact] | ||
| public void UpdateRequest_Serializes_WithExpectedNames() { | ||
| var model = new UpdateRequest { Zone = "example.com", Name = "host", Type = "A", Data = "1.1.1.1", Ttl = 120 }; | ||
| string json = DnsJson.Serialize(model, DnsJsonContext.Default.UpdateRequest); | ||
| using var doc = JsonDocument.Parse(json); | ||
| var root = doc.RootElement; | ||
| Assert.Equal("example.com", root.GetProperty("zone").GetString()); | ||
| Assert.Equal("host", root.GetProperty("name").GetString()); | ||
| Assert.Equal("A", root.GetProperty("type").GetString()); | ||
| Assert.Equal("1.1.1.1", root.GetProperty("data").GetString()); | ||
| Assert.Equal(120, root.GetProperty("ttl").GetInt32()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This foreach loop immediately maps its iteration variable to another variable - consider mapping the sequence explicitly using '.Select(...)'.