コード例 #1
0
        public void GetMD5Hash_CheckForMOdifications()
        {
            FileInfo tempFile001 = new FileInfo(Path.Combine(Path.GetTempPath(), "001.sql"));
            StreamWriter sw = new StreamWriter(tempFile001.OpenWrite());
            sw.WriteLine("test test 111");
            sw.Close();

            FileInfo tempFile002 = new FileInfo(Path.Combine(Path.GetTempPath(), "002.sql"));
            StreamWriter sw2 = new StreamWriter(tempFile002.OpenWrite());
            sw2.WriteLine("test test 222");
            sw2.Close();

            DeltaHashProvider hashProvider = new DeltaHashProvider(DeltaRunnerFactory.CreateDeltaRunner(null, null));
            hashProvider.AddDeltaHash(tempFile001.Name, DeltaHashProvider.GetMD5Hash(tempFile001));
            hashProvider.AddDeltaHash(tempFile002.Name, DeltaHashProvider.GetMD5Hash(tempFile002));

            Assert.AreEqual(null, hashProvider.CheckForModifications(new FileInfo[]{tempFile001, tempFile002}));
        }
コード例 #2
0
        public void GetMD5Hash_CheckForMOdifications_WithModificationsToRandomFile()
        {
            DeltaHashProvider hashProvider = new DeltaHashProvider(DeltaRunnerFactory.CreateDeltaRunner(null, null));

            FileInfo[] files = new FileInfo[100];

            Console.Out.WriteLine("Creating [{0}] Temp Deltas", files.Length);

            for (int i = 0; i < files.Length; i++)
            {
                FileInfo tempFile = new FileInfo(Path.Combine(Path.GetTempPath(), string.Format("00{0}.sql", i)));
                using(StreamWriter sw = new StreamWriter(tempFile.OpenWrite()))
                {
                    sw.WriteLine("test test {0}", i);
                    sw.Close();
                    hashProvider.AddDeltaHash(tempFile.Name, DeltaHashProvider.GetMD5Hash(tempFile));
                    files[i] = tempFile;
                }
            }

            Random r = new Random(DateTime.Now.Millisecond);
            int randomFileIndex = r.Next(1,files.Length-1);
            FileInfo randomTempFile = files[randomFileIndex];

            Console.Out.WriteLine("Random Temp File = {0} : {1}", randomFileIndex, randomTempFile.FullName);

            using(StreamWriter sw2 = new StreamWriter(randomTempFile.Open(FileMode.OpenOrCreate, FileAccess.Write)))
            {
                Console.Out.WriteLine("Modifying Delta");
                sw2.WriteLine("changes to this delta!!");
                sw2.Close();
            }

            Assert.AreEqual(randomTempFile, hashProvider.CheckForModifications(files));
        }
コード例 #3
0
        public void GetMD5Hash_CheckForMOdifications_WithModificationsToSecondFile()
        {
            FileInfo tempFile001 = new FileInfo(Path.Combine(Path.GetTempPath(), "001.sql"));
            using(StreamWriter sw = new StreamWriter(tempFile001.OpenWrite()))
            {
                sw.WriteLine("test test 111");
                sw.Close();
            }

            FileInfo tempFile002 = new FileInfo(Path.Combine(Path.GetTempPath(), "002.sql"));
            using(StreamWriter sw2 = new StreamWriter(tempFile002.OpenWrite()))
            {
                sw2.WriteLine("test test 222");
                sw2.Close();
            }

            DeltaHashProvider hashProvider = new DeltaHashProvider(DeltaRunnerFactory.CreateDeltaRunner(null, null));
            hashProvider.AddDeltaHash(tempFile001.Name, DeltaHashProvider.GetMD5Hash(tempFile001));
            hashProvider.AddDeltaHash(tempFile002.Name, DeltaHashProvider.GetMD5Hash(tempFile002));

            using(StreamWriter sw3 = new StreamWriter(tempFile002.Open(FileMode.OpenOrCreate, FileAccess.Write)))
            {
                sw3.WriteLine("test test changes to 222");
                sw3.Close();
            }

            Assert.AreEqual(tempFile002, hashProvider.CheckForModifications(new FileInfo[]{tempFile001, tempFile002}));
        }
コード例 #4
0
        public void GetMD5Hash_CheckForModifications_TimeTracker()
        {
            FileInfo[] files = new FileInfo[3];

            DeltaHashProvider hashProvider = new DeltaHashProvider(DeltaRunnerFactory.CreateDeltaRunner(null, null));

            int i = 0;
            foreach (FileInfo file in new DirectoryInfo("../../TestFiles/FullTest3_TimeTracker/").GetFiles())
            {
                files[i++] = file;
                string hashCode = DeltaHashProvider.GetMD5Hash(file);
                Console.Out.WriteLine("hashCode = {0}", hashCode);
                hashProvider.AddDeltaHash(file.Name, hashCode);
            }

            Assert.AreEqual(null, hashProvider.CheckForModifications(files));
        }