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 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 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 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 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 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 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 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 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); } }
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 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); } }
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 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 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); }