示例#1
0
        public IReportModel CreateReport()
        {
            var model = new ReportModel(_queryBuilder, _queryExecutor);

            model.SetDataSource(ReportDataSource);

            foreach (var repotColumn in ReportColumns)
            {
                model.AddReportColumn(repotColumn);
            }

            return(model);
        }
        public void Get_ValidInputs_ReportReturned()
        {
            var columns = new List <IReportColumn>()
            {
                new ReportColumn()
                {
                    Title = "Column A",
                    SqlValueExpression = "select A"
                }
            };
            var    filters    = Enumerable.Empty <IReportFilter>();
            string dataSource = "select * from ...";

            var       sqlCommand  = new SqlCommand("select ColumnA from ....");
            DataTable reportTable = new DataTable();

            reportTable.Columns.Add("ColumnA");
            reportTable.Rows.Add("Row #1");
            reportTable.Rows.Add("Row #2");

            var queryBuilder = new Mock <IQueryBuilder>();

            queryBuilder.Setup(x => x.BuildQuery(columns, filters, dataSource)).Returns(sqlCommand);

            var queryExecutor = new Mock <IQueryExecutor>();

            queryExecutor.Setup(x => x.ExecuteToDataTable(sqlCommand)).Returns(reportTable);

            var reportModel = new ReportModel(queryBuilder.Object, queryExecutor.Object);

            reportModel.AddReportColumn(columns.First());
            reportModel.SetDataSource(new ReportDataSource("select * from ..."));

            var result = reportModel.Get(columns, filters);

            Assert.That(result.Count, Is.EqualTo(2));

            Assert.That(result[0].Count, Is.EqualTo(1));
            Assert.True(result[0].ContainsKey("ColumnA"));
            Assert.That(result[0]["ColumnA"], Is.EqualTo("Row #1"));

            Assert.That(result[1].Count, Is.EqualTo(1));
            Assert.True(result[1].ContainsKey("ColumnA"));
            Assert.That(result[1]["ColumnA"], Is.EqualTo("Row #2"));
        }
 public void AddReportColumn_GivenNullValue_ThrownArgumentNullException()
 {
     Assert.Throws(typeof(ArgumentNullException),
                   () =>
     {
         _reportModel.AddReportColumn(null);
     });
 }