Skip to content

Commit 78080ba

Browse files
authored
Remove unnecessary CA2022 suppressions (#47904)
1 parent 496a47a commit 78080ba

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

test/dotnet.Tests/CommandTests/Solution/Add/GivenDotnetSlnAdd.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,22 @@ public void WhenProjectIsAddedSolutionHasUTF8BOM(string solutionCommand)
583583
using (var stream = new FileStream(Path.Combine(projectDirectory, "App.sln"), FileMode.Open))
584584
{
585585
var bytes = new byte[preamble.Length];
586-
#pragma warning disable CA2022 // Avoid inexact read
587-
stream.Read(bytes, 0, bytes.Length);
588-
#pragma warning restore CA2022 // Avoid inexact read
586+
#if NET
587+
stream.ReadExactly(bytes, 0, bytes.Length);
588+
#else
589+
int offset = 0;
590+
int count = bytes.Length;
591+
while (count > 0)
592+
{
593+
int read = stream.Read(bytes, offset, count);
594+
if (read <= 0)
595+
{
596+
throw new EndOfStreamException();
597+
}
598+
offset += read;
599+
count -= read;
600+
}
601+
#endif
589602
bytes.Should().BeEquivalentTo(preamble);
590603
}
591604
}

test/dotnet.Tests/CommandTests/Solution/Remove/GivenDotnetSlnRemove.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,22 @@ public void WhenProjectIsRemovedSolutionHasUTF8BOM(string solutionCommand)
544544
using (var stream = new FileStream(Path.Combine(projectDirectory, "App.sln"), FileMode.Open))
545545
{
546546
var bytes = new byte[preamble.Length];
547-
#pragma warning disable CA2022 // Avoid inexact read
548-
stream.Read(bytes, 0, bytes.Length);
549-
#pragma warning restore CA2022 // Avoid inexact read
547+
#if NET
548+
stream.ReadExactly(bytes, 0, bytes.Length);
549+
#else
550+
int offset = 0;
551+
int count = bytes.Length;
552+
while (count > 0)
553+
{
554+
int read = stream.Read(bytes, offset, count);
555+
if (read <= 0)
556+
{
557+
throw new EndOfStreamException();
558+
}
559+
offset += read;
560+
count -= read;
561+
}
562+
#endif
550563
bytes.Should().BeEquivalentTo(preamble);
551564
}
552565
}

0 commit comments

Comments
 (0)