Example #1
0
        public void CompressedArchiveAccess_RegisterWithForbiddenFormat_ThrowsArgumentOutOfRangeException()
        {
            var implementation = this.GetFakeCompressedArchiveAccessImplementationForTest();

            Assert.Throws <ArgumentOutOfRangeException>(() => CompressedArchiveAccess.RegisterFactory(
                                                            CompressedArchiveFormat.None,
                                                            implementation,
                                                            (s, m) => TestCompressedArchiveAccess.Create(s, m, CompressedArchiveFormat.None, implementation)));
        }
Example #2
0
        public void CompressedArchiveAccess_RegisterFactoryWithForbiddenImplementationValue_ThrowsArgumentOutOfRangeException(CompressedArchiveAccessImplementation implementation)
        {
            var format = this.GetFakeCompressedArchiveFormatForTest();

            Assert.Throws <ArgumentOutOfRangeException>(() => CompressedArchiveAccess.RegisterFactory(
                                                            format,
                                                            implementation,
                                                            (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementation)));
        }
Example #3
0
        public void CompressedArchiveAccess_FileBasedArchiveDeleteEntry_Succeeds()
        {
            var format        = this.RegisterFakeFormatForTest(registerFormat: true);
            var fileExtension = format.FileExtensions().First();

            using (var tempFile = new TemporaryFile(fileExtension, createFile: true))
            {
                using (var archive = CompressedArchiveAccess.Open(tempFile.FilePath, CompressedArchiveAccessMode.Update))
                {
                    var testArchive = TestCompressedArchiveAccess.GetFromCompressedArchiveFileAccess(archive);
                    var entryName   = testArchive.AddFakeEntries(2);
                    Assert.True(archive.DeleteEntry(entryName));
                }
            }
        }
Example #4
0
        public void CompressedArchiveAccess_FileBasedArchiveFindEntryUsingAbsolutePath_Succeeds()
        {
            var format        = this.RegisterFakeFormatForTest(registerFormat: true);
            var fileExtension = format.FileExtensions().First();

            using (var tempFile = new TemporaryFile(fileExtension, createFile: true))
            {
                using (var archive = CompressedArchiveAccess.Open(tempFile.FilePath, CompressedArchiveAccessMode.Read))
                {
                    var testArchive        = TestCompressedArchiveAccess.GetFromCompressedArchiveFileAccess(archive);
                    var firstEntryName     = testArchive.AddFakeEntries(3);
                    var firstEntryFullpath = Path.Combine(tempFile.FilePath, firstEntryName);
                    Assert.NotNull(archive.FindEntry(firstEntryFullpath));
                }
            }
        }
Example #5
0
            public static TestCompressedArchiveAccess Create(
                Stream stream,
                CompressedArchiveAccessMode mode,
                CompressedArchiveFormat format,
                CompressedArchiveAccessImplementation implementation,
                string firstEntryName = null,
                bool isArchive        = true,
                bool isCompressed     = true)
            {
                var testArchiveAccess = new TestCompressedArchiveAccess()
                {
                    Mode = mode, _format = format, Implementation = implementation
                };

                testArchiveAccess._isArchive    = isArchive;
                testArchiveAccess._isCompressed = isCompressed;
                if (!string.IsNullOrWhiteSpace(firstEntryName))
                {
                    testArchiveAccess.CreateAndAddEntry(firstEntryName);
                }
                return(testArchiveAccess);
            }
Example #6
0
 public void CompressedArchiveAccess_ConvertCompressedArchiveAccessModeToFileMode_ReturnsExpectedFileAccess(CompressedArchiveAccessMode mode, FileAccess expectedFileAccess)
 {
     Assert.Equal(expectedFileAccess, TestCompressedArchiveAccess.ConvertModeToFileAccess(mode));
 }
Example #7
0
        public void CompressedArchiveAccess_RegisterFactoryTwice_SucceedsThenFails()
        {
            var format         = this.GetFakeCompressedArchiveFormatForTest();
            var implementation = this.GetFakeCompressedArchiveAccessImplementationForTest();

            Assert.True(CompressedArchiveAccess.RegisterFactory(format, implementation, (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementation)));

            var succeeded = CompressedArchiveAccess.RegisterFactory(format, implementation, (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementation));

            Assert.False(succeeded);
        }
Example #8
0
        private CompressedArchiveFormat RegisterFakeFormatForTest(bool registerFormat = false, string firstEntryName = null, bool isArchive = true, bool isCompressed = true)
        {
            var format         = registerFormat ? this.RegisterTestCompressedArchiveFormat() : this.GetFakeCompressedArchiveFormatForTest();
            var implementation = registerFormat ? format.GetPreferredCompressedArchiveImplementation() : this.GetFakeCompressedArchiveAccessImplementationForTest();
            var registered     = CompressedArchiveAccess.RegisterFactory(format, implementation, (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementation, firstEntryName, isArchive, isCompressed));

            Assert.True(registered);
            return(format);
        }
Example #9
0
        public void CompressedArchiveAccess_RegisterMultipleImplementationsAndCreateWithSpecificImplementation_CreatesUsingSelectedImplementation()
        {
            var format = RegisterFakeFormatForTest(registerFormat: true);

            var implementations = new[]
            {
                format.GetPreferredCompressedArchiveImplementation(),
                this.GetFakeCompressedArchiveAccessImplementationForTest(),
                this.GetFakeCompressedArchiveAccessImplementationForTest()
            };

            Assert.True(format.AddImplementation(implementations[1], makePreferred: false));
            Assert.True(format.AddImplementation(implementations[2], makePreferred: false));
            Assert.True(CompressedArchiveAccess.RegisterFactory(format, implementations[1], (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementations[1])));
            Assert.True(CompressedArchiveAccess.RegisterFactory(format, implementations[2], (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementations[2])));

            foreach (var implementation in implementations)
            {
                using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Create, implementation) as TestCompressedArchiveAccess)
                {
                    Assert.NotNull(archive);
                    Assert.Equal(implementation, archive.Implementation);
                }
            }
        }
Example #10
0
        public void CompressedArchiveAccess_RegisterTwoImplementationsAndCreateUsingEitherOne_BothSucceed()
        {
            var format = RegisterFakeFormatForTest(registerFormat: true);
            var initialImplementation = format.GetPreferredCompressedArchiveImplementation();

            using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read))
            {
                Assert.NotNull(archive);
            }

            Assert.True(format.AddImplementation(this.GetFakeCompressedArchiveAccessImplementationForTest(), makePreferred: true));
            var newImplementation = format.GetPreferredCompressedArchiveImplementation();

            Assert.NotEqual(initialImplementation, newImplementation);
            Assert.True(CompressedArchiveAccess.RegisterFactory(format, newImplementation, (s, m) => TestCompressedArchiveAccess.Create(s, m, format, newImplementation)));
            Assert.NotNull(CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Create));
        }