Esempio n. 1
0
        public void CheckMonthlySettingsCloneMethod()
        {
            MonthlySettings monset = MonthlySettings.Random(2000, 1, MachineType.M3);
            var             check  = monset.Clone() as MonthlySettings;

            Assert.IsTrue(check != null && check == monset);
        }
Esempio n. 2
0
        public void TestNavyMessagingM3()
        {
            string fileName        = IoUtil.MonthFileName(DateTime.Now.Year, DateTime.Now.Month, ".xml");
            string digraphFileName = IoUtil.DigraphFileName(DateTime.Now.Year, DateTime.Now.Month);

            string folder = Path.GetTempPath();

            string xmlFullPath     = Path.Combine(folder, fileName);
            string digraphFullPath = Path.Combine(folder, digraphFileName);

            MonthlySettings monSet = MonthlySettings.Random(DateTime.Now.Year, DateTime.Now.Month, MachineType.M3K);

            monSet.Save(xmlFullPath);
            IoUtil.SaveDigraphTable(DateTime.Now.Year, DateTime.Now.Month, folder);

            NavyMessage msg = new NavyMessage(xmlFullPath, digraphFullPath, LONG_TEST_PLAIN_TEXT, DateTime.Now.Day, "XYZ");

            string messageText = msg.ToString();

            string decrypted  = NavyMessage.Decrypt(xmlFullPath, digraphFullPath, messageText);
            string cleanPlain = Utility.GetPaddedString(Utility.CleanString(LONG_TEST_PLAIN_TEXT), 4);

            Assert.AreEqual(decrypted, cleanPlain);

            File.Delete(xmlFullPath);
            File.Delete(digraphFullPath);
        }
Esempio n. 3
0
        public void MonthlySettingsHaveCorrectNumberOfDays()
        {
            int             days = DateTime.DaysInMonth(2015, 12);
            MonthlySettings ms   = MonthlySettings.Random(2015, 12, MachineType.M4K, ReflectorType.B_Dunn);

            Assert.AreEqual(ms.DailySettings.Count, days);
        }
Esempio n. 4
0
        public static void SaveYear(string folder, string title, int year, MachineType t)
        {
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            for (int m = 1; m <= 12; m++)
            {
                string monthFolderName = MonthFolderName(year, m);
                string monthFolderPath = Path.Combine(folder, monthFolderName);

                if (!Directory.Exists(monthFolderPath))
                {
                    Directory.CreateDirectory(monthFolderPath);
                }

                MonthlySettings s = MonthlySettings.Random(year, m, t);
                string          serializedFileName = MonthFileName(year, m, ".xml");

                string serializedPath = Path.Combine(monthFolderPath, serializedFileName);
                s.Save(serializedPath);

                string textFileName = MonthFileName(year, m, ".txt");
                string textFilePath = Path.Combine(monthFolderPath, textFileName);
                SaveFile(textFilePath, Formatting.MonthlySettings(title, year, m, t, s.DailySettings));

                SaveDigraphTable(year, m, monthFolderPath);
            }

            SaveKeySheet(year, folder);
        }
Esempio n. 5
0
        public void CheckMonthlySettingParsingAndEquality()
        {
            MonthlySettings monSet = MonthlySettings.Random(2000, 1, MachineType.M3);
            MonthlySettings check  = MonthlySettings.Parse(monSet.ToString());

            Assert.IsTrue(monSet == check);

            monSet = MonthlySettings.Random(2000, 1, MachineType.M3K);
            check  = MonthlySettings.Parse(monSet.ToString());
            Assert.IsTrue(monSet == check);

            monSet = MonthlySettings.Random(2000, 1, MachineType.M4K);
            check  = MonthlySettings.Parse(monSet.ToString());
            Assert.IsTrue(monSet == check);
        }
Esempio n. 6
0
        public void WhenSavingSettingsTheSchemaFileIsAlsoSaved()
        {
            string folderName = Path.GetTempPath();
            string fileName   = Path.GetTempFileName();

            MonthlySettings ms = MonthlySettings.Random(2015, 12, MachineType.M4K, ReflectorType.B_Dunn, false);

            string filePath = Path.Combine(folderName, fileName);

            ms.Save(filePath);

            Assert.AreEqual(true, File.Exists(Path.Combine(folderName, "Settings.xsd")));

            File.Delete(filePath);
            File.Delete(Path.Combine(folderName, "Settings.xsd"));
        }
Esempio n. 7
0
        public static void SaveYearlyFiles(string name, string classification, int year, string folder)
        {
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            for (int m = 1; m <= 12; m++)
            {
                DateTime        dt              = new DateTime(year, m, 1);
                string          folderName      = string.Format("{0} {1:MMM yyyy}", name, dt);
                string          monthFolderName = Path.Combine(folder, folderName);
                MonthlySettings monSet          = MonthlySettings.Random(name, classification, dt);
                SaveMonthlyFiles(monSet, monthFolderName);
            }
        }
Esempio n. 8
0
        public void MonthlySettingsSerializationAndSave()
        {
            string folderName = Path.GetTempPath();
            string fileName   = Path.GetTempFileName();

            MonthlySettings ms = MonthlySettings.Random(2015, 12, MachineType.M4K, ReflectorType.B_Dunn, false);

            string filePath = Path.Combine(folderName, fileName);

            ms.Save(filePath);
            string foo = ms.ToString();

            ms = MonthlySettings.Open(filePath);
            Assert.AreEqual(ms.ToString(), foo);

            File.Delete(filePath);
        }
Esempio n. 9
0
        public void MonthlySettingsSaveValidXmlWhenSerializing()
        {
            string folderName = Path.GetTempPath();
            string fileName   = Path.GetTempFileName();

            MonthlySettings ms = MonthlySettings.Random(2015, 12, MachineType.M4K, ReflectorType.B_Dunn, false);

            string filePath = Path.Combine(folderName, fileName);

            ms.Save(filePath);

            XmlDocument doc = new XmlDocument();

            doc.Load(filePath);

            doc.Schemas.Add("", Path.Combine(folderName, "Settings.xsd"));
            doc.Validate(XmlValidationHandler);

            Assert.AreEqual(xmlValidationCount, 0);

            File.Delete(filePath);
            File.Delete(Path.Combine(folderName, "Settings.xsd"));
        }
Esempio n. 10
0
        public static void SaveMonth(string folder, string title, int year, int month, MachineType t)
        {
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            MonthlySettings s = MonthlySettings.Random(year, month, t);

            string fileName = MonthFileName(year, month, TEXT_FILE_EXTENSION);
            string filePath = Path.Combine(folder, fileName);

            SaveFile(filePath, Formatting.MonthlySettings(title, year, month, t, s.DailySettings));

            fileName = MonthFileName(year, month, XML_FILE_EXTENSION);
            filePath = Path.Combine(folder, fileName);
            s.Save(filePath);

            if (t != MachineType.M3)
            {
                SaveDigraphTable(year, month, folder);
            }
        }
Esempio n. 11
0
        public void MonthlyRotorSettingsInCompatibilityMode()
        {
            MonthlySettings ms = MonthlySettings.Random(2015, 12, MachineType.M4K, ReflectorType.B_Dunn, true);

            Assert.AreEqual(true, ms.DailySettings.All(s => s.Rotors[0].Name == RotorName.Beta && s.Rotors[0].RingSetting == 0));
        }