@@ -5,8 +5,8 @@ namespace BlazorWebFormsComponents.Cli.Tests.TransformUnit;
55
66/// <summary>
77/// Unit tests for SessionDetectTransform — detects Session["key"] and Cache["key"]
8- /// patterns, injects [Inject] SessionShim / CacheShim properties, and generates
9- /// migration guidance .
8+ /// patterns and generates migration guidance. Session/Cache are provided by
9+ /// WebFormsPageBase — no [Inject] needed .
1010/// </summary>
1111public class SessionDetectTransformTests
1212{
@@ -21,9 +21,10 @@ public class SessionDetectTransformTests
2121 } ;
2222
2323 [ Fact ]
24- public void InjectsSessionShimProperty ( )
24+ public void DetectsSessionAccess_AddsGuidance ( )
2525 {
26- var input = @"namespace MyApp
26+ var input = @"// =============================================================================
27+ namespace MyApp
2728{
2829 public partial class MyPage
2930 {
@@ -32,13 +33,16 @@ public partial class MyPage
3233}" ;
3334 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
3435
35- Assert . Contains ( "[Inject] private SessionShim Session { get; set; }" , result ) ;
36+ Assert . Contains ( "// --- Session State Migration ---" , result ) ;
37+ Assert . Contains ( "SessionShim on WebFormsPageBase" , result ) ;
38+ Assert . DoesNotContain ( "[Inject]" , result ) ;
3639 }
3740
3841 [ Fact ]
39- public void InjectsCacheShimProperty ( )
42+ public void DetectsCacheAccess_AddsGuidance ( )
4043 {
41- var input = @"namespace MyApp
44+ var input = @"// =============================================================================
45+ namespace MyApp
4246{
4347 public partial class MyPage
4448 {
@@ -47,13 +51,16 @@ public partial class MyPage
4751}" ;
4852 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
4953
50- Assert . Contains ( "[Inject] private CacheShim Cache { get; set; }" , result ) ;
54+ Assert . Contains ( "// --- Cache Migration ---" , result ) ;
55+ Assert . Contains ( "CacheShim on WebFormsPageBase" , result ) ;
56+ Assert . DoesNotContain ( "[Inject]" , result ) ;
5157 }
5258
5359 [ Fact ]
54- public void InjectsBothSessionAndCacheShims ( )
60+ public void DetectsBothSessionAndCache_AddsBothGuidanceBlocks ( )
5561 {
56- var input = @"namespace MyApp
62+ var input = @"// =============================================================================
63+ namespace MyApp
5764{
5865 public partial class MyPage
5966 {
@@ -66,8 +73,9 @@ void Load()
6673}" ;
6774 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
6875
69- Assert . Contains ( "[Inject] private SessionShim Session { get; set; }" , result ) ;
70- Assert . Contains ( "[Inject] private CacheShim Cache { get; set; }" , result ) ;
76+ Assert . Contains ( "// --- Session State Migration ---" , result ) ;
77+ Assert . Contains ( "// --- Cache Migration ---" , result ) ;
78+ Assert . DoesNotContain ( "[Inject]" , result ) ;
7179 }
7280
7381 [ Fact ]
@@ -84,7 +92,7 @@ public partial class MyPage
8492 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
8593
8694 Assert . Contains ( "// --- Session State Migration ---" , result ) ;
87- Assert . Contains ( "SessionShim auto-wired via [Inject] " , result ) ;
95+ Assert . Contains ( "calls work automatically via SessionShim on WebFormsPageBase " , result ) ;
8896 Assert . Contains ( "Session keys found: CartId" , result ) ;
8997 Assert . Contains ( "Options for long-term replacement:" , result ) ;
9098 }
@@ -103,7 +111,7 @@ public partial class MyPage
103111 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
104112
105113 Assert . Contains ( "// --- Cache Migration ---" , result ) ;
106- Assert . Contains ( "CacheShim auto-wired via [Inject] " , result ) ;
114+ Assert . Contains ( "calls work automatically via CacheShim on WebFormsPageBase " , result ) ;
107115 Assert . Contains ( "Cache keys found: Products" , result ) ;
108116 Assert . Contains ( "CacheShim wraps IMemoryCache" , result ) ;
109117 }
@@ -133,9 +141,10 @@ void Load()
133141 }
134142
135143 [ Fact ]
136- public void IdempotentDoesNotDuplicateInjectProperty ( )
144+ public void IdempotentDoesNotDuplicateGuidance ( )
137145 {
138- var input = @"namespace MyApp
146+ var input = @"// =============================================================================
147+ namespace MyApp
139148{
140149 public partial class MyPage
141150 {
@@ -145,13 +154,12 @@ public partial class MyPage
145154 var firstPass = _transform . Apply ( input , TestMetadata ( input ) ) ;
146155 var secondPass = _transform . Apply ( firstPass , TestMetadata ( firstPass ) ) ;
147156
148- // Count occurrences of the inject line
149- var injectCount = secondPass . Split ( "[Inject] private SessionShim Session" ) . Length - 1 ;
150- Assert . Equal ( 1 , injectCount ) ;
157+ var markerCount = secondPass . Split ( "// --- Session State Migration ---" ) . Length - 1 ;
158+ Assert . Equal ( 1 , markerCount ) ;
151159 }
152160
153161 [ Fact ]
154- public void IdempotentDoesNotDuplicateGuidanceBlock ( )
162+ public void IdempotentDoesNotDuplicateGuidanceBlock_WithTodoHeader ( )
155163 {
156164 var input = @"// =============================================================================
157165namespace MyApp
@@ -186,7 +194,8 @@ public partial class MyPage
186194 [ Fact ]
187195 public void DetectsVariableKeySessionAccess ( )
188196 {
189- var input = @"namespace MyApp
197+ var input = @"// =============================================================================
198+ namespace MyApp
190199{
191200 public partial class MyPage
192201 {
@@ -195,7 +204,8 @@ public partial class MyPage
195204}" ;
196205 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
197206
198- Assert . Contains ( "[Inject] private SessionShim Session { get; set; }" , result ) ;
207+ Assert . Contains ( "// --- Session State Migration ---" , result ) ;
208+ Assert . Contains ( "SessionShim on WebFormsPageBase" , result ) ;
199209 }
200210
201211 [ Fact ]
@@ -229,9 +239,10 @@ public partial class MyPage
229239 }
230240
231241 [ Fact ]
232- public void InjectPropertyAppearsAfterClassBrace ( )
242+ public void GuidanceAppearsInOutput ( )
233243 {
234- var input = @"namespace MyApp
244+ var input = @"// =============================================================================
245+ namespace MyApp
235246{
236247 public partial class MyPage
237248 {
@@ -240,10 +251,9 @@ public partial class MyPage
240251}" ;
241252 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
242253
243- var classIdx = result . IndexOf ( "public partial class MyPage" ) ;
244- var braceIdx = result . IndexOf ( '{' , classIdx ) ;
245- var injectIdx = result . IndexOf ( "[Inject] private SessionShim Session" , braceIdx ) ;
246- Assert . True ( injectIdx > braceIdx , "[Inject] should appear after the class opening brace" ) ;
254+ Assert . Contains ( "// --- Session State Migration ---" , result ) ;
255+ Assert . Contains ( "SessionShim on WebFormsPageBase" , result ) ;
256+ Assert . DoesNotContain ( "[Inject]" , result ) ;
247257 }
248258
249259 [ Fact ]
@@ -285,9 +295,10 @@ public partial class MyPage
285295 }
286296
287297 [ Fact ]
288- public void HttpContextCurrentSession_StillInjectsSessionShim ( )
298+ public void HttpContextCurrentSession_StillAddsSessionGuidance ( )
289299 {
290- var input = @"namespace MyApp
300+ var input = @"// =============================================================================
301+ namespace MyApp
291302{
292303 public partial class MyPage
293304 {
@@ -296,8 +307,9 @@ public partial class MyPage
296307}" ;
297308 var result = _transform . Apply ( input , TestMetadata ( input ) ) ;
298309
299- // After replacement, Session[ is detected → [Inject] is added
300- Assert . Contains ( "[Inject] private SessionShim Session { get; set; }" , result ) ;
310+ // After replacement, Session[ is detected → guidance is added
311+ Assert . Contains ( "SessionShim on WebFormsPageBase" , result ) ;
312+ Assert . DoesNotContain ( "[Inject]" , result ) ;
301313 }
302314
303315 [ Fact ]
0 commit comments