public void ExtractLogo_1() { // Type 1 EngineState s = EngineTests.CreateEngineState(); string pPath = Path.Combine("%TestBench%", "EncodedFile", "ExtractFileTests.script"); pPath = StringEscaper.Preprocess(s, pPath); Plugin p = s.Project.LoadPluginMonkeyPatch(pPath); byte[] extractDigest; using (MemoryStream ms = EncodedFile.ExtractLogo(p, out ImageHelper.ImageType type)) { Assert.IsTrue(type == ImageHelper.ImageType.Jpg); extractDigest = HashHelper.CalcHash(HashType.SHA256, ms); } string originFile = Path.Combine("%TestBench%", "EncodedFile", "Logo.jpg"); originFile = StringEscaper.Preprocess(s, originFile); byte[] originDigest; using (FileStream fs = new FileStream(originFile, FileMode.Open)) { originDigest = HashHelper.CalcHash(HashType.SHA256, fs); } // Compare Hash Assert.IsTrue(originDigest.SequenceEqual(extractDigest)); }
public void ExtractLogo() { // Type 1 EngineState s = EngineTests.CreateEngineState(); string scPath = Path.Combine("%TestBench%", "EncodedFile", "ExtractFileTests.script"); scPath = StringEscaper.Preprocess(s, scPath); Script sc = s.Project.LoadScriptRuntime(scPath, new LoadScriptRuntimeOptions()); byte[] extractDigest; using (MemoryStream ms = EncodedFile.ExtractLogo(sc, out ImageHelper.ImageFormat type, out _)) { Assert.IsTrue(type == ImageHelper.ImageFormat.Jpg); extractDigest = HashHelper.GetHash(HashHelper.HashType.SHA256, ms); } string originFile = Path.Combine("%TestBench%", "EncodedFile", "Logo.jpg"); originFile = StringEscaper.Preprocess(s, originFile); byte[] originDigest; using (FileStream fs = new FileStream(originFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { originDigest = HashHelper.GetHash(HashHelper.HashType.SHA256, fs); } // Compare Hash Assert.IsTrue(originDigest.SequenceEqual(extractDigest)); }