public void HashString_NullContent() { var SHA1Hasher = new SHA1Hasher(new Mock<IRetryableFileOpener>(MockBehavior.Strict).Object); var ex = Assert.Throws<InvalidOperationException>(() => SHA1Hasher.GetHash((string)null)); Assert.AreEqual("Can't calculate hash for null content.", ex.Message); }
public void HashString(string content, string expectedHash) { var SHA1Hasher = new SHA1Hasher(new Mock<IRetryableFileOpener>(MockBehavior.Strict).Object); var hash = SHA1Hasher.GetHash(content); Assert.AreEqual(expectedHash, hash); }
public void HashFileInfo_FileDoesntExist() { var info = new FileInfo("fakeFile"); var SHA1Hasher = new SHA1Hasher(new RetryableFileOpener()); var ex = Assert.Throws<FileNotFoundException>(() => SHA1Hasher.GetHash(info)); //mono 3 uses " instead of ' around file name Assert.True(ex.Message.StartsWith("Could not find file")); Assert.True(ex.Message.Contains(info.FullName)); }
public void HashFileInfo(string data) { var info = new FileInfo(data); var retryableFileOpener = new Mock<IRetryableFileOpener>(MockBehavior.Strict); retryableFileOpener.Setup(rfo => rfo.OpenFileStream(info, 5, FileMode.Open, FileAccess.Read, FileShare.Read)) .Returns(new MemoryStream(Encoding.ASCII.GetBytes(data))); var SHA1Hasher = new SHA1Hasher(retryableFileOpener.Object); Assert.AreEqual(SHA1Hasher.GetHash(data), SHA1Hasher.GetHash(info)); }