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); } } }
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))); }
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))); }
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); }
public void CompressedArchiveAccess_RegisterFactory_Succeeds() { var format = this.GetFakeCompressedArchiveFormatForTest(); var implementation = this.GetFakeCompressedArchiveAccessImplementationForTest(); var succeeded = CompressedArchiveAccess.RegisterFactory(format, implementation, (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementation)); Assert.True(succeeded); }
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)); }