AA2Install.Tests.MainTests.forceModTest C# (CSharp) Метод

forceModTest() приватный Метод

private forceModTest ( ) : void
Результат void
        public void forceModTest()
        {
            Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp"), Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp did not deploy");

            form.refreshModList();

            CopyFilesRecursively(new DirectoryInfo(Environment.CurrentDirectory + @"\testdir\"), new DirectoryInfo(Environment.CurrentDirectory + @"\testdir2\"));

            var subfiles = new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles;
            Dictionary<string, uint> CRCValues = new Dictionary<string, uint>();

            foreach (IWriteFile kv in subfiles)
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    kv.WriteTo(mem);
                    byte[] buffer = new byte[mem.Length];
                    mem.Position = 0;
                    mem.Read(buffer, 0, (int)mem.Length);

                    var value = DamienG.Security.Cryptography.Crc32.Compute(buffer);
                    CRCValues.Add(kv.Name, value);
                }
            }

            foreach (ListViewItem lv in form.lsvMods.Items)
                lv.Checked = true;

            Assert.IsTrue(form.inject(true, true, true), "Installation injection failed. Log: {0}", form.labelStatus.Text);

            Directory.Delete(Environment.CurrentDirectory + @"\testdir\", true);
            CopyFilesRecursively(new DirectoryInfo(Environment.CurrentDirectory + @"\testdir2\"), new DirectoryInfo(Environment.CurrentDirectory + @"\testdir\"));
            Directory.Delete(Environment.CurrentDirectory + @"\testdir2\", true);

            foreach (ListViewItem lsv in form.lsvMods.Items)
                lsv.Selected = true;

            form.forceSelectedMods(true);

            foreach (Mod m in form.modDict.Values)
            {
                Assert.IsTrue(m.Installed, "Backup archive for {0} was not created.", m.Name);
            }

            Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2e04_00_TEST.pp"), "jg2e04_00_TEST.pp was not created.");
            Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p01_00_TEST.pp"), "jg2p01_00_TEST.pp was not created.");

            Dictionary<string, uint> diff = new Dictionary<string, uint>();

            foreach (IWriteFile kv in new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles)
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    kv.WriteTo(mem);
                    byte[] buffer = new byte[mem.Length];
                    mem.Position = 0;
                    mem.Read(buffer, 0, (int)mem.Length);

                    var value = DamienG.Security.Cryptography.Crc32.Compute(buffer);
                    if (CRCValues[kv.Name] != value)
                        diff.Add(kv.Name, value);
                }
            }

            Dictionary<string, uint> TrueCRC = new Dictionary<string, uint>()
            {
                { "jg2_01_05_00.lst", 838774076 },
                { "jg2_01_05_01.lst", 1767953068 },
                { "jg2_01_05_02.lst", 1609570759 },
                { "jg2_01_05_03.lst", 4121681499 },
                { "jg2_01_06_05.lst", 32814373 },
                { "jg2_01_06_06.lst", 2454317916 },
                { "jg2_01_06_08.lst", 3999174270 }
            };

            //Assert.IsFalse(subfiles.Count == new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles.Count, "Subfiles have not changed.");
            Assert.IsTrue(diff.Count == TrueCRC.Count, "Amount of changes in jg2p00_00_00.pp was incorrect. Expected value: {0}; Actual value: {1}", TrueCRC.Count, diff.Count);

            foreach (KeyValuePair<string, uint> kv in TrueCRC)
                Assert.IsTrue(kv.Value == diff[kv.Key], "CRC check failed after installation. Key: {0}; Expected value: {1}; Actual value: {2}", kv.Key, kv.Value, diff[kv.Key]);

            foreach (ListViewItem lv in form.lsvMods.Items)
                lv.Checked = false;

            Assert.IsTrue(form.inject(false, false, true), "Uninstallation injection failed. Log: {0}", form.labelStatus.Text);

            Assert.IsTrue(!File.Exists(Environment.CurrentDirectory + @"\testdir\jg2e04_00_TEST.pp"), "jg2e04_00_TEST.pp was not deleted.");
            Assert.IsTrue(!File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p01_00_TEST.pp"), "jg2p01_00_TEST.pp was not deleted.");

            foreach (Mod m in form.modDict.Values)
            {
                Assert.IsTrue(!m.Installed, "Backup archive for {0} was not deleted.", m.Name);
            }

            Assert.IsTrue(subfiles.Count == new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles.Count, "Amount of restored changes in jg2p00_00_00.pp was incorrect. Expected value: {0}; Actual value: {1}", subfiles.Count, new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles.Count);

            foreach (IWriteFile kv in new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles)
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    kv.WriteTo(mem);
                    var value = DamienG.Security.Cryptography.Crc32.Compute(mem.ToArray());
                    Assert.IsTrue(CRCValues[kv.Name] == value, "CRC check failed after uninstallation. Key: {0}; Expected value: {1}; Actual value: {2}", kv.Name, CRCValues[kv.Name], value);
                }
            };

            Configuration.saveMods(form.modDict);
        }