public void ExistsThrowsOnNullOrEmptyHash() { GitLooseFilesDictionary dict = new GitLooseFilesDictionary(new InMemoryFileSystem(), new NullCompressionStrategy()); Assert.Throws<ArgumentException>(() => dict.Exists(null)) .WithParamName("hash"); Assert.Throws<ArgumentException>(() => dict.Exists(String.Empty)) .WithParamName("hash"); }
public void ExistsReturnsTrueIfHashFileExists() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); fs.WriteTestFile(@"ab\cdefghijk", "Foo"); // Act/Assert Assert.True(db.Exists("abcdefghijk")); }
public void HashesLessThan3CharactersThrowWhenNeededToCreateObjects() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); fs.WriteTestFile(@"xy", "Foo"); // Act Assert.Equal( "Hash 'xy' does not exist and is not long enough to create a new entry in the database\r\nParameter name: partialHash", Assert.Throws<ArgumentException>(() => db.OpenWrite("xy", create: true)).Message); }
public void ExistsReturnsFalseIfHashFileDoesNotExist() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); // Assume Assert.False(fs.Exists(@"ab\cdefghijk")); // Act/Assert Assert.False(db.Exists("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 OpenWriteUsesCompressionStrategyToWrapStreamForCompression() { // Arrange Mock<ICompressionStrategy> mockStrategy = new Mock<ICompressionStrategy>(MockBehavior.Strict); Stream expected = new MemoryStream(); mockStrategy.Setup(s => s.WrapStreamForCompression(It.IsAny<Stream>())) .Returns(expected); InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, mockStrategy.Object); // Act using (Stream actual = db.OpenWrite("test", create: true)) { Assert.Same(expected, actual); } }
public void OpenWriteThrowsOnNullOrEmptyHash() { GitLooseFilesDictionary dict = new GitLooseFilesDictionary(new InMemoryFileSystem(), new NullCompressionStrategy()); Assert.Throws<ArgumentException>(() => dict.OpenWrite(null, create: false)) .WithParamName("hash"); Assert.Throws<ArgumentException>(() => dict.OpenWrite(String.Empty, create: false)) .WithParamName("hash"); }
public void OpenNonExistantKeyForWriteWithoutCreateThrowsKeyNotFound() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); // Act/Assert Assert.Throws<KeyNotFoundException>(() => new StreamWriter(db.OpenWrite("abcdefghijk", create: false))); }
public void OpenNonExistantKeyForWriteWithCreateCreatesNewData() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); // Assume Assert.False(fs.Exists(@"ab\cdefghijk")); // Act using (Stream strm = db.OpenWrite("abcdefghijk", create: true)) using(StreamWriter writer = new StreamWriter(strm)) { writer.Write("FooBarBaz"); } // Assert Assert.Equal("FooBarBaz", fs.ReadTestFile(@"ab\cdefghijk")); }
public void OpenExistingKeyForWriteAndEditData() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitLooseFilesDictionary db = new GitLooseFilesDictionary(fs, new NullCompressionStrategy()); fs.WriteTestFile(@"ab\cdefghijk", "Foo"); // Act using (Stream strm = db.OpenWrite("abcdefghijk", create: false)) using (StreamWriter writer = new StreamWriter(strm)) { strm.Seek(2, SeekOrigin.Begin); writer.Write("Bar"); } // Assert Assert.Equal("FoBar", fs.ReadTestFile(@"ab\cdefghijk")); }