@@ -623,4 +623,90 @@ private class TestStore(IDictionary<string, byte[]> state) : IPersistentComponen
623623 public Task < IDictionary < string , byte [ ] > > GetPersistedStateAsync ( ) => Task . FromResult ( state ) ;
624624 public Task PersistStateAsync ( IReadOnlyDictionary < string , byte [ ] > state ) => throw new NotImplementedException ( ) ;
625625 }
626+
627+ private class ComponentWithPrivateProperty : IComponent
628+ {
629+ [ PersistentState ]
630+ private string PrivateValue { get ; set ; } = "initial" ;
631+
632+ public void Attach ( RenderHandle renderHandle ) => throw new NotImplementedException ( ) ;
633+ public Task SetParametersAsync ( ParameterView parameters ) => throw new NotImplementedException ( ) ;
634+ }
635+
636+ private class ComponentWithPrivateGetter : IComponent
637+ {
638+ [ PersistentState ]
639+ public string PropertyWithPrivateGetter { private get ; set ; } = "initial" ;
640+
641+ public void Attach ( RenderHandle renderHandle ) => throw new NotImplementedException ( ) ;
642+ public Task SetParametersAsync ( ParameterView parameters ) => throw new NotImplementedException ( ) ;
643+ }
644+
645+ [ Fact ]
646+ public void Constructor_ThrowsClearException_ForPrivateProperty ( )
647+ {
648+ // Arrange
649+ var state = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] , [ ] ) ;
650+ state . InitializeExistingState ( new Dictionary < string , byte [ ] > ( ) , RestoreContext . InitialValue ) ;
651+ var renderer = new TestRenderer ( ) ;
652+ var component = new ComponentWithPrivateProperty ( ) ;
653+ var componentState = CreateComponentState ( renderer , component , null , null ) ;
654+ var cascadingParameterInfo = CreateCascadingParameterInfo ( "PrivateValue" , typeof ( string ) ) ;
655+ var serviceProvider = new ServiceCollection ( ) . BuildServiceProvider ( ) ;
656+ var logger = NullLogger . Instance ;
657+
658+ // Act & Assert
659+ var exception = Assert . Throws < InvalidOperationException > ( ( ) =>
660+ new PersistentValueProviderComponentSubscription (
661+ state , componentState , cascadingParameterInfo , serviceProvider , logger ) ) ;
662+
663+ // Should throw a clear error about non-public properties, not "Property not found"
664+ Assert . Contains ( "not public" , exception . Message ) ;
665+ Assert . Contains ( "PersistentState" , exception . Message ) ;
666+ Assert . DoesNotContain ( "not found" , exception . Message ) ;
667+ }
668+
669+ [ Fact ]
670+ public void Constructor_ThrowsClearException_ForPrivateGetter ( )
671+ {
672+ // Arrange
673+ var state = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] , [ ] ) ;
674+ state . InitializeExistingState ( new Dictionary < string , byte [ ] > ( ) , RestoreContext . InitialValue ) ;
675+ var renderer = new TestRenderer ( ) ;
676+ var component = new ComponentWithPrivateGetter ( ) ;
677+ var componentState = CreateComponentState ( renderer , component , null , null ) ;
678+ var cascadingParameterInfo = CreateCascadingParameterInfo ( nameof ( ComponentWithPrivateGetter . PropertyWithPrivateGetter ) , typeof ( string ) ) ;
679+ var serviceProvider = new ServiceCollection ( ) . BuildServiceProvider ( ) ;
680+ var logger = NullLogger . Instance ;
681+
682+ // Act & Assert
683+ var exception = Assert . Throws < InvalidOperationException > ( ( ) =>
684+ new PersistentValueProviderComponentSubscription (
685+ state , componentState , cascadingParameterInfo , serviceProvider , logger ) ) ;
686+
687+ // Should throw a clear error about non-public getter
688+ Assert . Contains ( "not public" , exception . Message ) ;
689+ Assert . Contains ( "PersistentState" , exception . Message ) ;
690+ }
691+
692+ [ Fact ]
693+ public void Constructor_WorksCorrectly_ForPublicProperty ( )
694+ {
695+ // Arrange
696+ var state = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] , [ ] ) ;
697+ state . InitializeExistingState ( new Dictionary < string , byte [ ] > ( ) , RestoreContext . InitialValue ) ;
698+ var renderer = new TestRenderer ( ) ;
699+ var component = new TestComponent { State = "test-value" } ;
700+ var componentState = CreateComponentState ( renderer , component , null , null ) ;
701+ var cascadingParameterInfo = CreateCascadingParameterInfo ( nameof ( TestComponent . State ) , typeof ( string ) ) ;
702+ var serviceProvider = new ServiceCollection ( ) . BuildServiceProvider ( ) ;
703+ var logger = NullLogger . Instance ;
704+
705+ // Act & Assert - Should not throw
706+ var subscription = new PersistentValueProviderComponentSubscription (
707+ state , componentState , cascadingParameterInfo , serviceProvider , logger ) ;
708+
709+ Assert . NotNull ( subscription ) ;
710+ subscription . Dispose ( ) ;
711+ }
626712}
0 commit comments