Пример #1
0
        public void WhenCalculatingBundleHash_HashingBeginsAtFirstObject()
        {
            ArchiveAndCompressBundles.TaskInput input = GetDefaultInput();
            WriteResult result = AddSimpleBundle(input, "mybundle", "internalName");

            // Add a serialized. Say that the first object begins 100 bytes into the file
            var osi = new ObjectSerializedInfo();
            SerializedLocation header = new SerializedLocation();

            header.SetFileName(result.resourceFiles[0].fileAlias);
            header.SetOffset(100);
            osi.SetHeader(header);
            result.SetSerializedObjects(new ObjectSerializedInfo[] { osi });
            ResourceFile rf = result.resourceFiles[0];

            rf.SetSerializedFile(true);
            result.SetResourceFiles(new ResourceFile[] { rf });
            input.InternalFilenameToWriteResults["internalName"] = result;
            string srcFile = input.InternalFilenameToWriteResults["internalName"].resourceFiles[0].fileName;

            ArchiveAndCompressBundles.Run(input, out ArchiveAndCompressBundles.TaskOutput output);
            // Change the first 100 bytes. This is before the serialized object.
            WriteRandomData(srcFile, 100, 1);
            ArchiveAndCompressBundles.Run(input, out ArchiveAndCompressBundles.TaskOutput output2);

            // Change the first 104 bytes. This should affect the hash
            WriteRandomData(srcFile, 104, 2);
            ArchiveAndCompressBundles.Run(input, out ArchiveAndCompressBundles.TaskOutput output3);

            Assert.AreEqual(output.BundleDetails["mybundle"].Hash, output2.BundleDetails["mybundle"].Hash);
            Assert.AreNotEqual(output.BundleDetails["mybundle"].Hash, output3.BundleDetails["mybundle"].Hash);
        }