@@ -1270,75 +1270,122 @@ static void Main()
12701270 result . StdOut . ShouldBe ( [ "136" ] , result ) ;
12711271 }
12721272
1273- [ Theory ]
1274- [ InlineData ( 20 ) ]
1275- [ InlineData ( 21 ) ]
1276- [ InlineData ( 22 ) ]
1277- [ InlineData ( 23 ) ]
1278- [ InlineData ( 24 ) ]
1279- [ InlineData ( 25 ) ]
1280- [ InlineData ( 26 ) ]
1281- [ InlineData ( 27 ) ]
1282- [ InlineData ( 28 ) ]
1283- [ InlineData ( 29 ) ]
1284- [ InlineData ( 30 ) ]
1285- public async Task ShouldFailWhenLightweightRootHasTooManyTaggedArguments ( int argsCount )
1273+ private async Task ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( string argumentExpression )
12861274 {
12871275 // Given
1288- var ctorArgs = new global ::System . Collections . Generic . List < string > ( ) ;
1289- var sumArgs = new global ::System . Collections . Generic . List < string > ( ) ;
1290- var rootArgs = new global ::System . Collections . Generic . List < string > ( ) ;
1291- var callArgs = new global ::System . Collections . Generic . List < string > ( ) ;
1292- for ( var i = 1 ; i <= argsCount ; i ++ )
1293- {
1294- ctorArgs . Add ( $ "[Tag(\" a{ i } \" )] int a{ i } ") ;
1295- sumArgs . Add ( $ "a{ i } ") ;
1296- rootArgs . Add ( $ ".RootArg<int>(\" a{ i } \" , \" a{ i } \" )") ;
1297- callArgs . Add ( i . ToString ( ) ) ;
1298- }
1299-
1300- var ctorSeparator = ",\n " ;
1301- var rootSeparator = "\n " ;
1302-
1303- var setupCode = $ """
1276+
1277+ // When
1278+ var result = await $$ """
13041279 using Pure.DI;
13051280
13061281 namespace Sample;
13071282
1308- interface IService {{ int Sum {{ get; }} }}
1309- class Service(
1310- { string . Join ( ctorSeparator , ctorArgs ) } )
1311- : IService
1312- {{
1313- public int Sum {{ get; }} = { string . Join ( " + " , sumArgs ) } ;
1314- }}
1283+ interface IService { }
1284+ class Service(int id) : IService { }
13151285
13161286 partial class Composition
1317- {{
1287+ {
13181288 void Setup() => DI.Setup(nameof(Composition))
13191289 .Hint(Hint.Resolve, "Off")
1320- { string . Join ( rootSeparator , rootArgs ) }
1290+ .RootArg<int>("id")
13211291 .Bind<IService>().To<Service>()
13221292 .Root<IService>("Create", kind: RootKinds.Light);
1323- }}
1293+ }
13241294
13251295 class Program
1326- {{
1296+ {
13271297 static void Main()
1328- {{
1298+ {
13291299 var composition = new Composition();
1330- var service = composition.Create({ string . Join ( ", " , callArgs ) } );
1331- }}
1332- }}
1333- """ ;
1334-
1335- // When
1336- var result = await setupCode . RunAsync ( new Options ( LanguageVersion . Preview , CheckCompilationErrors : false ) ) ;
1300+ var service = composition.Create({{ argumentExpression }} );
1301+ }
1302+ }
1303+ """ . RunAsync ( new Options ( LanguageVersion . Preview , CheckCompilationErrors : false ) ) ;
13371304
13381305 // Then
13391306 result . Success . ShouldBeFalse ( result ) ;
13401307 }
13411308
1309+ [ Fact ]
1310+ public Task ShouldFailWhenCallingLightweightRootWithBoolArgument ( ) =>
1311+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "true" ) ;
1312+
1313+ [ Fact ]
1314+ public Task ShouldFailWhenCallingLightweightRootWithCharArgument ( ) =>
1315+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "'a'" ) ;
1316+
1317+ [ Fact ]
1318+ public Task ShouldFailWhenCallingLightweightRootWithStringArgument ( ) =>
1319+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "\" abc\" " ) ;
1320+
1321+ [ Fact ]
1322+ public Task ShouldFailWhenCallingLightweightRootWithNullArgument ( ) =>
1323+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "null" ) ;
1324+
1325+ [ Fact ]
1326+ public Task ShouldFailWhenCallingLightweightRootWithDoubleArgument ( ) =>
1327+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "1.23" ) ;
1328+
1329+ [ Fact ]
1330+ public Task ShouldFailWhenCallingLightweightRootWithFloatArgument ( ) =>
1331+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "1.23f" ) ;
1332+
1333+ [ Fact ]
1334+ public Task ShouldFailWhenCallingLightweightRootWithDecimalArgument ( ) =>
1335+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "1.23m" ) ;
1336+
1337+ [ Fact ]
1338+ public Task ShouldFailWhenCallingLightweightRootWithLongArgument ( ) =>
1339+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "1L" ) ;
1340+
1341+ [ Fact ]
1342+ public Task ShouldFailWhenCallingLightweightRootWithUIntArgument ( ) =>
1343+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "1u" ) ;
1344+
1345+ [ Fact ]
1346+ public Task ShouldFailWhenCallingLightweightRootWithULongArgument ( ) =>
1347+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "1ul" ) ;
1348+
1349+ [ Fact ]
1350+ public Task ShouldFailWhenCallingLightweightRootWithShortArgument ( ) =>
1351+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "(short)1" ) ;
1352+
1353+ [ Fact ]
1354+ public Task ShouldFailWhenCallingLightweightRootWithByteArgument ( ) =>
1355+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "(byte)1" ) ;
1356+
1357+ [ Fact ]
1358+ public Task ShouldFailWhenCallingLightweightRootWithSByteArgument ( ) =>
1359+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "(sbyte)1" ) ;
1360+
1361+ [ Fact ]
1362+ public Task ShouldFailWhenCallingLightweightRootWithNIntArgument ( ) =>
1363+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "(nint)1" ) ;
1364+
1365+ [ Fact ]
1366+ public Task ShouldFailWhenCallingLightweightRootWithNUIntArgument ( ) =>
1367+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "(nuint)1" ) ;
1368+
1369+ [ Fact ]
1370+ public Task ShouldFailWhenCallingLightweightRootWithObjectArgument ( ) =>
1371+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "new object()" ) ;
1372+
1373+ [ Fact ]
1374+ public Task ShouldFailWhenCallingLightweightRootWithDateTimeArgument ( ) =>
1375+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "System.DateTime.Now" ) ;
1376+
1377+ [ Fact ]
1378+ public Task ShouldFailWhenCallingLightweightRootWithGuidArgument ( ) =>
1379+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "System.Guid.NewGuid()" ) ;
1380+
1381+ [ Fact ]
1382+ public Task ShouldFailWhenCallingLightweightRootWithArrayArgument ( ) =>
1383+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "new[] { 1, 2, 3 }" ) ;
1384+
1385+ [ Fact ]
1386+ public Task ShouldFailWhenCallingLightweightRootWithLambdaArgument ( ) =>
1387+ ShouldFailWhenCallingLightweightRootWithWrongIntArgument ( "() => 1" ) ;
1388+
13421389 [ Fact ]
13431390 public async Task ShouldFailWhenCallingLightweightRootWithWrongArgumentType ( )
13441391 {
0 commit comments