Ejemplo n.º 1
0
        public void ReadAllFilesInfo()
        {
            // ReSharper disable once InconsistentNaming
            const string FolderExample = "FolderExample";

            EngineState s = EngineTests.CreateEngineState();
            string      pbOriginScript = Path.Combine("%TestBench%", "EncodedFile", "ExtractFileTests.script");
            string      originScript   = StringEscaper.Preprocess(s, pbOriginScript);

            Script sc = s.Project.LoadScriptRuntime(originScript, new LoadScriptRuntimeOptions());

            // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
            void Template(bool inspectEncodedSize, Dictionary <string, List <EncodedFileInfo> > compDict)
            {
                ReadFileInfoOptions opts = new ReadFileInfoOptions
                {
                    InspectEncodeMode = inspectEncodedSize,
                };
                ResultReport <Dictionary <string, List <EncodedFileInfo> > > report = EncodedFile.ReadAllFilesInfo(sc, opts);

                Assert.IsTrue(report.Success);
                Dictionary <string, List <EncodedFileInfo> > infoDict = report.Result;

                Assert.AreEqual(compDict.Count, infoDict.Count);
                foreach (var kv in compDict)
                {
                    Assert.IsTrue(infoDict.ContainsKey(kv.Key));
                    Assert.AreEqual(kv.Value.Count, infoDict[kv.Key].Count);
                    foreach (EncodedFileInfo fileInfo in kv.Value)
                    {
                        Assert.IsTrue(infoDict[kv.Key].Contains(fileInfo));
                    }
                }
            }

            Dictionary <string, List <EncodedFileInfo> > compDetailDict = new Dictionary <string, List <EncodedFileInfo> >
            {
                ["FolderExample"] = new List <EncodedFileInfo>
                {
                    new EncodedFileInfo
                    {
                        FolderName  = FolderExample,
                        FileName    = "Type1.jpg",
                        RawSize     = 7683,
                        EncodedSize = 10244,
                        EncodeMode  = EncodedFile.EncodeMode.ZLib
                    },
                    new EncodedFileInfo
                    {
                        FolderName  = FolderExample,
                        FileName    = "Type2.7z",
                        RawSize     = 1631,
                        EncodedSize = 2175,
                        EncodeMode  = EncodedFile.EncodeMode.Raw
                    },
                    new EncodedFileInfo
                    {
                        FolderName  = FolderExample,
                        FileName    = "Type3.pdf",
                        RawSize     = 88692,
                        EncodedSize = 102908,
                        EncodeMode  = EncodedFile.EncodeMode.XZ
                    }
                },
                ["FolderRun"] = new List <EncodedFileInfo>
                {
                    new EncodedFileInfo
                    {
                        FolderName  = "FolderRun",
                        FileName    = "TestBatch.cmd",
                        RawSize     = 34,
                        EncodedSize = 144,
                        EncodeMode  = EncodedFile.EncodeMode.Raw
                    }
                },
                ["BannerImage"] = new List <EncodedFileInfo>
                {
                    new EncodedFileInfo
                    {
                        FolderName  = "BannerImage",
                        FileName    = "Banner.bmp",
                        RawSize     = 17626,
                        EncodedSize = 23502,
                        EncodeMode  = EncodedFile.EncodeMode.ZLib
                    },
                    new EncodedFileInfo
                    {
                        FolderName  = "BannerImage",
                        FileName    = "Banner.svg",
                        RawSize     = 4715,
                        EncodedSize = 6287,
                        EncodeMode  = EncodedFile.EncodeMode.ZLib
                    },
                }
            };

            Dictionary <string, List <EncodedFileInfo> > compNoDetailDict = new Dictionary <string, List <EncodedFileInfo> >();

            foreach (var kv in compDetailDict)
            {
                compNoDetailDict[kv.Key] = new List <EncodedFileInfo>();
                foreach (EncodedFileInfo info in kv.Value)
                {
                    EncodedFileInfo clone = info.Clone() as EncodedFileInfo;
                    Assert.IsTrue(clone != null);

                    clone.EncodeMode = null;

                    compNoDetailDict[kv.Key].Add(clone);
                }
            }

            Template(true, compDetailDict);
            Template(false, compNoDetailDict);
        }