@@ -488,39 +488,39 @@ public async Task AuthenticationManager_LogoutCallback_NavigatesToLoginFailureOn
488
488
public static TheoryData < UIValidator > DisplaysRightUIData { get ; } = new TheoryData < UIValidator >
489
489
{
490
490
{ new UIValidator {
491
- Action = "login" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LoggingIn = validator . Render ; } }
491
+ Action = "login" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LoggingIn = validator . FakeRender ; } }
492
492
} ,
493
493
{ new UIValidator {
494
- Action = "login-callback" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . CompletingLoggingIn = validator . Render ; } }
494
+ Action = "login-callback" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . CompletingLoggingIn = validator . FakeRender ; } }
495
495
} ,
496
496
{ new UIValidator {
497
- Action = "login-failed" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogInFailed = m => builder => validator . Render ( builder ) ; } }
497
+ Action = "login-failed" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogInFailed = m => builder => validator . FakeRender ( builder ) ; } }
498
498
} ,
499
499
{ new UIValidator {
500
- Action = "profile" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LoggingIn = validator . Render ; } }
500
+ Action = "profile" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LoggingIn = validator . FakeRender ; } }
501
501
} ,
502
502
// Profile fragment overrides
503
503
{ new UIValidator {
504
- Action = "profile" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . UserProfile = validator . Render ; } }
504
+ Action = "profile" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . UserProfile = validator . FakeRender ; } }
505
505
} ,
506
506
{ new UIValidator {
507
- Action = "register" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LoggingIn = validator . Render ; } }
507
+ Action = "register" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LoggingIn = validator . FakeRender ; } }
508
508
} ,
509
509
// Register fragment overrides
510
510
{ new UIValidator {
511
- Action = "register" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . Registering = validator . Render ; } }
511
+ Action = "register" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . Registering = validator . FakeRender ; } }
512
512
} ,
513
513
{ new UIValidator {
514
- Action = "logout" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogOut = validator . Render ; } }
514
+ Action = "logout" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogOut = validator . FakeRender ; } }
515
515
} ,
516
516
{ new UIValidator {
517
- Action = "logout-callback" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . CompletingLogOut = validator . Render ; } }
517
+ Action = "logout-callback" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . CompletingLogOut = validator . FakeRender ; } }
518
518
} ,
519
519
{ new UIValidator {
520
- Action = "logout-failed" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogOutFailed = m => builder => validator . Render ( builder ) ; } }
520
+ Action = "logout-failed" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogOutFailed = m => builder => validator . FakeRender ( builder ) ; } }
521
521
} ,
522
522
{ new UIValidator {
523
- Action = "logged-out" , SetupAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogOutSucceeded = validator . Render ; } }
523
+ Action = "logged-out" , SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . LogOutSucceeded = validator . FakeRender ; } }
524
524
} ,
525
525
} ;
526
526
@@ -531,8 +531,72 @@ public async Task AuthenticationManager_DisplaysRightUI_ForEachStateAsync(UIVali
531
531
// Arrange
532
532
var renderer = new TestRenderer ( new ServiceCollection ( ) . BuildServiceProvider ( ) ) ;
533
533
var authenticator = new TestRemoteAuthenticatorView ( ) ;
534
+ renderer . Attach ( authenticator ) ;
535
+ validator . SetupFakeRender ( authenticator ) ;
536
+
537
+ var parameters = ParameterView . FromDictionary ( new Dictionary < string , object >
538
+ {
539
+ [ _action ] = validator . Action
540
+ } ) ;
541
+
542
+ // Act
543
+ await renderer . Dispatcher . InvokeAsync < object > ( ( ) => authenticator . SetParametersAsync ( parameters ) ) ;
544
+
545
+ // Assert
546
+ Assert . True ( validator . WasCalled ) ;
547
+ }
548
+
549
+ [ Theory ]
550
+ [ MemberData ( nameof ( DisplaysRightUIData ) ) ]
551
+ public async Task AuthenticationManager_DoesNotThrowExceptionOnDisplaysUI_WhenPathsAreMissing ( UIValidator validator )
552
+ {
553
+ // Arrange
554
+ var renderer = new TestRenderer ( new ServiceCollection ( ) . BuildServiceProvider ( ) ) ;
555
+ var authenticator = new TestRemoteAuthenticatorView ( new RemoteAuthenticationApplicationPathsOptions ( ) ) ;
556
+ renderer . Attach ( authenticator ) ;
557
+ validator . SetupFakeRender ( authenticator ) ;
558
+
559
+ var parameters = ParameterView . FromDictionary ( new Dictionary < string , object >
560
+ {
561
+ [ _action ] = validator . Action
562
+ } ) ;
563
+
564
+ // Act
565
+ Task result = await renderer . Dispatcher . InvokeAsync < Task > ( ( ) => authenticator . SetParametersAsync ( parameters ) ) ;
566
+
567
+
568
+ // Assert
569
+ Assert . Null ( result . Exception ) ;
570
+ }
571
+
572
+ public static TheoryData < UIValidator , string > DisplaysRightUIWhenPathsAreMissingData { get ; } = new TheoryData < UIValidator , string >
573
+ {
574
+ // Profile fragment overrides
575
+ {
576
+ new UIValidator {
577
+ Action = "profile" ,
578
+ SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . UserProfile = validator . FakeRender ; } ,
579
+ RetrieveOriginalRenderAction = ( validator , remoteAuthenticator ) => { validator . OriginalRender = remoteAuthenticator . UserProfile ; } } ,
580
+ "ProfileNotSupportedFragment"
581
+ } ,
582
+ {
583
+ new UIValidator {
584
+ Action = "register" ,
585
+ SetupFakeRenderAction = ( validator , remoteAuthenticator ) => { remoteAuthenticator . Registering = validator . FakeRender ; } ,
586
+ RetrieveOriginalRenderAction = ( validator , remoteAuthenticator ) => { validator . OriginalRender = remoteAuthenticator . Registering ; } } ,
587
+ "RegisterNotSupportedFragment"
588
+ }
589
+ } ;
590
+
591
+ [ Theory ]
592
+ [ MemberData ( nameof ( DisplaysRightUIWhenPathsAreMissingData ) ) ]
593
+ public async Task AuthenticationManager_DisplaysRightUI_WhenPathsAreMissing ( UIValidator validator , string methodName )
594
+ {
595
+ // Arrange
596
+ var renderer = new TestRenderer ( new ServiceCollection ( ) . BuildServiceProvider ( ) ) ;
597
+ var jsRuntime = new TestJsRuntime ( ) ;
598
+ var authenticator = new TestRemoteAuthenticatorView ( new RemoteAuthenticationApplicationPathsOptions ( ) , jsRuntime ) ;
534
599
renderer . Attach ( authenticator ) ;
535
- validator . Setup ( authenticator ) ;
536
600
537
601
var parameters = ParameterView . FromDictionary ( new Dictionary < string , object >
538
602
{
@@ -541,21 +605,30 @@ public async Task AuthenticationManager_DisplaysRightUI_ForEachStateAsync(UIVali
541
605
542
606
// Act
543
607
await renderer . Dispatcher . InvokeAsync < object > ( ( ) => authenticator . SetParametersAsync ( parameters ) ) ;
608
+ validator . RetrieveOriginalRender ( authenticator ) ;
609
+ validator . SetupFakeRender ( authenticator ) ;
610
+ Task result = await renderer . Dispatcher . InvokeAsync < Task > ( ( ) => authenticator . SetParametersAsync ( parameters ) ) ;
611
+
544
612
545
613
// Assert
546
614
Assert . True ( validator . WasCalled ) ;
615
+ Assert . Equal ( methodName , validator . OriginalRender . Method . Name ) ;
616
+ Assert . Equal ( default , jsRuntime . LastInvocation ) ;
547
617
}
548
618
549
619
public class UIValidator
550
620
{
551
621
public string Action { get ; set ; }
552
- public Action < UIValidator , RemoteAuthenticatorViewCore < RemoteAuthenticationState > > SetupAction { get ; set ; }
622
+ public Action < UIValidator , RemoteAuthenticatorViewCore < RemoteAuthenticationState > > SetupFakeRenderAction { get ; set ; }
623
+ public Action < UIValidator , RemoteAuthenticatorViewCore < RemoteAuthenticationState > > RetrieveOriginalRenderAction { get ; set ; }
553
624
public bool WasCalled { get ; set ; }
554
- public RenderFragment Render { get ; set ; }
625
+ public RenderFragment OriginalRender { get ; set ; }
626
+ public RenderFragment FakeRender { get ; set ; }
555
627
556
- public UIValidator ( ) => Render = builder => WasCalled = true ;
628
+ public UIValidator ( ) => FakeRender = builder => WasCalled = true ;
557
629
558
- internal void Setup ( TestRemoteAuthenticatorView manager ) => SetupAction ( this , manager ) ;
630
+ internal void SetupFakeRender ( TestRemoteAuthenticatorView manager ) => SetupFakeRenderAction ( this , manager ) ;
631
+ internal void RetrieveOriginalRender ( TestRemoteAuthenticatorView manager ) => RetrieveOriginalRenderAction ( this , manager ) ;
559
632
}
560
633
561
634
private static
@@ -646,6 +719,12 @@ public TestRemoteAuthenticatorView()
646
719
} ;
647
720
}
648
721
722
+ public TestRemoteAuthenticatorView ( RemoteAuthenticationApplicationPathsOptions applicationPaths , IJSRuntime jsRuntime = default )
723
+ {
724
+ ApplicationPaths = applicationPaths ;
725
+ JS = jsRuntime ;
726
+ }
727
+
649
728
protected override Task OnParametersSetAsync ( )
650
729
{
651
730
if ( Action == "register" || Action == "profile" )
0 commit comments