@@ -438,4 +438,134 @@ await SetUpSourceGeneratorTest(code,
438438 . WithArguments ( "UnsupportedTask" , "System.Threading.Tasks.Task<int>" , "TestClassWithTask" )
439439 ) . RunAsync ( ) ;
440440 }
441+
442+ [ TestMethod ]
443+ public async Task TestNino012_NotPublic ( )
444+ {
445+ var code = @"
446+ using Nino.Core;
447+
448+ [NinoType]
449+ public class TestClass
450+ {
451+ [NinoRefDeserialization]
452+ private static TestClass GetInstance() => new TestClass();
453+
454+ public int Value;
455+ }
456+ " ;
457+
458+ await SetUpAnalyzerTest ( code ,
459+ Verify . Diagnostic ( "NINO012" )
460+ . WithSpan ( 8 , 30 , 8 , 41 )
461+ . WithArguments ( "GetInstance" , "must be public" ) ) . RunAsync ( ) ;
462+ }
463+
464+ [ TestMethod ]
465+ public async Task TestNino012_NotStatic ( )
466+ {
467+ var code = @"
468+ using Nino.Core;
469+
470+ [NinoType]
471+ public class TestClass
472+ {
473+ [NinoRefDeserialization]
474+ public TestClass GetInstance() => new TestClass();
475+
476+ public int Value;
477+ }
478+ " ;
479+
480+ await SetUpAnalyzerTest ( code ,
481+ Verify . Diagnostic ( "NINO012" )
482+ . WithSpan ( 8 , 22 , 8 , 33 )
483+ . WithArguments ( "GetInstance" , "must be static" ) ) . RunAsync ( ) ;
484+ }
485+
486+ [ TestMethod ]
487+ public async Task TestNino012_HasParameters ( )
488+ {
489+ var code = @"
490+ using Nino.Core;
491+
492+ [NinoType]
493+ public class TestClass
494+ {
495+ [NinoRefDeserialization]
496+ public static TestClass GetInstance(int value) => new TestClass();
497+
498+ public int Value;
499+ }
500+ " ;
501+
502+ await SetUpAnalyzerTest ( code ,
503+ Verify . Diagnostic ( "NINO012" )
504+ . WithSpan ( 8 , 29 , 8 , 40 )
505+ . WithArguments ( "GetInstance" , "must be parameterless" ) ) . RunAsync ( ) ;
506+ }
507+
508+ [ TestMethod ]
509+ public async Task TestNino012_WrongReturnType ( )
510+ {
511+ var code = @"
512+ using Nino.Core;
513+
514+ [NinoType]
515+ public class TestClass
516+ {
517+ [NinoRefDeserialization]
518+ public static object GetInstance() => new TestClass();
519+
520+ public int Value;
521+ }
522+ " ;
523+
524+ await SetUpAnalyzerTest ( code ,
525+ Verify . Diagnostic ( "NINO012" )
526+ . WithSpan ( 8 , 26 , 8 , 37 )
527+ . WithArguments ( "GetInstance" , "must return TestClass" ) ) . RunAsync ( ) ;
528+ }
529+
530+ [ TestMethod ]
531+ public async Task TestNino012_MultipleErrors ( )
532+ {
533+ var code = @"
534+ using Nino.Core;
535+
536+ [NinoType]
537+ public class TestClass
538+ {
539+ [NinoRefDeserialization]
540+ private object GetInstance(int value) => new TestClass();
541+
542+ public int Value;
543+ }
544+ " ;
545+
546+ await SetUpAnalyzerTest ( code ,
547+ Verify . Diagnostic ( "NINO012" )
548+ . WithSpan ( 8 , 20 , 8 , 31 )
549+ . WithArguments ( "GetInstance" , "must be public, must be static, must be parameterless, must return TestClass" ) ) . RunAsync ( ) ;
550+ }
551+
552+ [ TestMethod ]
553+ public async Task TestNino012_ValidUsage ( )
554+ {
555+ var code = @"
556+ using Nino.Core;
557+
558+ [NinoType]
559+ public class TestClass
560+ {
561+ [NinoRefDeserialization]
562+ public static TestClass GetInstance() => new TestClass();
563+
564+ public int Value;
565+ }
566+ " ;
567+
568+ // No diagnostics expected for valid usage
569+ await SetUpAnalyzerTest ( code ) . RunAsync ( ) ;
570+ }
441571}
0 commit comments