@@ -166,4 +166,73 @@ public partial class PersonSetup
166166 result . Should ( ) . HaveClass ( "MyTests.PersonSetup" )
167167 . WithoutMethod ( "GetNumber" , "System.Func<int>" ) ;
168168 }
169+
170+ [ TestMethod ]
171+ public void EnsureDefaultValueWithStringEmptyIsCreatedCorrectly ( )
172+ {
173+ var code = @"namespace MyTests
174+ {
175+ using FluentSetups;
176+
177+ [FluentSetup]
178+ public partial class PersonSetup
179+ {
180+ [FluentMember]
181+ private string name = string.Empty;
182+ }
183+ }" ;
184+
185+ var result = Setup . SourceGeneratorTest ( )
186+ . WithSource ( code )
187+ . Done ( ) ;
188+
189+ result . Should ( ) . NotHaveErrors ( ) . And
190+ . HaveClass ( "MyTests.PersonSetup" )
191+ . WhereMethod ( "GetName" )
192+ . IsProtected ( )
193+ . Contains ( "return name;" ) ;
194+ }
195+
196+ [ TestMethod ]
197+ public void EnsureDefaultValueWorksCorrectlyForSetupClassesWithDifferentNamePattern ( )
198+ {
199+ var code = @"namespace MyTests
200+ {
201+ using FluentSetups;
202+
203+ public class Color
204+ {
205+ public string Name { get; set; }
206+
207+ public int Opacity { get; set; }
208+ }
209+
210+ [FluentSetup(typeof(Color))]
211+ public partial class ColorSetup
212+ {
213+ }
214+
215+ [FluentSetup(typeof(Color), SetupMethod = ""ColorWithDefaults"")]
216+ public partial class ColorWithDefaultsSetup
217+ {
218+ [FluentMember]
219+ private string name = string.Empty;
220+
221+ [FluentMember]
222+ private int opacity = -1;
223+ }
224+ }" ;
225+
226+ var result = Setup . SourceGeneratorTest ( )
227+ . WithSource ( code )
228+ . Done ( ) ;
229+
230+ result . Should ( ) . NotHaveErrors ( ) . And
231+ . HaveClass ( "MyTests.ColorWithDefaultsSetup" )
232+ . WhereMethod ( "GetName" )
233+ . IsProtected ( )
234+ . Contains ( "return name;" ) ;
235+
236+ result . Print ( ) ;
237+ }
169238}
0 commit comments