Пример #1
0
        public async Task WithBcl(string path)
        {
            // Arrange
            using (var stream = TestUtility.BufferTestData(path))
            {
                // Act
                var miniZip = await TestUtility.ReadWithMiniZipAsync(stream);

                var bcl = TestUtility.ReadWithBcl(stream);

                // Assert
                if (CasesHandledByBcl.TryGetValue(path, out var knownException))
                {
                    Assert.Equal(knownException.Type, miniZip.Exception.GetType());
                    Assert.Equal(knownException.Message, miniZip.Exception.Message);
                    Assert.True(bcl.Success);
                }
                else if (CasesNotHandledByBcl.TryGetValue(path, out knownException))
                {
                    Assert.Equal(knownException.Type, bcl.Exception.GetType());
                    Assert.Equal(knownException.Message, bcl.Exception.Message);
                    Assert.True(miniZip.Success);
                }
                else
                {
                    Assert.Equal(bcl.Success, miniZip.Success);
                    if (miniZip.Success)
                    {
                        Assert.Equal(bcl.Data.Count, miniZip.Data.Entries.Count);

                        var nameToBcl = bcl
                                        .Data
                                        .OrderBy(x => x.FullName)
                                        .ThenBy(x => x.CompressedLength)
                                        .ThenBy(x => x.Length)
                                        .ThenBy(x => x.ExternalAttributes)
                                        .ThenBy(x => x.LastWriteTime)
                                        .ToLookup(x => x.FullName);

                        var nameToMiniZip = miniZip
                                            .Data
                                            .Entries
                                            .OrderBy(x => x.GetName())
                                            .ThenBy(x => x.CompressedSize)
                                            .ThenBy(x => x.UncompressedSize)
                                            .ThenBy(x => x.ExternalAttributes)
                                            .ThenBy(x => x.GetLastModified())
                                            .ToLookup(x => x.GetName());

                        foreach (var name in nameToMiniZip.Select(x => x.Key))
                        {
                            var bclEntries     = nameToBcl[name].ToList();
                            var miniZipEntries = nameToMiniZip[name].ToList();

                            Assert.Equal(bclEntries.Count, miniZipEntries.Count);
                            for (var i = 0; i < bclEntries.Count; i++)
                            {
                                Assert.Equal((ulong)bclEntries[i].CompressedLength, miniZipEntries[i].GetCompressedSize());
                                Assert.Equal((ulong)bclEntries[i].Length, miniZipEntries[i].GetUncompressedSize());
                                Assert.Equal((uint)bclEntries[i].ExternalAttributes, miniZipEntries[i].ExternalAttributes);
                                Assert.Equal(bclEntries[i].LastWriteTime.DateTime, miniZipEntries[i].GetLastModified());
                            }
                        }
                    }
                }
            }
        }