public void CommitFromByteWithPgpSig() { var commitBytes = Encoding.UTF8.GetBytes(CommitWithPgpSig); var commit = new Commit(new ObjectHash(CommitWithPgpSigHash), commitBytes); Assert.AreEqual("413f6b2e45859c6a962d2f2e8437598c63d92e3a", commit.TreeHash.ToString()); Assert.AreEqual("d5191b5c947f79bb35960075621c273dc0bd0109", commit.Parents.Single().ToString()); Assert.AreEqual("Test User <*****@*****.**>", commit.GetAuthorName()); Assert.AreEqual("\nUpdated build instructions", commit.CommitMessage); Assert.AreEqual(commitBytes, commit.SerializeToBytes()); var newTreeHash = "1234567890123456789012345678901234567890"; var newParent1 = "3216549870321654987032165498703216549870"; var newParent2 = "9999999999999999999999999999999999999999"; var newCommitBytes = Commit.GetSerializedCommitWithChangedTreeAndParents(commit, new ObjectHash(newTreeHash), new[] { new ObjectHash(newParent1), new ObjectHash(newParent2) }.ToList()); var newCommit = new Commit(new ObjectHash("1234567890123456789012345678901234567890"), newCommitBytes); Assert.AreEqual(newTreeHash, newCommit.TreeHash.ToString()); Assert.AreEqual(2, newCommit.Parents.Count); Assert.AreEqual(newParent1, newCommit.Parents.First().ToString()); Assert.AreEqual(newParent2, newCommit.Parents.Last().ToString()); Assert.AreEqual("Test User <*****@*****.**>", newCommit.GetAuthorName()); Assert.AreEqual("\nUpdated build instructions", newCommit.CommitMessage); }
public void CommitFromByte() { var commitBytes = Encoding.UTF8.GetBytes(CommitWithoutPgpSig); var commit = new Commit(new ObjectHash(CommitHash), commitBytes); Assert.AreEqual("f7bbd02edd480914d28633f4404e2600d93af690", commit.TreeHash.ToString()); Assert.AreEqual("6f6fa334d886eb104e46452d7e2aae5b9fbcc102", commit.Parents.Single().ToString()); Assert.AreEqual("Test User <*****@*****.**>", commit.GetAuthorName()); Assert.AreEqual("\nGitignore", commit.CommitMessage); Assert.AreEqual(commitBytes, commit.SerializeToBytes()); var sameCommitBytes = Commit.GetSerializedCommitWithChangedTreeAndParents(commit, commit.TreeHash, commit.Parents); CollectionAssert.AreEqual(commitBytes, sameCommitBytes); var newTreeHash = "1234567890123456789012345678901234567890"; var newParent1 = "3216549870321654987032165498703216549870"; var newParent2 = "9999999999999999999999999999999999999999"; var newCommitBytes = Commit.GetSerializedCommitWithChangedTreeAndParents(commit, new ObjectHash(newTreeHash), new[] { new ObjectHash(newParent1), new ObjectHash(newParent2) }.ToList()); var newCommit = new Commit(new ObjectHash("1234567890123456789012345678901234567890"), newCommitBytes); Assert.AreEqual(newTreeHash, newCommit.TreeHash.ToString()); Assert.AreEqual(2, newCommit.Parents.Count); Assert.AreEqual(newParent1, newCommit.Parents.First().ToString()); Assert.AreEqual(newParent2, newCommit.Parents.Last().ToString()); Assert.AreEqual("Test User <*****@*****.**>", newCommit.GetAuthorName()); Assert.AreEqual("\nGitignore", newCommit.CommitMessage); }