Esempio n. 1
0
        public void BinaryData_ChecksumAlgorithm()
        {
            var s0 = "qwer";
            var s1 = "qwert";
            var s2 = "Qwert";
            var s3 = "QWERT";
            var h0 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s0));
            var h1 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s1));
            var h2 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s2));
            var h3 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s3));

            Assert.IsTrue(h0 != h1, s0 + " == " + s1);
            Assert.IsTrue(h0 != h2, s0 + " == " + s2);
            Assert.IsTrue(h0 != h3, s0 + " == " + s3);
            Assert.IsTrue(h1 != h2, s1 + " == " + s2);
            Assert.IsTrue(h1 != h3, s1 + " == " + s3);
            Assert.IsTrue(h2 != h3, s2 + " == " + s3);
        }
Esempio n. 2
0
        public void BinaryData_FileStreamChanged()
        {
            var s0  = "qwer";
            var s1  = "qwert";
            var s2  = "Qwert";
            var s3  = "QWERT";
            var ch0 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s0));
            var ch1 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s1));
            var ch2 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s2));
            var ch3 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s3));

            var file = new File(TestRoot);

            file.Binary.SetStream(Tools.GetStreamFromString(s0));
            file.Save();
            var fileId = file.Id;
            var ch01   = file.Binary.Checksum;
            var ss01   = Tools.GetStreamString(file.Binary.GetStream());

            file = Node.Load <File>(fileId);
            var ch10 = file.Binary.Checksum;
            var ss10 = Tools.GetStreamString(file.Binary.GetStream());

            file.Binary.SetStream(Tools.GetStreamFromString(s1));
            file.Save();
            var ch11 = file.Binary.Checksum;
            var ss11 = Tools.GetStreamString(file.Binary.GetStream());

            file = Node.Load <File>(fileId);
            var ch20 = file.Binary.Checksum;
            var ss20 = Tools.GetStreamString(file.Binary.GetStream());

            file.Binary.SetStream(Tools.GetStreamFromString(s2));
            file.Save();
            var ch21 = file.Binary.Checksum;
            var ss21 = Tools.GetStreamString(file.Binary.GetStream());

            file = Node.Load <File>(fileId);
            var ch30 = file.Binary.Checksum;
            var ss30 = Tools.GetStreamString(file.Binary.GetStream());

            file.Binary.SetStream(Tools.GetStreamFromString(s3));
            file.Save();
            var ch31 = file.Binary.Checksum;
            var ss31 = Tools.GetStreamString(file.Binary.GetStream());

            Assert.IsTrue(ss01 == s0, "#1");
            Assert.IsTrue(ss10 == s0, "#2");
            Assert.IsTrue(ss11 == s1, "#3");
            Assert.IsTrue(ss20 == s1, "#4");
            Assert.IsTrue(ss21 == s2, "#5");
            Assert.IsTrue(ss30 == s2, "#6");
            Assert.IsTrue(ss31 == s3, "#7");

            Assert.IsTrue(ch01 == ch0, "#11");
            Assert.IsTrue(ch10 == ch0, "#12");
            Assert.IsTrue(ch11 == ch1, "#13");
            Assert.IsTrue(ch20 == ch1, "#14");
            Assert.IsTrue(ch21 == ch2, "#15");
            Assert.IsTrue(ch30 == ch2, "#16");
            Assert.IsTrue(ch31 == ch3, "#17");
        }