public void TestExceptionDuringProcessReport()
        {
            session.DeleteEach<ReportResultLog>();
            var dtStart = DateTime.Now;
            var gr = new FakeGeneralReport();
            var reports = new[] {
                new FakeReport(), new FakeReportWithReportException(), new FakeReportWithReportException(),
                new FakeReport(), new FakeReportWithException(), new FakeReport()
            };
            reports.Each(x => gr.Reports.Enqueue(x));
            FlushAndCommit();

            var ex = false;
            try {
                gr.ProcessReports(new ReportExecuteLog(), null, false, DateTime.Today, DateTime.Today, false);
            }
            catch (ReportException e) {
                Assert.That(e.Message, Is.EqualTo("Системная ошибка."));
                Assert.That(e.SubreportCode, Is.EqualTo(10));
                Assert.That(e.Payer, Is.EqualTo("Тестовый плательщик"));
                Assert.That(e.ReportCaption, Is.EqualTo("FakeReportWithException"));
                ex = true;
            }
            Assert.That(ex, Is.True);
            // Проверяем записи в логах
            var logs = session.Query<ReportResultLog>().Where(l => l.StartTime >= dtStart).OrderBy(l => l.StartTime).ToList();
            Assert.That(logs.Count, Is.EqualTo(5), $"время запуска {dtStart}");
            Assert.That(logs[0].ErrorMessage, Is.Null);
            Assert.That(logs[1].ErrorMessage, Does.Contain("Ошибка при формировании отчета."));
            Assert.That(logs[2].ErrorMessage, Does.Contain("Ошибка при формировании отчета."));
            Assert.That(logs[3].ErrorMessage, Is.Null);
            Assert.That(logs[4].ErrorMessage, Does.Contain("Системная ошибка."));
        }
        public void Do_not_throw_empty_exception()
        {
            var gr = new FakeGeneralReport();
            var reports = new[] {
                new FakeReportWithReportException {
                    ReportCode = 1
                }
            };
            reports.Each(x => gr.Reports.Enqueue(x));

            var ex = Assert.Throws<ReportException>(() => gr.ProcessReports(new ReportExecuteLog(), null, false, DateTime.Today, DateTime.Today, false));
            Assert.AreEqual("Ошибка при формировании отчета.", ex.Message);
            Assert.AreEqual(1, ex.SubreportCode);
        }
Пример #3
0
        public void Archive_files_for_report_type()
        {
            var connection = (MySqlConnection)session.Connection;

            try {
                var report = new FakeGeneralReport();
                report.Id = 1;
                report.SendDescriptionFile = true;
                report.Connection          = connection;
                object reportTypeCode = null;

                new MySqlCommand("update reports.general_reports r set r.SendDescriptionFile = true where generalreportcode = 1", connection).ExecuteNonQuery();
                new MySqlCommand("update reports.reports r set r.Enabled = true where generalreportcode = 1", connection).ExecuteNonQuery();
                new MySqlCommand("delete from reports.filessendwithreport;delete from reports.fileforreporttypes;", connection).ExecuteNonQuery();
                report.DataTable = report.GetReports();
                foreach (DataRow row in report.DataTable.Rows)
                {
                    reportTypeCode = row[BaseReportColumns.colReportTypeCode];
                    new MySqlCommand(string.Format("insert into reports.fileforreporttypes (File, ReportType) value ('testFile{0}', {0})", reportTypeCode), connection).ExecuteNonQuery();
                }
                var files      = session.CreateSQLQuery("select id from reports.fileforreporttypes;").List <uint>();
                var filesNames = session.CreateSQLQuery("select File from reports.fileforreporttypes group by File;").List <string>();
                foreach (var file in files)
                {
                    var create = File.Create(file.ToString());
                    create.Close();
                }
                Assert.IsNotNull(reportTypeCode);
                var additionalFiles = report.GetFilesForReports();
                Assert.That(additionalFiles.Count, Is.GreaterThan(0));
                Assert.That(additionalFiles.Count, Is.EqualTo(filesNames.Count()));
                foreach (var file in files)
                {
                    File.Delete(file.ToString());
                }
            }
            finally {
                new MySqlCommand("delete from reports.filessendwithreport;delete from reports.fileforreporttypes;", connection).ExecuteNonQuery();
            }
        }