33using System . Linq ;
44using Shouldly ;
55using TestStack . Dossier . DataSources . Generators ;
6+ using TestStack . Dossier . Factories ;
67using TestStack . Dossier . Lists ;
8+ using TestStack . Dossier . Tests . Stubs . Examples ;
79using TestStack . Dossier . Tests . Stubs . ViewModels ;
810using Xunit ;
911
@@ -167,5 +169,40 @@ public void WhenBuildingObjectsImplicitly_ThenTheAnonymousValueFixtureIsSharedAc
167169
168170 studentViewModels . Select ( x => x . Grade ) . ShouldBeUnique ( ) ;
169171 }
172+
173+ public void WhenBuildingObjectsWithCtorAndPrivateSetters_ShouldSetPrivateSettersByDefault ( )
174+ {
175+ var dto = Builder < MixedAccessibilityDto > . CreateListOfSize ( 1 )
176+ . TheFirst ( 1 )
177+ . Set ( x => x . SetByCtorWithPublicSetter , "1" )
178+ . Set ( x => x . SetByCtorWithPrivateSetter , "2" )
179+ . Set ( x => x . NotSetByCtorWithPrivateSetter , "3" )
180+ . Set ( x => x . NotSetByCtorWithPublicSetter , "4" )
181+ . BuildList ( )
182+ [ 0 ] ;
183+
184+ dto . SetByCtorWithPublicSetter . ShouldBe ( "1" ) ;
185+ dto . SetByCtorWithPrivateSetter . ShouldBe ( "2" ) ;
186+ dto . NotSetByCtorWithPrivateSetter . ShouldBe ( "3" ) ;
187+ dto . NotSetByCtorWithPublicSetter . ShouldBe ( "4" ) ;
188+ }
189+
190+ [ Fact ]
191+ public void GivenBuilderListWithFactoryOverride_WhenBuildingObjects_ShouldRespectOverriddenFactory ( )
192+ {
193+ var dto = Builder < MixedAccessibilityDto > . CreateListOfSize ( 1 , new CallConstructorFactory ( ) )
194+ . TheFirst ( 1 )
195+ . Set ( x => x . SetByCtorWithPublicSetter , "1" )
196+ . Set ( x => x . SetByCtorWithPrivateSetter , "2" )
197+ . Set ( x => x . NotSetByCtorWithPrivateSetter , "3" )
198+ . Set ( x => x . NotSetByCtorWithPublicSetter , "4" )
199+ . BuildList ( )
200+ [ 0 ] ;
201+
202+ dto . SetByCtorWithPublicSetter . ShouldBe ( "1" ) ;
203+ dto . SetByCtorWithPrivateSetter . ShouldBe ( "2" ) ;
204+ dto . NotSetByCtorWithPrivateSetter . ShouldNotBe ( "3" ) ;
205+ dto . NotSetByCtorWithPublicSetter . ShouldNotBe ( "4" ) ;
206+ }
170207 }
171208}
0 commit comments