Skip to content

Commit c0d31aa

Browse files
committed
fix: IO 测试 net471 兼容(续):修复 IndexOf/EndsWith/Replace/StringComparison、Split/StringSplitOptions、await using(IAsyncDisposable),补 System.Runtime.CompilerServices.Unsafe
1 parent 0cc74c4 commit c0d31aa

6 files changed

Lines changed: 14 additions & 10 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />
3030
<!-- netstandard2.0 polyfills for Magicodes.IE.IO -->
3131
<PackageVersion Include="System.Memory" Version="4.5.5" />
32+
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
3233
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
3334
<PackageVersion Include="PolySharp" Version="1.15.0" />
3435
<!-- Transitive CVE overrides (Stage 2 Step 6): see Excel.NPOI.csproj for context.

tests/Magicodes.IE.IO.Tests/Magicodes.IE.IO.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<ItemGroup>
3030
<PackageReference Include="System.Memory" Condition="'$(TargetFramework)' == 'net471'" />
31+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Condition="'$(TargetFramework)' == 'net471'" />
3132
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net471" Condition="'$(TargetFramework)' == 'net471'" PrivateAssets="all" />
3233
</ItemGroup>
3334

tests/Magicodes.IE.IO.Tests/XlsxIO_EdgeCases_Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ async Task<byte[]> Async()
201201
[Fact]
202202
public async Task CompleteAsync_FailureIsFaultedAndCannotResume()
203203
{
204-
await using var output = new XlsxIO_TestSupport.ThrowOnAsyncWriteStream();
205-
await using var writer = new XlsxWriter(output, "Sheet1");
204+
using var output = new XlsxIO_TestSupport.ThrowOnAsyncWriteStream();
205+
using var writer = new XlsxWriter(output, "Sheet1");
206206
writer.WriteHeader(XlsxIO_TestSupport.MakeCols());
207207
var first = await Should.ThrowAsync<IOException>(() => writer.CompleteAsync());
208208
var second = await Should.ThrowAsync<IOException>(() => writer.CompleteAsync());

tests/Magicodes.IE.IO.Tests/XlsxIO_Features_Tests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ public async Task SetOutline_AppearsInSheetFormatPr()
440440
var xml = XlsxIO_TestSupport.ReadEntry(ms.ToArray(), "xl/worksheets/sheet1.xml");
441441
xml.ShouldContain("summaryBelow=\"0\"");
442442
xml.ShouldContain("summaryRight=\"0\"");
443-
xml.IndexOf("<sheetPr", StringComparison.Ordinal).ShouldBeLessThan(xml.IndexOf("<sheetViews", StringComparison.Ordinal));
443+
System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(xml, "<sheetPr", System.Globalization.CompareOptions.Ordinal)
444+
.ShouldBeLessThan(System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(xml, "<sheetViews", System.Globalization.CompareOptions.Ordinal));
444445
}
445446

446447
[Fact]
@@ -680,8 +681,9 @@ public void SheetProtection_PrecedesAutoFilterInWorksheetXml()
680681
}
681682

682683
var xml = XlsxIO_TestSupport.ReadEntry(ms.ToArray(), "xl/worksheets/sheet1.xml");
683-
xml.IndexOf("<sheetProtection", StringComparison.Ordinal).ShouldBeLessThan(
684-
xml.IndexOf("<autoFilter", StringComparison.Ordinal));
684+
System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(xml, "<sheetProtection", System.Globalization.CompareOptions.Ordinal)
685+
.ShouldBeLessThan(
686+
System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(xml, "<autoFilter", System.Globalization.CompareOptions.Ordinal));
685687
}
686688

687689
[Fact]

tests/Magicodes.IE.IO.Tests/XlsxIO_Styles_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public async Task EveryCell_HasRAttribute_RequiredBySpec()
206206
new OrderDto { OrderNo = "A2", Amount = 2m, CreatedAt = new DateTime(2024, 1, 2) },
207207
});
208208
var xml = XlsxIO_TestSupport.ReadEntry(bytes, "xl/worksheets/sheet1.xml");
209-
int cellCount = xml.Split("<c ", StringSplitOptions.RemoveEmptyEntries).Length - 1;
209+
int cellCount = xml.Split(new[] { "<c " }, StringSplitOptions.RemoveEmptyEntries).Length - 1;
210210
int cellsWithR = System.Text.RegularExpressions.Regex.Matches(xml, "<c r=\"[A-Z]+\\d+\"").Count;
211211
cellCount.ShouldBe(cellsWithR, $"每个 <c> 都需要 r=\"A1\" — 缺 {cellCount - cellsWithR} 个");
212212
}

tests/Magicodes.IE.IO.Tests/XlsxIO_TestSupport.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ public static void AssertWellFormedXlsx(byte[] bytes)
274274
}
275275
foreach (var entry in zip.Entries)
276276
{
277-
if (!entry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)
278-
&& !entry.FullName.EndsWith(".rels", StringComparison.OrdinalIgnoreCase)) continue;
277+
if (!entry.FullName.EndsWith(".xml")
278+
&& !entry.FullName.EndsWith(".rels")) continue;
279279
using var es = entry.Open();
280280
using var sr = new StreamReader(es);
281281
var xml = sr.ReadToEnd();
@@ -287,11 +287,11 @@ public static void AssertWellFormedXlsx(byte[] bytes)
287287

288288
public static void AssertPackageGraph(ZipArchive zip)
289289
{
290-
foreach (var relsEntry in zip.Entries.Where(e => e.FullName.EndsWith(".rels", StringComparison.OrdinalIgnoreCase)))
290+
foreach (var relsEntry in zip.Entries.Where(e => e.FullName.EndsWith(".rels")))
291291
{
292292
string sourcePart = relsEntry.FullName == "_rels/.rels"
293293
? ""
294-
: relsEntry.FullName.Substring(0, relsEntry.FullName.Length - ".rels".Length).Replace("/_rels/", "/", StringComparison.Ordinal);
294+
: relsEntry.FullName.Substring(0, relsEntry.FullName.Length - ".rels".Length).Replace("/_rels/", "/");
295295
var doc = new XmlDocument { XmlResolver = null };
296296
using (var stream = relsEntry.Open()) doc.Load(stream);
297297
var ns = new XmlNamespaceManager(doc.NameTable);

0 commit comments

Comments
 (0)