public void OpenReadThrowsOnNullOrEmptyHash() { GitLooseFilesDictionary dict = new GitLooseFilesDictionary(new InMemoryFileSystem(), new NullCompressionStrategy()); Assert.Throws <ArgumentException>(() => dict.OpenRead(null)) .WithParamName("hash"); Assert.Throws <ArgumentException>(() => dict.OpenRead(String.Empty)) .WithParamName("hash"); }
public void OpenNonExistantKeyForReadThrowsKeyNotFound() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); // Act/Assert Assert.Throws <KeyNotFoundException>(() => new StreamWriter(db.OpenRead("abcdefghijk"))); }
public void OpenExistingKeyForReadDoesNotAllowWrite() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); fs.WriteTestFile(@"ab\cdefghijk", "Foo"); // Act/Assert Assert.Equal("Stream was not writable.", Assert.Throws <ArgumentException>(() => new StreamWriter(db.OpenRead("abcdefghijk"))).Message); }
public void OpenExistingKeyForRead() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); fs.WriteTestFile(@"ab\cdefghijk", "Foo"); // Act using (StreamReader reader = new StreamReader(db.OpenRead("abcdefghijk"))) { // Assert Assert.Equal("Foo", reader.ReadToEnd()); } }
public void OpenReadUsesCompressionStrategyToWrapStreamForDecompression() { // Arrange Mock <ICompressionStrategy> mockStrategy = new Mock <ICompressionStrategy>(MockBehavior.Strict); Stream expected = new MemoryStream(); mockStrategy.Setup(s => s.WrapStreamForDecompression(It.IsAny <Stream>())) .Returns(expected); InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, mockStrategy.Object); fs.WriteTestFile(@"te\st", "Foo"); // Act using (Stream actual = db.OpenRead("test")) { Assert.Same(expected, actual); } }