summaryrefslogtreecommitdiff
path: root/src/test/PlayingWithActiveReports.Test/Reports
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/PlayingWithActiveReports.Test/Reports')
-rw-r--r--src/test/PlayingWithActiveReports.Test/Reports/MainReportTest.cs69
-rw-r--r--src/test/PlayingWithActiveReports.Test/Reports/ReportParameterTest.cs16
-rw-r--r--src/test/PlayingWithActiveReports.Test/Reports/ReportSectionTest.cs45
-rw-r--r--src/test/PlayingWithActiveReports.Test/Reports/ResultsReportTest.cs33
-rw-r--r--src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionBuilderTest.cs72
-rw-r--r--src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionTest.cs34
6 files changed, 269 insertions, 0 deletions
diff --git a/src/test/PlayingWithActiveReports.Test/Reports/MainReportTest.cs b/src/test/PlayingWithActiveReports.Test/Reports/MainReportTest.cs
new file mode 100644
index 0000000..a45d7fc
--- /dev/null
+++ b/src/test/PlayingWithActiveReports.Test/Reports/MainReportTest.cs
@@ -0,0 +1,69 @@
+using System.Collections.Generic;
+using MbUnit.Framework;
+using PlayingWithActiveReports.Core.Reports;
+using Rhino.Mocks;
+using Rhino.Mocks.Constraints;
+
+namespace PlayingWithActiveReports.Test.Reports {
+ [TestFixture]
+ public class MainReportTest {
+ [SetUp]
+ public void Setup( ) {
+ _mockery = new MockRepository( );
+ }
+
+ [Test]
+ public void Should_Call_Build_On_Builders_When_Run( ) {
+ IList< ISectionBuilder > builders = new List< ISectionBuilder >( );
+ ISectionBuilder stubBuilder1 = _mockery.Stub< ISectionBuilder >( );
+ ISectionBuilder stubBuilder2 = _mockery.Stub< ISectionBuilder >( );
+ ISectionBuilder stubBuilder3 = _mockery.Stub< ISectionBuilder >( );
+
+ builders.Add( stubBuilder1 );
+ builders.Add( stubBuilder2 );
+ builders.Add( stubBuilder3 );
+
+ using( _mockery.Record( ) ) {
+ stubBuilder1.BuildFrom( null );
+ LastCall.Constraints( Is.NotNull( ) );
+
+ stubBuilder2.BuildFrom( null );
+ LastCall.Constraints( Is.NotNull( ) );
+
+ stubBuilder3.BuildFrom( null );
+ LastCall.Constraints( Is.NotNull( ) );
+ }
+
+ using( _mockery.Playback( ) ) {
+ IMainReport report = CreateSut( builders ).Run( );
+ }
+ }
+
+ [Test]
+ public void Should_Be_Able_To_Find_Section_By_Name( ) {
+ IReportSection stubSection = _mockery.Stub< IReportSection >( );
+ using( _mockery.Record( ) ) {
+ SetupResult.For( stubSection.Name ).Return( "sectionName" );
+ }
+
+ using( _mockery.Playback( ) ) {
+ IMainReport report = CreateSut( );
+ report.AddSection( stubSection );
+ Assert.AreEqual( stubSection, report.FindBy(
+ new Specification< IReportSection >(
+ delegate( IReportSection section ) { return section.Name == "sectionName"; }
+ ) ) );
+ }
+ }
+
+ private IMainReport CreateSut( IList< ISectionBuilder > builders ) {
+ return new MainReport( builders );
+ }
+
+ private IMainReport CreateSut( ) {
+ return new MainReport( );
+ }
+
+ private MockRepository _mockery;
+ }
+} \ No newline at end of file
diff --git a/src/test/PlayingWithActiveReports.Test/Reports/ReportParameterTest.cs b/src/test/PlayingWithActiveReports.Test/Reports/ReportParameterTest.cs
new file mode 100644
index 0000000..1adff8f
--- /dev/null
+++ b/src/test/PlayingWithActiveReports.Test/Reports/ReportParameterTest.cs
@@ -0,0 +1,16 @@
+using MbUnit.Framework;
+using PlayingWithActiveReports.Core.Reports;
+
+namespace PlayingWithActiveReports.Test.Reports {
+ [TestFixture]
+ public class ReportParameterTest {
+ [RowTest]
+ [Row( "key", "value" )]
+ [Row( "Text", "Hello World" )]
+ public void Should_Create_A_New_Report_Parameter( string key, string value ) {
+ IReportParameter parameter = new ReportParameter( key, value );
+ Assert.AreEqual( key, parameter.Key );
+ Assert.AreEqual( value, parameter.Value );
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/PlayingWithActiveReports.Test/Reports/ReportSectionTest.cs b/src/test/PlayingWithActiveReports.Test/Reports/ReportSectionTest.cs
new file mode 100644
index 0000000..6853b07
--- /dev/null
+++ b/src/test/PlayingWithActiveReports.Test/Reports/ReportSectionTest.cs
@@ -0,0 +1,45 @@
+using System.Collections.Generic;
+using MbUnit.Framework;
+using PlayingWithActiveReports.Core.Reports;
+
+namespace PlayingWithActiveReports.Test.Reports {
+ [TestFixture]
+ public class ReportSectionTest {
+ [Test]
+ public void Should_Contain_0_Parameters( ) {
+ Assert.AreEqual( 0, CreateSut( ).ParametersCount );
+ }
+
+ [Test]
+ public void Should_Bind_2_Parameters_To_Section( ) {
+ IList< IReportParameter > parameters = new List< IReportParameter >( );
+ parameters.Add( CreateParameter( "QuestionText", "How Old Are You?" ) );
+ parameters.Add( CreateParameter( "AnswerText", "23" ) );
+
+ IReportSection section = CreateSut( );
+ section.BindTo( parameters );
+ Assert.AreEqual( 2, section.ParametersCount );
+ }
+
+ [RowTest]
+ [Row( "Questions" )]
+ [Row( "Results" )]
+ [Row( "Table Of Contents" )]
+ public void Should_Set_Section_Name_To( string name ) {
+ Assert.AreEqual( name, CreateSut( ).WithName( name ).Name );
+ }
+
+ [Test]
+ public void Should_Contain_Undefined_Name( ) {
+ Assert.AreEqual( "Undefined", CreateSut( ).Name );
+ }
+
+ private IReportParameter CreateParameter( string key, string value ) {
+ return new ReportParameter( key, value );
+ }
+
+ private IReportSection CreateSut( ) {
+ return new ReportSection( );
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/PlayingWithActiveReports.Test/Reports/ResultsReportTest.cs b/src/test/PlayingWithActiveReports.Test/Reports/ResultsReportTest.cs
new file mode 100644
index 0000000..616be61
--- /dev/null
+++ b/src/test/PlayingWithActiveReports.Test/Reports/ResultsReportTest.cs
@@ -0,0 +1,33 @@
+using MbUnit.Framework;
+using PlayingWithActiveReports.Core.Reports;
+
+namespace PlayingWithActiveReports.Test.Reports {
+ [TestFixture]
+ public class ResultsReportTest {
+ [Test]
+ public void Should_Contain_Page_Header( ) {
+ IReportSection header = CreateSut( ).FindSectionBy( ReportSection.Header );
+ Assert.IsNotNull( header );
+ Assert.AreEqual( "Header", header.Name );
+ }
+
+ [Test]
+ public void Should_Contain_Page_Footer( ) {
+ IReportSection footer = CreateSut( ).FindSectionBy( ReportSection.Footer );
+ Assert.IsNotNull( footer );
+ Assert.AreEqual( "Footer", footer.Name );
+ }
+
+ [Test]
+ public void Should_Return_Questions_Results_Section( ) {
+ Assert.IsNotNull( CreateSut( ).FindSectionBy( ReportSection.Results ) );
+ }
+
+ [Test]
+ public void Should_Bind_All_Parameters_To_DataSource( ) {}
+
+ private IResultsReport CreateSut( ) {
+ return new ResultsReport( );
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionBuilderTest.cs b/src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionBuilderTest.cs
new file mode 100644
index 0000000..0661368
--- /dev/null
+++ b/src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionBuilderTest.cs
@@ -0,0 +1,72 @@
+using System.Collections.Generic;
+using MbUnit.Framework;
+using PlayingWithActiveReports.Core.Dto;
+using PlayingWithActiveReports.Core.Reports;
+using Rhino.Mocks;
+using Rhino.Mocks.Constraints;
+
+namespace PlayingWithActiveReports.Test.Reports {
+ [TestFixture]
+ public class ResultsSectionBuilderTest {
+ public delegate void CallBackAssertion( );
+
+ // get list of dto items to bind to section
+ // add section to the report
+
+ [SetUp]
+ public void Setup( ) {
+ _mockery = new MockRepository( );
+ _taskStub = _mockery.Stub< IResultSectionTask >( );
+ }
+
+ [Test]
+ public void Should_Add_Section_To_Report( ) {
+ IMainReport mainReportStub = _mockery.Stub< IMainReport >( );
+
+ using( _mockery.Record( ) ) {
+ mainReportStub.AddSection( null );
+ LastCall.Constraints( Is.TypeOf( typeof( IResultsSection ) ) );
+ }
+
+ using( _mockery.Playback( ) ) {
+ CreateSut( ).BuildFrom( mainReportStub );
+ }
+ }
+
+ [Test]
+ public void Should_Get_List_Of_Dtos_Using_Task( ) {
+ IMainReport mainReportStub = _mockery.Stub< IMainReport >( );
+
+ using( _mockery.Record( ) ) {
+ _taskStub.GetResults( );
+ }
+
+ using( _mockery.Playback( ) ) {
+ CreateSut( ).BuildFrom( mainReportStub );
+ }
+ }
+
+ [Test]
+ public void Should_Bind_Dtos_To_Section( ) {
+ IMainReport mainReportStub = _mockery.Stub< IMainReport >( );
+ IResultsSection sectionStub = _mockery.Stub< IResultsSection >( );
+ IEnumerable< DisplayReportQuestionDto > returnValue = _mockery.Stub< IEnumerable< DisplayReportQuestionDto > >( );
+
+ using( _mockery.Record( ) ) {
+ Expect.Call( _taskStub.GetResults( ) ).Return( returnValue );
+ sectionStub.BindTo( returnValue );
+ }
+
+ using( _mockery.Playback( ) ) {
+ CreateSut( ).BuildFrom( mainReportStub, sectionStub );
+ }
+ }
+
+ private ISectionBuilder CreateSut( ) {
+ return new ResultsSectionBuilder( _taskStub );
+ }
+
+ private MockRepository _mockery;
+ private IResultSectionTask _taskStub;
+ }
+} \ No newline at end of file
diff --git a/src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionTest.cs b/src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionTest.cs
new file mode 100644
index 0000000..bb185d4
--- /dev/null
+++ b/src/test/PlayingWithActiveReports.Test/Reports/ResultsSectionTest.cs
@@ -0,0 +1,34 @@
+using System.Collections.Generic;
+using MbUnit.Framework;
+using PlayingWithActiveReports.Core.Dto;
+using PlayingWithActiveReports.Core.Reports;
+
+namespace PlayingWithActiveReports.Test.Reports {
+ [TestFixture]
+ public class ResultsSectionTest {
+ [Test]
+ public void Should_Be_Able_To_Bind_Dtos_To_Report( ) {
+ IResultsSection section = CreateSut( );
+ IList< DisplayReportQuestionDto > results = new List< DisplayReportQuestionDto >( );
+ results.Add( CreateDto( "How are you?", "good" ) );
+ results.Add( CreateDto( "How are you?", "bad" ) );
+ results.Add( CreateDto( "How are you?", "hungry" ) );
+
+ section.BindTo( results );
+ Assert.AreEqual( 3, section.ResultsCount );
+ }
+
+ [Test]
+ public void Should_Have_No_Results( ) {
+ Assert.AreEqual( 0, CreateSut( ).ResultsCount );
+ }
+
+ private DisplayReportQuestionDto CreateDto( string question, string answer ) {
+ return new DisplayReportQuestionDto( question, answer );
+ }
+
+ private IResultsSection CreateSut( ) {
+ return new ResultsSection( );
+ }
+ }
+} \ No newline at end of file