Lab8#44
Open
slavik22 wants to merge 34 commits into
Open
Conversation
Lab2 smells
…for testability - Add ITcpListener interface and TcpListenerWrapper to decouple TcpListener - Extract EchoServer into EchoServer.cs with injected ITcpListener and logger - Extract UdpTimedSender into its own file; move Random to field to avoid per-call allocation - Make HandleClientAsync public and accept Stream for direct unit testing - Reduce Program.cs to entry-point only
…r and UdpTimedSender - EchoServerTests: StartAsync lifecycle, HandleClientAsync echo logic, cancellation, stream exception handling, client connect/disconnect logging - UdpTimedSenderTests: double-start guard, stop without start, restart after stop, dispose lifecycle
…ull-forgiving operator on _cts
…pression, replace O(n) Count() loop in GetSamples with index-based iteration
…er and double-connect guard
- Wrap independent asserts in Assert.Multiple across test files - Replace Has.Count / .Count() on IEnumerable with Has.Exactly(n).Items - Switch ReadAsync/WriteAsync to Memory-based overloads (S4583) - Make _cts readonly in TcpClientWrapper; fix null-forgiving operator - Split GetSamples into guard + private iterator (S3972) - Fix IDisposable pattern in UdpTimedSender with Dispose(bool) - Make _udpClient_MessageReceived static (S2325) - Remove TODO comment; fix empty while block in Program.cs - Add ErrorStream helper replacing Mock<Stream> for exception tests
…s; add coverlet.msbuild to EchoTcpServerTests
- Replace same-argument GetHashCode assertion with captured variable (NUnit2009)
- Use Is.EqualTo/Is.Not.EqualTo on objects directly instead of .Equals()+Is.True/False
- Replace Is.Not.EqualTo("string") with new object() to avoid NUnit2021 (incompatible types)
- Add coverlet.msbuild to EchoTcpServerTests.csproj so /p:CollectCoverage=true produces
an OpenCover report; without it EchoTcpServer coverage was silently absent from SonarCloud
Integration tests spin up a local TcpListener on a random port so the wrapper's SendBytesAsync (WriteAsync(data.AsMemory())) and StartListeningAsync (ReadAsync(buffer.AsMemory(), token)) paths are exercised — the three new lines changed in lab8 that had 0% coverage. Also adds disconnect-when-not-connected and send-when-not-connected edge-case tests to cover the guard branches.
SonarCloud rule S3903 flags types not in a named namespace. File-scoped namespace syntax (namespace X;) is not recognized by older SonarCloud C# plugin versions. Converted all EchoTcpServer and EchoTcpServerTests files to block-style namespaces to resolve the two open issues.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Uh oh!
There was an error while loading. Please reload this page.