1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using Shouldly ;
45using TestStack . Dossier . DataSources . Generators ;
56using TestStack . Dossier . Lists ;
67using TestStack . Dossier . Tests . Builders ;
7- using TestStack . Dossier . Tests . Entities ;
8+ using TestStack . Dossier . Tests . Stubs . ViewModels ;
89using Xunit ;
910
1011namespace TestStack . Dossier . Tests
1112{
1213 public class BuilderBuildListTests
1314 {
15+ private DateTime _enrollmentDate = new DateTime ( 2004 , 9 , 9 ) ;
16+
1417 [ Fact ]
1518 public void GivenANormalBuilderInstance_WhenCallingIsListBuilderProxy_ThenReturnFalse ( )
1619 {
17- var builder = Builder < Customer > . CreateNew ( ) ;
20+ var builder = Builder < StudentViewModel > . CreateNew ( ) ;
1821
1922 builder . IsListBuilderProxy ( ) . ShouldBe ( false ) ;
2023 }
2124
2225 [ Fact ]
2326 public void GivenAListBuilderProxyInstance_WhenCallingIsListBuilderProxy_ThenReturnTrue ( )
2427 {
25- var builder = Builder < Customer > . CreateListOfSize ( 1 ) . TheFirst ( 1 ) ;
28+ var builder = Builder < StudentViewModel > . CreateListOfSize ( 1 ) . TheFirst ( 1 ) ;
2629
2730 builder . IsListBuilderProxy ( ) . ShouldBe ( true ) ;
2831 }
2932
3033 [ Fact ]
3134 public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfEntitiesOfTheRightSizeShouldBeReturned ( )
3235 {
33- var builders = Builder < Customer > . CreateListOfSize ( 5 ) ;
36+ var builders = Builder < StudentViewModel > . CreateListOfSize ( 5 ) ;
3437
3538 var entities = builders . BuildList ( ) ;
3639
@@ -40,70 +43,52 @@ public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfEntiti
4043 [ Fact ]
4144 public void GivenListOfBuilders_WhenCallingBuildListImplicitly_ThenAListOfEntitiesOfTheRightSizeShouldBeReturned ( )
4245 {
43- List < Customer > entities = Builder < Customer > . CreateListOfSize ( 5 ) ;
46+ List < StudentViewModel > entities = Builder < StudentViewModel > . CreateListOfSize ( 5 ) ;
4447
4548 entities . Count . ShouldBe ( 5 ) ;
4649 }
4750
4851 [ Fact ]
4952 public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfEntitiesOfTheRightTypeShouldBeReturned ( )
5053 {
51- var builders = Builder < Customer > . CreateListOfSize ( 5 ) ;
54+ var builders = Builder < StudentViewModel > . CreateListOfSize ( 5 ) ;
5255
5356 var entities = builders . BuildList ( ) ;
5457
55- entities . ShouldBeAssignableTo < IList < Customer > > ( ) ;
58+ entities . ShouldBeAssignableTo < IList < StudentViewModel > > ( ) ;
5659 }
5760
5861 [ Fact ]
5962 public void GivenListOfBuilders_WhenCallingBuildListImplicitly_ThenAListOfEntitiesOfTheRightTypeShouldBeReturned ( )
6063 {
61- List < Customer > entities = Builder < Customer > . CreateListOfSize ( 5 ) ;
64+ List < StudentViewModel > entities = Builder < StudentViewModel > . CreateListOfSize ( 5 ) ;
6265
63- entities . ShouldBeAssignableTo < IList < Customer > > ( ) ;
66+ entities . ShouldBeAssignableTo < IList < StudentViewModel > > ( ) ;
6467 }
6568
6669 [ Fact ]
6770 public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfUniqueEntitiesShouldBeReturned ( )
6871 {
69- var builders = Builder < Customer > . CreateListOfSize ( 5 ) ;
72+ var builders = Builder < StudentViewModel > . CreateListOfSize ( 5 ) ;
7073
7174 var entities = builders . BuildList ( ) ;
7275
73- entities [ 0 ] . ShouldNotBe ( entities [ 1 ] ) ;
74- entities [ 0 ] . ShouldNotBe ( entities [ 2 ] ) ;
75- entities [ 0 ] . ShouldNotBe ( entities [ 3 ] ) ;
76- entities [ 0 ] . ShouldNotBe ( entities [ 4 ] ) ;
77- entities [ 1 ] . ShouldNotBe ( entities [ 2 ] ) ;
78- entities [ 1 ] . ShouldNotBe ( entities [ 3 ] ) ;
79- entities [ 1 ] . ShouldNotBe ( entities [ 4 ] ) ;
80- entities [ 2 ] . ShouldNotBe ( entities [ 3 ] ) ;
81- entities [ 2 ] . ShouldNotBe ( entities [ 4 ] ) ;
82- entities [ 3 ] . ShouldNotBe ( entities [ 4 ] ) ;
76+ entities . ShouldBeUnique ( ) ;
8377 }
8478
8579 [ Fact ]
8680 public void GivenListOfBuilders_WhenCallingBuildListImplicitly_ThenAListOfUniqueEntitiesShouldBeReturned ( )
8781 {
88- List < Customer > entities = Builder < Customer > . CreateListOfSize ( 5 ) ;
89-
90- entities [ 0 ] . ShouldNotBe ( entities [ 1 ] ) ;
91- entities [ 0 ] . ShouldNotBe ( entities [ 2 ] ) ;
92- entities [ 0 ] . ShouldNotBe ( entities [ 3 ] ) ;
93- entities [ 0 ] . ShouldNotBe ( entities [ 4 ] ) ;
94- entities [ 1 ] . ShouldNotBe ( entities [ 2 ] ) ;
95- entities [ 1 ] . ShouldNotBe ( entities [ 3 ] ) ;
96- entities [ 1 ] . ShouldNotBe ( entities [ 4 ] ) ;
97- entities [ 2 ] . ShouldNotBe ( entities [ 3 ] ) ;
98- entities [ 2 ] . ShouldNotBe ( entities [ 4 ] ) ;
99- entities [ 3 ] . ShouldNotBe ( entities [ 4 ] ) ;
82+ List < StudentViewModel > entities = Builder < StudentViewModel > . CreateListOfSize ( 5 ) ;
83+
84+ entities . ShouldBeUnique ( ) ;
10085 }
10186
10287 [ Fact ]
10388 public void GivenListOfBuildersWithCustomisation_WhenBuildingEntitiesExplicitly_ThenTheCustomisationShouldTakeEffect ( )
10489 {
10590 var generator = new SequentialGenerator ( 0 , 100 ) ;
106- var list = CustomerBuilder . CreateListOfSize ( 3 )
91+ var list = StudentViewModelBuilder . CreateListOfSize ( 3 )
10792 . All ( ) . With ( b => b . WithFirstName ( generator . Generate ( ) . ToString ( ) ) ) ;
10893
10994 var data = list . BuildList ( ) ;
@@ -117,7 +102,7 @@ public void GivenListOfBuildersWithCustomisation_WhenBuildingEntitiesImplicitly_
117102 {
118103 var generator = new SequentialGenerator ( 0 , 100 ) ;
119104
120- List < Customer > data = CustomerBuilder . CreateListOfSize ( 3 )
105+ List < StudentViewModel > data = StudentViewModelBuilder . CreateListOfSize ( 3 )
121106 . All ( ) . With ( b => b . WithFirstName ( generator . Generate ( ) . ToString ( ) ) ) ;
122107
123108 data . Select ( c => c . FirstName ) . ToArray ( )
@@ -128,67 +113,59 @@ public void GivenListOfBuildersWithCustomisation_WhenBuildingEntitiesImplicitly_
128113 public void GivenListOfBuildersWithARangeOfCustomisationMethods_WhenBuildingEntitiesExplicitly_ThenThenTheListIsBuiltAndModifiedCorrectly ( )
129114 {
130115 var i = 0 ;
131- var customers = CustomerBuilder . CreateListOfSize ( 5 )
116+ var studentViewModels = StudentViewModelBuilder . CreateListOfSize ( 5 )
132117 . TheFirst ( 1 ) . WithFirstName ( "First" )
133118 . TheNext ( 1 ) . WithLastName ( "Next Last" )
134119 . TheLast ( 1 ) . WithLastName ( "Last Last" )
135120 . ThePrevious ( 2 ) . With ( b => b . WithLastName ( "last" + ( ++ i ) . ToString ( ) ) )
136- . All ( ) . WhoJoinedIn ( 1999 )
121+ . All ( ) . WhoEntrolledIn ( _enrollmentDate )
137122 . BuildList ( ) ;
138123
139- customers . ShouldBeAssignableTo < IList < Customer > > ( ) ;
140- customers . Count . ShouldBe ( 5 ) ;
141- customers [ 0 ] . FirstName . ShouldBe ( "First" ) ;
142- customers [ 1 ] . LastName . ShouldBe ( "Next Last" ) ;
143- customers [ 2 ] . LastName . ShouldBe ( "last1" ) ;
144- customers [ 3 ] . LastName . ShouldBe ( "last2" ) ;
145- customers [ 4 ] . LastName . ShouldBe ( "Last Last" ) ;
146- customers . ShouldAllBe ( c => c . YearJoined == 1999 ) ;
124+ studentViewModels . ShouldBeAssignableTo < IList < StudentViewModel > > ( ) ;
125+ studentViewModels . Count . ShouldBe ( 5 ) ;
126+ studentViewModels [ 0 ] . FirstName . ShouldBe ( "First" ) ;
127+ studentViewModels [ 1 ] . LastName . ShouldBe ( "Next Last" ) ;
128+ studentViewModels [ 2 ] . LastName . ShouldBe ( "last1" ) ;
129+ studentViewModels [ 3 ] . LastName . ShouldBe ( "last2" ) ;
130+ studentViewModels [ 4 ] . LastName . ShouldBe ( "Last Last" ) ;
131+ studentViewModels . ShouldAllBe ( c => c . EnrollmentDate == _enrollmentDate ) ;
147132 }
148133
149134 [ Fact ]
150135 public void GivenListOfBuildersWithARangeOfCustomisationMethods_WhenBuildingEntitiesImplicitly_ThenThenTheListIsBuiltAndModifiedCorrectly ( )
151136 {
152137 var i = 0 ;
153- List < Customer > customers = CustomerBuilder . CreateListOfSize ( 5 )
138+ List < StudentViewModel > studentViewModels = StudentViewModelBuilder . CreateListOfSize ( 5 )
154139 . TheFirst ( 1 ) . WithFirstName ( "First" )
155140 . TheNext ( 1 ) . WithLastName ( "Next Last" )
156141 . TheLast ( 1 ) . WithLastName ( "Last Last" )
157142 . ThePrevious ( 2 ) . With ( b => b . WithLastName ( "last" + ( ++ i ) . ToString ( ) ) )
158- . All ( ) . WhoJoinedIn ( 1999 ) ;
159-
160- customers . ShouldBeAssignableTo < IList < Customer > > ( ) ;
161- customers . Count . ShouldBe ( 5 ) ;
162- customers [ 0 ] . FirstName . ShouldBe ( "First" ) ;
163- customers [ 1 ] . LastName . ShouldBe ( "Next Last" ) ;
164- customers [ 2 ] . LastName . ShouldBe ( "last1" ) ;
165- customers [ 3 ] . LastName . ShouldBe ( "last2" ) ;
166- customers [ 4 ] . LastName . ShouldBe ( "Last Last" ) ;
167- customers . ShouldAllBe ( c => c . YearJoined == 1999 ) ;
143+ . All ( ) . WhoEntrolledIn ( _enrollmentDate ) ;
144+
145+ studentViewModels . ShouldBeAssignableTo < IList < StudentViewModel > > ( ) ;
146+ studentViewModels . Count . ShouldBe ( 5 ) ;
147+ studentViewModels [ 0 ] . FirstName . ShouldBe ( "First" ) ;
148+ studentViewModels [ 1 ] . LastName . ShouldBe ( "Next Last" ) ;
149+ studentViewModels [ 2 ] . LastName . ShouldBe ( "last1" ) ;
150+ studentViewModels [ 3 ] . LastName . ShouldBe ( "last2" ) ;
151+ studentViewModels [ 4 ] . LastName . ShouldBe ( "Last Last" ) ;
152+ studentViewModels . ShouldAllBe ( c => c . EnrollmentDate == _enrollmentDate ) ;
168153 }
169154
170155 [ Fact ]
171156 public void WhenBuildingEntitiesExplicitly_ThenTheAnonymousValueFixtureIsSharedAcrossBuilders ( )
172157 {
173- var customers = CustomerBuilder . CreateListOfSize ( 5 ) . BuildList ( ) ;
158+ var studentViewModels = StudentViewModelBuilder . CreateListOfSize ( 5 ) . BuildList ( ) ;
174159
175- customers [ 0 ] . CustomerClass . ShouldBe ( CustomerClass . Normal ) ;
176- customers [ 1 ] . CustomerClass . ShouldBe ( CustomerClass . Bronze ) ;
177- customers [ 2 ] . CustomerClass . ShouldBe ( CustomerClass . Silver ) ;
178- customers [ 3 ] . CustomerClass . ShouldBe ( CustomerClass . Gold ) ;
179- customers [ 4 ] . CustomerClass . ShouldBe ( CustomerClass . Platinum ) ;
160+ studentViewModels . Select ( x => x . Grade ) . ShouldBeUnique ( ) ;
180161 }
181162
182163 [ Fact ]
183164 public void WhenBuildingEntitiesImplicitly_ThenTheAnonymousValueFixtureIsSharedAcrossBuilders ( )
184165 {
185- List < Customer > customers = CustomerBuilder . CreateListOfSize ( 5 ) ;
166+ List < StudentViewModel > studentViewModels = StudentViewModelBuilder . CreateListOfSize ( 5 ) ;
186167
187- customers [ 0 ] . CustomerClass . ShouldBe ( CustomerClass . Normal ) ;
188- customers [ 1 ] . CustomerClass . ShouldBe ( CustomerClass . Bronze ) ;
189- customers [ 2 ] . CustomerClass . ShouldBe ( CustomerClass . Silver ) ;
190- customers [ 3 ] . CustomerClass . ShouldBe ( CustomerClass . Gold ) ;
191- customers [ 4 ] . CustomerClass . ShouldBe ( CustomerClass . Platinum ) ;
168+ studentViewModels . Select ( x => x . Grade ) . ShouldBeUnique ( ) ;
192169 }
193170 }
194171}
0 commit comments