public void Get_NullAsArguments_ThrownArgumentNulException() { Assert.Throws(typeof(ArgumentNullException), () => { _reportModel.Get(null, Enumerable.Empty <IReportFilter>()); }); Assert.Throws(typeof(ArgumentNullException), () => { _reportModel.Get(Enumerable.Empty <IReportColumn>(), null); }); }
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")); }