public void GetInvalidObject() { using (var gitPack = new GitPack( (sha, objectType) => null, new Lazy <FileStream>(() => File.OpenRead(this.indexFile)), () => File.OpenRead(this.packFile), GitPackNullCache.Instance)) { Assert.Throws <GitException>(() => gitPack.GetObject(12, "invalid")); Assert.Throws <IOException>(() => gitPack.GetObject(-1, "commit")); Assert.Throws <GitException>(() => gitPack.GetObject(1, "commit")); Assert.Throws <GitException>(() => gitPack.GetObject(2, "commit")); Assert.Throws <GitException>(() => gitPack.GetObject(int.MaxValue, "commit")); } }
public void GetDeltafiedObject() { using (var gitPack = new GitPack( (sha, objectType) => null, new Lazy <FileStream>(() => File.OpenRead(this.indexFile)), () => File.OpenRead(this.packFile), GitPackNullCache.Instance)) using (Stream commitStream = gitPack.GetObject(317, "commit")) using (SHA1 sha = SHA1.Create()) { // This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file. var deltaStream = Assert.IsType <GitPackDeltafiedStream>(commitStream); var zlibStream = Assert.IsType <ZLibStream>(deltaStream.BaseStream); var deflateStream = Assert.IsType <DeflateStream>(zlibStream.BaseStream); if (IntPtr.Size > 4) { var pooledStream = Assert.IsType <MemoryMappedStream>(deflateStream.BaseStream); } else { var directAccessStream = Assert.IsType <FileStream>(deflateStream.BaseStream); } Assert.Equal(137, commitStream.Length); Assert.Equal("lZu/7nGb0n1UuO9SlPluFnSvj4o=", Convert.ToBase64String(sha.ComputeHash(commitStream))); } }
public void GetPackedObject() { using (var gitPack = new GitPack( (sha, objectType) => null, new Lazy <FileStream>(() => File.OpenRead(this.indexFile)), () => File.OpenRead(this.packFile), GitPackNullCache.Instance)) using (Stream commitStream = gitPack.GetObject(12, "commit")) using (SHA1 sha = SHA1.Create()) { // This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file. var zlibStream = Assert.IsType <ZLibStream>(commitStream); var deflateStream = Assert.IsType <DeflateStream>(zlibStream.BaseStream); if (IntPtr.Size > 4) { var pooledStream = Assert.IsType <MemoryMappedStream>(deflateStream.BaseStream); } else { var pooledStream = Assert.IsType <FileStream>(deflateStream.BaseStream); } Assert.Equal(222, commitStream.Length); Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream))); } }