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 ResolveReferenceSingleIndirection(string name, string actualFile) { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitReferenceDirectory refs = new GitReferenceDirectory(fs); fs.WriteTestFile(actualFile, "abcdefghij"); // Act/Assert Assert.Equal("abcdefghij", refs.ResolveReference(name)); }
public void ResolveReferenceWithHash() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitReferenceDirectory refs = new GitReferenceDirectory(fs); // Assume Assert.False(fs.Exists("abcdefghij")); // Act/Assert Assert.Equal("abcdefghij", refs.ResolveReference("abcdefghij")); }
public void ResolveReferenceDoubleIndirection(string name, string actualFile) { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); GitReferenceDirectory refs = new GitReferenceDirectory(fs); fs.WriteTestFile(actualFile, "ref: refs/remotes/origin/master"); fs.WriteTestFile(@"refs\remotes\origin\master", "abcdefghij"); // Act/Assert Assert.Equal("abcdefghij", refs.ResolveReference(name)); }
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 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")); }
public void UsesCorrectPackFile() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); fs.WriteTestFile("pack-test.idx", w => { w.Write(GitPackIndex.V2PlusSignature); w.Write(IPAddress.HostToNetworkOrder(2)); }); // Act GitPackFile file = GitPackFile.Open(fs, "pack-test"); // Assert Assert.Equal("pack-test.pack", file.PackFileName); Assert.Same(fs, file.FileSystem); }
public void SetsUpDefaultCompressionAndDelta() { // Arrange InMemoryFileSystem fs = new InMemoryFileSystem(); fs.WriteTestFile("pack-test.idx", w => { w.Write(GitPackIndex.V2PlusSignature); w.Write(IPAddress.HostToNetworkOrder(2)); }); // Act GitPackFile file = GitPackFile.Open(fs, "pack-test"); // Assert Assert.IsType<ZlibCompressionStrategy>(file.Compression); Assert.IsType<GitDeltaDecoder>(file.Delta); Assert.IsType<GitPackIndexV2>(file.Index); }