Repository navigation
Add .NET 9.0 to app and tests; set roll-forward; update Rider config #20
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
Changes from all commits
f7cd660
67119f3
88cf4fc
98e65ce
cdd1537
5f8b5f0
07f2956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,20 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| namespace yTools.Tests | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| [TestClass] | ||||||||||||||||||||||||||||||||||||||||||||
| public class SerializationTests | ||||||||||||||||||||||||||||||||||||||||||||
| public class SerializationTests | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| private readonly char _sep = General.PathSeparator; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| [TestCleanup] | ||||||||||||||||||||||||||||||||||||||||||||
| public void Cleanup() | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| const string testDirectory = "yTools"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| var fullDir = $"{Environment.GetFolderPath( | ||||||||||||||||||||||||||||||||||||||||||||
| Environment.SpecialFolder.LocalApplicationData | ||||||||||||||||||||||||||||||||||||||||||||
| )}{_sep}{testDirectory}"; | ||||||||||||||||||||||||||||||||||||||||||||
| if (Directory.Exists(fullDir)) | ||||||||||||||||||||||||||||||||||||||||||||
| Directory.Delete(fullDir, true); | ||||||||||||||||||||||||||||||||||||||||||||
| try | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| const string testDirectory = "yTools"; | ||||||||||||||||||||||||||||||||||||||||||||
| var fullDir = $"{Environment.GetFolderPath( | ||||||||||||||||||||||||||||||||||||||||||||
| Environment.SpecialFolder.LocalApplicationData | ||||||||||||||||||||||||||||||||||||||||||||
| )}{_sep}{testDirectory}"; | ||||||||||||||||||||||||||||||||||||||||||||
| if (Directory.Exists(fullDir)) | ||||||||||||||||||||||||||||||||||||||||||||
| Directory.Delete(fullDir, true); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (Directory.Exists("./test-serialization")) | ||||||||||||||||||||||||||||||||||||||||||||
| Directory.Delete("./test-serialization", true); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| catch | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| Console.WriteLine("Something went wrong when cleaning up."); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| [TestMethod] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -24,14 +33,7 @@ public void CheckObjectsJsonSerialized() | |||||||||||||||||||||||||||||||||||||||||||
| TestSerializationObject testObject2 = new("Good Morning.", -8485, -6498.948); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| JsonSerializer serializer = new(); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| var directory = $"yTools{_sep}Tests{_sep}Serialization"; | ||||||||||||||||||||||||||||||||||||||||||||
| serializer.SetSerializationDirectoryInLocalAppData(directory); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Assert.IsTrue(Directory.Exists( | ||||||||||||||||||||||||||||||||||||||||||||
| $"{Environment.GetFolderPath( | ||||||||||||||||||||||||||||||||||||||||||||
| Environment.SpecialFolder.LocalApplicationData | ||||||||||||||||||||||||||||||||||||||||||||
| )}{_sep}{directory}")); | ||||||||||||||||||||||||||||||||||||||||||||
| serializer.SetSerializationDirectory("./test-serialization"); | ||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| bool serialized = serializer.SerializeInDefault("testObject1.json", testObject1, out Exception? exception, out _); | ||||||||||||||||||||||||||||||||||||||||||||
| if (!serialized && exception != null) throw exception; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,14 +58,7 @@ public void CheckObjectsXmlSerialized() | |||||||||||||||||||||||||||||||||||||||||||
| TestSerializationObject testObject2 = new("Good Morning.", -8485, -6498.948); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| XmlSerializer serializer = new(); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| var directory = $"yTools{_sep}Tests{_sep}Serialization"; | ||||||||||||||||||||||||||||||||||||||||||||
| serializer.SetSerializationDirectoryInLocalAppData(directory); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Assert.IsTrue(Directory.Exists( | ||||||||||||||||||||||||||||||||||||||||||||
| $"{Environment.GetFolderPath( | ||||||||||||||||||||||||||||||||||||||||||||
| Environment.SpecialFolder.LocalApplicationData | ||||||||||||||||||||||||||||||||||||||||||||
| )}{_sep}{directory}")); | ||||||||||||||||||||||||||||||||||||||||||||
| serializer.SetSerializationDirectory("./test-serialization"); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| bool serialized = serializer.SerializeInDefault("testObject1.xml", testObject1, out Exception? exception, out _); | ||||||||||||||||||||||||||||||||||||||||||||
| if (!serialized && exception != null) throw exception; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -92,7 +87,7 @@ public void CheckSerializationDirCreated() | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| jsonSerializer.Serialize(testObj, "json.json", $@"{baseDir}{_sep}json", out _, out _); | ||||||||||||||||||||||||||||||||||||||||||||
| Assert.IsTrue(Directory.Exists($"{baseDir}{_sep}json")); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
88
to
89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check serialization results to diagnose the pipeline failure. Lines 81 and 84 discard the serialization return value and exception with Apply this diff to detect serialization failures: - jsonSerializer.Serialize(testObj, "json.json", $@"{baseDir}{_sep}json", out _, out _);
+ var jsonSuccess = jsonSerializer.Serialize(testObj, "json.json", $@"{baseDir}{_sep}json", out var jsonEx, out _);
+ if (!jsonSuccess && jsonEx != null) throw jsonEx;
Assert.IsTrue(Directory.Exists($"{baseDir}{_sep}json"));
- xmlSerializer.Serialize(testObj, "xml.xml", $@"{baseDir}{_sep}xml", out _, out _);
+ var xmlSuccess = xmlSerializer.Serialize(testObj, "xml.xml", $@"{baseDir}{_sep}xml", out var xmlEx, out _);
+ if (!xmlSuccess && xmlEx != null) throw xmlEx;
Assert.IsTrue(Directory.Exists($"{baseDir}{_sep}xml"));This change will surface the root cause of the failed assertion and help resolve the pipeline failure. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: .NET[error] 82-82: Assert.IsTrue failed in CheckSerializationDirCreated(). 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| xmlSerializer.Serialize(testObj, "xml.xml", $@"{baseDir}{_sep}xml", out _, out _); | ||||||||||||||||||||||||||||||||||||||||||||
| Assert.IsTrue(Directory.Exists($"{baseDir}{_sep}xml")); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -131,4 +126,4 @@ public void CheckSerializeException() | |||||||||||||||||||||||||||||||||||||||||||
| Console.WriteLine($"Type of XML exception: {ex.GetType()}"); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
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.
🧩 Analysis chain
Implement retry logic for locked file handles.
The try-catch wrapper silences cleanup failures but doesn't address the locked file handle issue flagged in past reviews. Pipeline failures indicate
Directory.Deletefails with "Directory not empty" errors, likely due to file handles remaining open after tests complete.Consider implementing retry logic with backoff as suggested in previous reviews:
[TestCleanup] public void Cleanup() { - try - { - const string testDirectory = "yTools"; - var fullDir = $"{Environment.GetFolderPath( - Environment.SpecialFolder.LocalApplicationData - )}{_sep}{testDirectory}"; - if (Directory.Exists(fullDir)) - Directory.Delete(fullDir, true); + const string testDirectory = "yTools"; + var fullDir = $"{Environment.GetFolderPath( + Environment.SpecialFolder.LocalApplicationData + )}{_sep}{testDirectory}"; + + TryDeleteDirectory(fullDir); + TryDeleteDirectory("./test-serialization"); +} + +private static void TryDeleteDirectory(string path, int maxAttempts = 3) +{ + if (!Directory.Exists(path)) return; + + for (int attempt = 0; attempt < maxAttempts; attempt++) + { + try + { + Directory.Delete(path, true); + return; + } + catch (IOException) when (attempt < maxAttempts - 1) + { + Thread.Sleep(100); + } + catch (UnauthorizedAccessException) when (attempt < maxAttempts - 1) + { + Thread.Sleep(100); + } + } + + // Log failure after all retries + Console.WriteLine($"Failed to delete directory: {path}"); +}Alternatively, ensure serializers in
CheckSerializationDirCreatedare properly disposed usingusingstatements if they implementIDisposable.Based on past review comments.
🏁 Script executed:
Length of output: 6160
🏁 Script executed:
Length of output: 799
Replace broad try-catch in Cleanup with retry logic for Directory.Delete
Implement a helper like
TryDeleteDirectory(path, maxAttempts)that retries onIOException/UnauthorizedAccessExceptionwith a short backoff, and call it for both cleanup paths instead of silencing failures:Call
TryDeleteDirectory(fullDir)andTryDeleteDirectory("./test-serialization")inCleanup.🤖 Prompt for AI Agents