コード例 #1
0
        public void ComputeHashForZeroBytesFile()
        {
            var file = Path.Combine(Path.Combine(testDir, "ComputeHashForZeroBytesFile"), "testfile.txt");

            IOHelper.CreateFile(file);

            Assert.That(IOHelper.ComputeMd5HashForFile(file), Is.EqualTo("D41D8CD98F00B204E9800998ECF8427E"));
        }
コード例 #2
0
        public void ComputeHashForDifferentFiles()
        {
            var file1 = Path.Combine(Path.Combine(testDir, "ComputeHashForDifferentFiles"), "testfile1.txt");
            var file2 = Path.Combine(Path.Combine(testDir, "ComputeHashForDifferentFiles"), "testfile2.txt");

            IOHelper.CreateFile(file1);
            IOHelper.CreateFile(file2);
            File.WriteAllText(file1, "Hubba");
            File.WriteAllText(file2, "Hubba-Hub");

            //differences in content means differences in hash!
            Assert.That(IOHelper.ComputeMd5HashForFile(file1), Is.Not.EqualTo(IOHelper.ComputeMd5HashForFile(file2)));
        }
コード例 #3
0
        public void ComputeHashForIdenticalFiles()
        {
            var file1 = Path.Combine(Path.Combine(testDir, "ComputeHashForIdenticalFiles"), "testfile1.txt");
            var file2 = Path.Combine(Path.Combine(testDir, "ComputeHashForIdenticalFiles"), "testfile2.txt");

            IOHelper.CreateFile(file1);
            IOHelper.CreateFile(file2);
            File.WriteAllText(file1, "Hubba");
            File.WriteAllText(file2, "Hubba");

            var commonHash = "9D745C023AB2C7CAC44557BFB9E5AC8C";

            Assert.That(IOHelper.ComputeMd5HashForFile(file1), Is.EqualTo(commonHash));
            Assert.That(IOHelper.ComputeMd5HashForFile(file2), Is.EqualTo(commonHash));
        }