Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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));
        }