File tree Expand file tree Collapse file tree
samples/AfterBlazorServerSide.Tests/Migration
src/BlazorWebFormsComponents.Test Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public async Task PostBack_Button_TriggersPostBackEvent()
2828
2929 try
3030 {
31- await page . GotoAsync ( $ "{ _fixture . BaseUrl } /postback-demo ", new PageGotoOptions
31+ await page . GotoAsync ( $ "{ _fixture . BaseUrl } /ControlSamples/PostBackDemo ", new PageGotoOptions
3232 {
3333 WaitUntil = WaitUntilState . NetworkIdle ,
3434 Timeout = 30000
@@ -76,7 +76,7 @@ public async Task PostBackHyperlink_Click_TriggersPostBackEvent()
7676
7777 try
7878 {
79- await page . GotoAsync ( $ "{ _fixture . BaseUrl } /postback-demo ", new PageGotoOptions
79+ await page . GotoAsync ( $ "{ _fixture . BaseUrl } /ControlSamples/PostBackDemo ", new PageGotoOptions
8080 {
8181 WaitUntil = WaitUntilState . NetworkIdle ,
8282 Timeout = 30000
@@ -124,7 +124,7 @@ public async Task ScriptManager_GetCurrent_RegistersStartupScript()
124124
125125 try
126126 {
127- await page . GotoAsync ( $ "{ _fixture . BaseUrl } /postback-demo ", new PageGotoOptions
127+ await page . GotoAsync ( $ "{ _fixture . BaseUrl } /ControlSamples/PostBackDemo ", new PageGotoOptions
128128 {
129129 WaitUntil = WaitUntilState . NetworkIdle ,
130130 Timeout = 30000
Original file line number Diff line number Diff line change @@ -30,9 +30,8 @@ protected BlazorWebFormsTestContext() : this(null)
3030 /// <param name="outputHelper">Optional xUnit test output helper for logging. When provided, enables logging output in test results.</param>
3131 protected BlazorWebFormsTestContext ( ITestOutputHelper outputHelper )
3232 {
33- // Configure bUnit's JSInterop to handle the OnAfterRender call
34- // This is required because the base component calls this on first render
35- JSInterop . SetupVoid ( "bwfc.Page.OnAfterRender" ) ;
33+ // Configure bUnit's JSInterop to handle all JS calls from lifecycle methods
34+ JSInterop . Mode = JSRuntimeMode . Loose ;
3635
3736 // Register required services for BaseWebFormsComponent and WebFormsPageBase
3837 Services . AddSingleton < LinkGenerator > ( new Mock < LinkGenerator > ( ) . Object ) ;
@@ -41,6 +40,7 @@ protected BlazorWebFormsTestContext(ITestOutputHelper outputHelper)
4140 Services . AddMemoryCache ( ) ;
4241 Services . AddScoped < CacheShim > ( ) ;
4342 Services . AddScoped < ServerShim > ( ) ;
43+ Services . AddScoped < ClientScriptShim > ( ) ;
4444
4545 // Always register logging so ILogger<T> is resolvable.
4646 // Add xUnit output sink when a test output helper is provided.
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public class IsPostBackTests : IDisposable
3434 public IsPostBackTests ( )
3535 {
3636 _ctx = new BunitContext ( ) ;
37- _ctx . JSInterop . SetupVoid ( "bwfc.Page.OnAfterRender" ) ;
37+ _ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
3838 _ctx . Services . AddSingleton < LinkGenerator > ( new Mock < LinkGenerator > ( ) . Object ) ;
3939 _ctx . Services . AddSingleton < IDataProtectionProvider > ( new EphemeralDataProtectionProvider ( ) ) ;
4040 _ctx . Services . AddLogging ( ) ;
@@ -43,6 +43,7 @@ public IsPostBackTests()
4343 _ctx . Services . AddMemoryCache ( ) ;
4444 _ctx . Services . AddScoped < CacheShim > ( ) ;
4545 _ctx . Services . AddScoped < ServerShim > ( ) ;
46+ _ctx . Services . AddScoped < ClientScriptShim > ( ) ;
4647 }
4748
4849 private static IWebHostEnvironment CreateMockWebHostEnv ( )
Original file line number Diff line number Diff line change 7373
7474 private (IRenderedComponent <TestPage > cut , CapturingLinkGenerator linkGen ) RenderWithCapturingLinkGen ()
7575 {
76+ JSInterop .Mode = JSRuntimeMode .Loose ;
7677 var linkGen = new CapturingLinkGenerator ();
7778 Services .AddSingleton <LinkGenerator >(linkGen );
7879 var mockHttpAccessor = new Mock <IHttpContextAccessor >();
9495 Services .AddMemoryCache ();
9596 Services .AddScoped <CacheShim >();
9697 Services .AddScoped <ServerShim >();
98+ Services .AddScoped <ClientScriptShim >();
9799 }
98100
99101 [Fact ]
Original file line number Diff line number Diff line change 2929
3030 private IRenderedComponent <TestPage > RenderWithHttpContext ()
3131 {
32+ JSInterop .Mode = JSRuntimeMode .Loose ;
3233 var mockHttpAccessor = new Mock <IHttpContextAccessor >();
3334 mockHttpAccessor .Setup (x => x .HttpContext ).Returns (new DefaultHttpContext ());
3435 Services .AddSingleton <IHttpContextAccessor >(mockHttpAccessor .Object );
4243
4344 private IRenderedComponent <TestPage > RenderWithoutHttpContext ()
4445 {
46+ JSInterop .Mode = JSRuntimeMode .Loose ;
4547 var mockHttpAccessor = new Mock <IHttpContextAccessor >();
4648 mockHttpAccessor .Setup (x => x .HttpContext ).Returns ((HttpContext )null );
4749 Services .AddSingleton <IHttpContextAccessor >(mockHttpAccessor .Object );
6264 Services .AddMemoryCache ();
6365 Services .AddScoped <CacheShim >();
6466 Services .AddScoped <ServerShim >();
67+ Services .AddScoped <ClientScriptShim >();
6568 }
6669
6770 [Fact ]
Original file line number Diff line number Diff line change 2222
2323 private IRenderedComponent <TestPage > RenderWithMockNav (string uri = null )
2424 {
25+ JSInterop .Mode = JSRuntimeMode .Loose ;
2526 var nav = new MockNavigationManager (initialUri : uri ?? " http://localhost/" );
2627 Services .AddSingleton <Microsoft .AspNetCore .Components .NavigationManager >(nav );
2728 var mockAccessor = new Mock <IHttpContextAccessor >();
4344 Services .AddMemoryCache ();
4445 Services .AddScoped <CacheShim >();
4546 Services .AddScoped <ServerShim >();
47+ Services .AddScoped <ClientScriptShim >();
4648 }
4749
4850 [Fact ]
118120 [Fact ]
119121 public void Cookies_WithHttpContext_ReturnsRealCookies ()
120122 {
123+ JSInterop .Mode = JSRuntimeMode .Loose ;
121124 // Set up a real HttpContext with cookies
122125 var httpContext = new DefaultHttpContext ();
123126 httpContext .Request .Headers [" Cookie" ] = " session=abc123" ;
Original file line number Diff line number Diff line change 2121
2222 private (IRenderedComponent <TestPage > cut , MockNavigationManager nav ) RenderWithMockNav ()
2323 {
24+ JSInterop .Mode = JSRuntimeMode .Loose ;
2425 var mockNav = new MockNavigationManager ();
2526 Services .AddSingleton <Microsoft .AspNetCore .Components .NavigationManager >(mockNav );
2627 Services .AddLogging ();
3334 Services .AddMemoryCache ();
3435 Services .AddScoped <CacheShim >();
3536 Services .AddScoped <ServerShim >();
37+ Services .AddScoped <ClientScriptShim >();
3638 return (Render <TestPage >(), mockNav );
3739 }
3840
Original file line number Diff line number Diff line change 2020
2121 private IRenderedComponent <TestPage > RenderTestPage ()
2222 {
23+ JSInterop .Mode = JSRuntimeMode .Loose ;
2324 Services .AddLogging ();
2425 Services .AddScoped <SessionShim >();
2526 Services .AddScoped <IPageService , PageService >();
3637 Services .AddMemoryCache ();
3738 Services .AddScoped <CacheShim >();
3839 Services .AddScoped <ServerShim >();
40+ Services .AddScoped <ClientScriptShim >();
3941 }
4042
4143 [Fact ]
Original file line number Diff line number Diff line change 2222
2323 private IRenderedComponent <TestPage > RenderTestPage ()
2424 {
25+ JSInterop .Mode = JSRuntimeMode .Loose ;
2526 Services .AddLogging ();
2627 Services .AddScoped <SessionShim >();
2728 Services .AddScoped <IPageService , PageService >();
3839 Services .AddMemoryCache ();
3940 Services .AddScoped <CacheShim >();
4041 Services .AddScoped <ServerShim >();
42+ Services .AddScoped <ClientScriptShim >();
4143 }
4244
4345 [Fact ]
You can’t perform that action at this time.
0 commit comments