Ejemplo n.º 1
0
        public void HashCombiner_Test_File()
        {
            using (var combiner1 = new HashGenerator())
                using (var combiner2 = new HashGenerator())
                    using (var combiner3 = new HashGenerator())
                    {
                        var dir       = PrepareFolder();
                        var file1Path = Path.Combine(dir.FullName, "hastest1.txt");
                        File.Delete(file1Path);
                        using (var file1 = File.CreateText(Path.Combine(dir.FullName, "hastest1.txt")))
                        {
                            file1.WriteLine("hello");
                        }
                        var file2Path = Path.Combine(dir.FullName, "hastest2.txt");
                        File.Delete(file2Path);
                        using (var file2 = File.CreateText(Path.Combine(dir.FullName, "hastest2.txt")))
                        {
                            //even though files are the same, the dates are different
                            file2.WriteLine("hello");
                        }

                        combiner1.AddFile(new FileInfo(file1Path));

                        combiner2.AddFile(new FileInfo(file1Path));

                        combiner3.AddFile(new FileInfo(file2Path));

                        Assert.AreEqual(combiner1.GenerateHash(), combiner2.GenerateHash());
                        Assert.AreNotEqual(combiner1.GenerateHash(), combiner3.GenerateHash());

                        combiner2.AddFile(new FileInfo(file2Path));

                        Assert.AreNotEqual(combiner1.GenerateHash(), combiner2.GenerateHash());
                    }
        }