コード例 #1
0
        public void TestCleanup()
        {
            DependencyInjection(DefaultAppSettingValues);

            QueueOperation.GetMessages(settings.MailQueueName, settings.MailQueueConnectionString);

            using (SqlConnection connection = new SqlConnection(settings.PrimaryDbConnectionString))
            {
                try
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(ClearTableCommand, connection))
                    {
                        command.ExecuteNonQuery();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }

            foreach (CloudBlockBlob blockBlob in failureBlob.Client.GetBlockBlobs(DefaultAppSettingValues["FailureBlobContainerName"]))
            {
                blockBlob.DeleteIfExistsAsync().Wait();
            }
        }
コード例 #2
0
        public void MonitorParentChildConnectTableTest(string no, string in_InitializeSqlSet, string expected_AlarmQueueSet, string expected_LogMessages, string remarks)
        {
            List <TestLog> actual_logs = new List <TestLog>();

            // DI
            DependencyInjection(DefaultAppSettingValues, actual_logs);

            // テストデータ準備
            {
                if (Directory.Exists(in_InitializeSqlSet))
                {
                    using (SqlConnection connection = new SqlConnection(settings.PrimaryDbConnectionString))
                    {
                        try
                        {
                            connection.Open();
                            foreach (string path in Directory.GetFiles(in_InitializeSqlSet, "*.sql", SearchOption.AllDirectories))
                            {
                                string cmdText = File.ReadAllText(path);
                                using (SqlCommand command = new SqlCommand(cmdText, connection))
                                {
                                    command.ExecuteNonQuery();
                                }
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }
            }

            // 期待値
            List <string> expected_queues       = Directory.Exists(expected_AlarmQueueSet) ? Directory.GetFiles(expected_AlarmQueueSet, "*.json").Select(x => File.ReadAllText(x)).ToList() : new List <string>();
            List <string> expected_log_messages = (expected_LogMessages != null && File.Exists(expected_LogMessages)) ? File.ReadLines(expected_LogMessages).ToList() : new List <string>();

            // テスト実行
            target.MonitorParentChildConnectTable(null, new TestLogger <ParentChildrenConnectionMonitorController>(actual_logs));

            // テスト結果
            List <string> actual_queses       = QueueOperation.GetMessages(settings.AlarmQueueName, settings.QueueStorageConnectionString);
            List <string> actual_log_messages = actual_logs.Select(x => x.GetSimpleText()).ToList();

            // 確認
            CollectionAssert.AreEqual(expected_queues, actual_queses);
            foreach (var expected_log_message in expected_log_messages)
            {
                var matching_element = actual_log_messages.FirstOrDefault(actual => actual.Contains(expected_log_message));
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(matching_element, string.Format("「{0}」に一致する要素が見つかりません", expected_log_message));
                if (matching_element != null)
                {
                    actual_log_messages.Remove(matching_element);
                }
            }
        }
コード例 #3
0
        public void ReceiveDirectoryUsageTest(string no, string in_InitializeSqlSet, string in_Message, string expected_AlarmQueueSet, string expected_FailureBlobFileSet, string expected_LogMessages, string remarks)
        {
            List <TestLog> actual_logs = new List <TestLog>();

            // DI
            DependencyInjection(DefaultAppSettingValues, actual_logs);

            // テストデータ準備
            {
                if (Directory.Exists(in_InitializeSqlSet))
                {
                    using (SqlConnection connection = new SqlConnection(settings.PrimaryDbConnectionString))
                    {
                        try
                        {
                            connection.Open();
                            foreach (string path in Directory.GetFiles(in_InitializeSqlSet, "*.sql", SearchOption.AllDirectories))
                            {
                                string cmdText = File.ReadAllText(path);
                                using (SqlCommand command = new SqlCommand(cmdText, connection))
                                {
                                    command.ExecuteNonQuery();
                                }
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }

                in_Message = (in_Message != null && File.Exists(in_Message)) ? File.ReadAllText(in_Message) : in_Message;
            }

            // 期待値
            List <string> expected_queues    = Directory.Exists(expected_AlarmQueueSet) ? Directory.GetFiles(expected_AlarmQueueSet, "*.json").Select(x => File.ReadAllText(x)).ToList() : new List <string>();
            DirectoryInfo expectedFailureDir = new DirectoryInfo(expected_FailureBlobFileSet);

            string[]      expectedFailureFiles      = expectedFailureDir.Exists ? expectedFailureDir.GetFiles("*", SearchOption.AllDirectories).Select(x => x.FullName).OrderBy(x => x).ToArray() : new string[] { };
            string[]      expected_failure_names    = expectedFailureFiles.Select(x => x.Replace(expectedFailureDir.FullName, string.Empty)).ToArray();
            string[]      expected_failure_contents = expectedFailureFiles.Select(x => File.ReadAllText(x)).ToArray();
            List <string> expected_log_messages     = (expected_LogMessages != null && File.Exists(expected_LogMessages)) ? File.ReadLines(expected_LogMessages).ToList() : new List <string>();

            // テスト実行
            target.ReceiveDirectoryUsage(in_Message, new TestLogger <DirectoryUsageMonitorController>(actual_logs));

            // テスト結果
            List <string> actual_queses = QueueOperation.GetMessages(settings.AlarmQueueName, settings.QueueStorageConnectionString);
            DirectoryInfo actualDir     = new DirectoryInfo(Path.Combine(TestResultRootDir, no));

            string[]      actualFailureFiles      = failureBlob.Client.GetFiles(settings.FailureBlobContainerName, actualDir).OrderBy(x => x).ToArray();
            string[]      actual_failure_names    = actualFailureFiles.Select(x => x.Replace(actualDir.FullName, string.Empty)).ToArray();
            string[]      actual_failure_contents = actualFailureFiles.Select(x => File.ReadAllText(x)).ToArray();
            List <string> actual_log_messages     = actual_logs.Select(x => x.GetSimpleText()).ToList();

            // 確認
            CollectionAssert.AreEqual(expected_queues, actual_queses);
            CollectionAssert.AreEqual(expected_failure_names, actual_failure_names);
            CollectionAssert.AreEqual(expected_failure_contents, actual_failure_contents);
            foreach (var expected_log_message in expected_log_messages)
            {
                var matching_element = actual_log_messages.FirstOrDefault(actual => actual.Contains(expected_log_message));
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(matching_element, string.Format("「{0}」に一致する要素が見つかりません", expected_log_message));
                if (matching_element != null)
                {
                    actual_log_messages.Remove(matching_element);
                }
            }
        }
コード例 #4
0
        public void MonitorAlmilogAnalysisResultTableTest(string no, string in_InitializeSqlSet, string expected_AlarmQueueSet, string expected_TableData, string expected_LogMessages, string remarks)
        {
            List <TestLog> actual_logs = new List <TestLog>();

            // DI
            DependencyInjection(DefaultAppSettingValues, actual_logs);

            // テストデータ準備
            {
                if (Directory.Exists(in_InitializeSqlSet))
                {
                    using (SqlConnection connection = new SqlConnection(settings.PrimaryDbConnectionString))
                    {
                        try
                        {
                            connection.Open();
                            foreach (string path in Directory.GetFiles(in_InitializeSqlSet, "*.sql", SearchOption.AllDirectories))
                            {
                                string cmdText = File.ReadAllText(path);
                                using (SqlCommand command = new SqlCommand(cmdText, connection))
                                {
                                    command.ExecuteNonQuery();
                                }
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }
            }

            // テスト実行後、テーブルを評価するかどうか
            bool isCheckTable = !string.IsNullOrEmpty(expected_TableData) && File.Exists(expected_TableData);

            // 評価対象テーブル名
            string targetTableName = isCheckTable ? Path.GetFileNameWithoutExtension(expected_TableData) : null;

            // 期待値
            DataTable     expected_table        = isCheckTable ? DataTableHelper.SelectCsv(settings.PrimaryDbConnectionString, expected_TableData, targetTableName) : null;
            List <string> expected_queues       = Directory.Exists(expected_AlarmQueueSet) ? Directory.GetFiles(expected_AlarmQueueSet, "*.json").Select(x => File.ReadAllText(x)).ToList() : new List <string>();
            List <string> expected_log_messages = (expected_LogMessages != null && File.Exists(expected_LogMessages)) ? File.ReadLines(expected_LogMessages).ToList() : new List <string>();

            // テスト実行
            target.MonitorAlmilogAnalysisResultTable(null, new TestLogger <DipAlmiLogPremonitorController>(actual_logs));

            // テスト結果
            DataTable     actual_table        = isCheckTable ? DataTableHelper.SelectTable(settings.PrimaryDbConnectionString, "SELECT * FROM " + targetTableName) : null;
            List <string> actual_queses       = QueueOperation.GetMessages(settings.AlarmQueueName, settings.QueueStorageConnectionString);
            List <string> actual_log_messages = actual_logs.Select(x => x.GetSimpleText()).ToList();

            // 確認
            CollectionAssert.AreEqual(expected_queues, actual_queses);
            if (isCheckTable)
            {
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(expected_table.Rows.Count, actual_table.Rows.Count);
                for (int i = 0; i < expected_table.Rows.Count; i++)
                {
                    CollectionAssert.AreEqual(expected_table.Rows[i].ItemArray, actual_table.Rows[i].ItemArray);
                }
            }

            foreach (var expected_log_message in expected_log_messages)
            {
                var matching_element = actual_log_messages.FirstOrDefault(actual => actual.Contains(expected_log_message));
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(matching_element, string.Format("「{0}」に一致する要素が見つかりません", expected_log_message));
                if (matching_element != null)
                {
                    actual_log_messages.Remove(matching_element);
                }
            }
        }
コード例 #5
0
        public void DequeueAlarmInfoTest(string no, string in_InitializeSqlSet, string in_QueueItem, string expected_MailQueueSet, string expected_TableData, string expected_FailureBlobFileSet, string expected_LogMessages, string remarks)
        {
            List <TestLog> actual_logs = new List <TestLog>();

            // DI
            DependencyInjection(DefaultAppSettingValues, actual_logs);

            // テストデータ準備
            {
                if (Directory.Exists(in_InitializeSqlSet))
                {
                    // 設置ベースデータテーブル、機器データテーブルを先に設定する
                    PresetDb();

                    using (SqlConnection connection = new SqlConnection(settings.PrimaryDbConnectionString))
                    {
                        try
                        {
                            connection.Open();
                            foreach (string path in Directory.GetFiles(in_InitializeSqlSet, "*.sql", SearchOption.AllDirectories))
                            {
                                string cmdText = File.ReadAllText(path);
                                using (SqlCommand command = new SqlCommand(cmdText, connection))
                                {
                                    command.ExecuteNonQuery();
                                }
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }

                in_QueueItem = (in_QueueItem != null && File.Exists(in_QueueItem)) ? File.ReadAllText(in_QueueItem) : in_QueueItem;
            }

            // テスト実行後、テーブルを評価するかどうか
            bool isCheckTable = !string.IsNullOrEmpty(expected_TableData) && File.Exists(expected_TableData);

            // 評価対象テーブル名
            string targetTableName = isCheckTable ? Path.GetFileNameWithoutExtension(expected_TableData) : null;

            // 期待値
            List <string> expected_queues    = Directory.Exists(expected_MailQueueSet) ? Directory.GetFiles(expected_MailQueueSet, "*.json").Select(x => File.ReadAllText(x)).ToList() : new List <string>();
            DataTable     expected_table     = isCheckTable ? DataTableHelper.SelectCsv(settings.PrimaryDbConnectionString, expected_TableData, targetTableName) : null;
            DirectoryInfo expectedFailureDir = new DirectoryInfo(expected_FailureBlobFileSet);

            string[]      expectedFailureFiles      = expectedFailureDir.Exists ? expectedFailureDir.GetFiles("*", SearchOption.AllDirectories).Select(x => x.FullName).OrderBy(x => x).ToArray() : new string[] { };
            string[]      expected_failure_names    = expectedFailureFiles.Select(x => x.Replace(expectedFailureDir.FullName, string.Empty)).ToArray();
            string[]      expected_failure_contents = expectedFailureFiles.Select(x => File.ReadAllText(x)).ToArray();
            List <string> expected_log_messages     = (expected_LogMessages != null && File.Exists(expected_LogMessages)) ? File.ReadLines(expected_LogMessages).ToList() : new List <string>();

            // テスト実行
            target.DequeueAlarmInfo(in_QueueItem, new TestLogger <AlarmRegisterController>(actual_logs));

            // テスト結果
            List <string> actual_queses = QueueOperation.GetMessages(settings.MailQueueName, settings.MailQueueConnectionString);
            DataTable     actual_table  = isCheckTable ? DataTableHelper.SelectTable(settings.PrimaryDbConnectionString, "SELECT * FROM " + targetTableName) : null;
            DirectoryInfo actualDir     = new DirectoryInfo(Path.Combine(TestResultRootDir, no));

            string[]      actualFailureFiles      = failureBlob.Client.GetFiles(settings.FailureBlobContainerName, actualDir).OrderBy(x => x).ToArray();
            string[]      actual_failure_names    = actualFailureFiles.Select(x => x.Replace(actualDir.FullName, string.Empty)).ToArray();
            string[]      actual_failure_contents = actualFailureFiles.Select(x => File.ReadAllText(x)).ToArray();
            List <string> actual_log_messages     = actual_logs.Select(x => x.GetSimpleText()).ToList();

            // 確認(メールキュー)
            CollectionAssert.AreEqual(expected_queues, actual_queses);

            // 確認(DT_ALARM)
            if (isCheckTable)
            {
                // 評価対象外のカラムを除外
                Array.ForEach(IgnoreColumns, x => expected_table.Columns.Remove(x));
                Array.ForEach(IgnoreColumns, x => actual_table.Columns.Remove(x));

                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(expected_table.Rows.Count, actual_table.Rows.Count);

                // 日付は期待値読み込み時に日本時刻で取得されてしまうため別に比較する
                foreach (var columnName in DateTimeColumns)
                {
                    var exptected_datetime_table = expected_table.DefaultView.ToTable(false, columnName);
                    var actual_datetime_table    = actual_table.DefaultView.ToTable(false, columnName);

                    for (int i = 0; i < exptected_datetime_table.Rows.Count; i++)
                    {
                        var expected_datetime = ((DateTime)exptected_datetime_table.Rows[i].ItemArray[0]).ToUniversalTime();
                        var actual_datetime   = (DateTime)actual_datetime_table.Rows[i].ItemArray[0];

                        Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(expected_datetime, actual_datetime);
                    }

                    // 評価したカラムを除外
                    expected_table.Columns.Remove(columnName);
                    actual_table.Columns.Remove(columnName);
                }

                for (int i = 0; i < expected_table.Rows.Count; i++)
                {
                    CollectionAssert.AreEqual(expected_table.Rows[i].ItemArray, actual_table.Rows[i].ItemArray);
                }
            }

            // 確認(Failureブロブ)
            CollectionAssert.AreEqual(expected_failure_names, actual_failure_names);
            CollectionAssert.AreEqual(expected_failure_contents, actual_failure_contents);

            // 確認(ログ)
            foreach (var expected_log_message in expected_log_messages)
            {
                var matching_element = actual_log_messages.FirstOrDefault(actual => actual.Contains(expected_log_message));
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(matching_element, string.Format("「{0}」に一致する要素が見つかりません", expected_log_message));
                if (matching_element != null)
                {
                    actual_log_messages.Remove(matching_element);
                }
            }
        }
コード例 #6
0
        public void ReceiveDiskDriveTest(string no, string in_InitializeSqlSet, string in_Message, string expected_AlarmQueueSet, string expected_TableData, string expected_FailureBlobFileSet, string expected_LogMessages, string remarks)
        {
            List <TestLog> actual_logs = new List <TestLog>();

            // DI
            DependencyInjection(DefaultAppSettingValues, actual_logs);

            // テストデータ準備
            {
                if (Directory.Exists(in_InitializeSqlSet))
                {
                    using (SqlConnection connection = new SqlConnection(settings.PrimaryDbConnectionString))
                    {
                        try
                        {
                            connection.Open();
                            foreach (string path in Directory.GetFiles(in_InitializeSqlSet, "*.sql", SearchOption.AllDirectories))
                            {
                                string cmdText = File.ReadAllText(path);
                                using (SqlCommand command = new SqlCommand(cmdText, connection))
                                {
                                    command.ExecuteNonQuery();
                                }
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }

                in_Message = (in_Message != null && File.Exists(in_Message)) ? File.ReadAllText(in_Message) : in_Message;
            }

            // テスト実行後、テーブルを評価するかどうか
            bool isCheckTable = !string.IsNullOrEmpty(expected_TableData) && File.Exists(expected_TableData);

            // 評価対象テーブル名
            string targetTableName = isCheckTable ? Path.GetFileNameWithoutExtension(expected_TableData) : null;

            // 期待値
            List <string> expected_queues    = Directory.Exists(expected_AlarmQueueSet) ? Directory.GetFiles(expected_AlarmQueueSet, "*.json").Select(x => File.ReadAllText(x)).ToList() : new List <string>();
            DataTable     expected_table     = isCheckTable ? DataTableHelper.SelectCsv(settings.PrimaryDbConnectionString, expected_TableData, targetTableName) : null;
            DirectoryInfo expectedFailureDir = new DirectoryInfo(expected_FailureBlobFileSet);

            string[]      expectedFailureFiles      = expectedFailureDir.Exists ? expectedFailureDir.GetFiles("*", SearchOption.AllDirectories).Select(x => x.FullName).OrderBy(x => x).ToArray() : new string[] { };
            string[]      expected_failure_names    = expectedFailureFiles.Select(x => x.Replace(expectedFailureDir.FullName, string.Empty)).ToArray();
            string[]      expected_failure_contents = expectedFailureFiles.Select(x => File.ReadAllText(x)).ToArray();
            List <string> expected_log_messages     = (expected_LogMessages != null && File.Exists(expected_LogMessages)) ? File.ReadLines(expected_LogMessages).ToList() : new List <string>();

            // テスト実行
            target.ReceiveDiskDrive(in_Message, new TestLogger <DiskDrivePremonitorController>(actual_logs));

            // テスト結果
            List <string> actual_queses = QueueOperation.GetMessages(settings.AlarmQueueName, settings.QueueStorageConnectionString);
            DataTable     actual_table  = isCheckTable ? DataTableHelper.SelectTable(settings.PrimaryDbConnectionString, "SELECT * FROM " + targetTableName) : null;
            DirectoryInfo actualDir     = new DirectoryInfo(Path.Combine(TestResultRootDir, no));

            string[]      actualFailureFiles      = failureBlob.Client.GetFiles(settings.FailureBlobContainerName, actualDir).OrderBy(x => x).ToArray();
            string[]      actual_failure_names    = actualFailureFiles.Select(x => x.Replace(actualDir.FullName, string.Empty)).ToArray();
            string[]      actual_failure_contents = actualFailureFiles.Select(x => File.ReadAllText(x)).ToArray();
            List <string> actual_log_messages     = actual_logs.Select(x => x.GetSimpleText()).ToList();

            // 確認(アラームキュー)
            CollectionAssert.AreEqual(expected_queues, actual_queses);

            // 確認(DT_SMART_ANALYSIS_RESULT)
            if (isCheckTable)
            {
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(expected_table.Rows.Count, actual_table.Rows.Count);
                for (int i = 0; i < expected_table.Rows.Count; i++)
                {
                    CollectionAssert.AreEqual(expected_table.Rows[i].ItemArray, actual_table.Rows[i].ItemArray);
                }
            }

            // 確認(Failureブロブ)
            CollectionAssert.AreEqual(expected_failure_names, actual_failure_names);
            CollectionAssert.AreEqual(expected_failure_contents, actual_failure_contents);

            // 確認(ログ)
            foreach (var expected_log_message in expected_log_messages)
            {
                var matching_element = actual_log_messages.FirstOrDefault(actual => actual.Contains(expected_log_message));
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(matching_element, string.Format("「{0}」に一致する要素が見つかりません", expected_log_message));
                if (matching_element != null)
                {
                    actual_log_messages.Remove(matching_element);
                }
            }
        }