summaryrefslogtreecommitdiff
path: root/src/test/PlayingWithActiveReports.Test/Repositories/QuestionBankTest.cs
blob: a8d86cbdeabe30917e39cb6bd9aa9296f97cd170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections.Generic;
using MbUnit.Framework;
using PlayingWithActiveReports.Core.Domain;
using PlayingWithActiveReports.Core.Repositories;

namespace PlayingWithActiveReports.Test {
	[TestFixture]
	public class QuestionBankTest {
		[Test]
		public void Should_Be_Able_To_Create_A_New_Question( ) {
			const string withText = "How are you?";
			IQuestionBank bank = CreateSut( );
			IQuestion question = bank.CreateQuestion( withText );

			Assert.AreEqual( withText, question.Text );
			Assert.IsNotNull( question.Id );
		}

		[Test]
		public void Should_Contain_No_Items( ) {
			IEnumerable< IQuestion > allQuestions = CreateSut( ).FindAll( );
			Assert.AreEqual( 0, GetCountFor( allQuestions ) );
		}

		[Test]
		public void Should_Return_Count_Of_2( ) {
			IQuestionBank bank = CreateSut( );
			bank.CreateQuestion( "What is your name?" );
			bank.CreateQuestion( "How old are you?" );

			Assert.AreEqual( 2, bank.Count );
		}

		[RowTest]
		[Row( 1 )]
		[Row( 2 )]
		[Row( 3 )]
		[Row( 4 )]
		public void Should_Return_2_Items( int expectedCount ) {
			IQuestionBank bank = CreateSut( );

			for( int i = 0; i < expectedCount; i++ ) {
				bank.CreateQuestion( "How old are you?" );
			}

			Assert.AreEqual( expectedCount, GetCountFor( bank.FindAll( ) ) );
		}

		private int GetCountFor< T >( IEnumerable< T > items ) {
			return new List< T >( items ).Count;
		}

		private IQuestionBank CreateSut( ) {
			return new QuestionBank( );
		}
	}
}