Repository: dotnet/aspnetcore
File: src/Components/Components/test/PersistentValueProviderComponentSubscriptionTests.cs (C#)

Code before:
    }

    [Fact]
    public void Constructor_ThrowsClearException_ForPrivateGetter()
    {
        // Arrange
        var state = new PersistentComponentState(new Dictionary<string, byte[]>(), [], []);
        state.InitializeExistingState(new Dictionary<string, byte[]>(), RestoreContext.InitialValue);
        var renderer = new TestRenderer();
        var component = new ComponentWithPrivateGetter();
        var componentState = CreateComponentState(renderer, component, null, null);
        var cascadingParameterInfo = CreateCascadingParameterInfo(nameof(ComponentWithPrivateGetter.PropertyWithPrivateGetter), typeof(string));
        var serviceProvider = new ServiceCollection().BuildServiceProvider();
        var logger = NullLogger.Instance;

        // Act & Assert
        var exception = Assert.Throws<InvalidOperationException>(() =>
            new PersistentValueProviderComponentSubscription(
                state, componentState, cascadingParameterInfo, serviceProvider, logger));

        // Should throw a clear error about non-public getter
        Assert.Contains("not public", exception.Message);
        Assert.Contains("PersistentState", exception.Message);
    }

    [Fact]
    public void Constructor_WorksCorrectly_ForPublicProperty()
    {
        // Arrange
        var state = new PersistentComponentState(new Dictionary<string, byte[]>(), [], []);
        state.InitializeExistingState(new Dictionary<string, byte[]>(), RestoreContext.InitialValue);
        var renderer = new TestRenderer();
        var component = new TestComponent { State = "test-value" };
        var componentState = CreateComponentState(renderer, component, null, null);
        var cascadingParameterInfo = CreateCascadingParameterInfo(nameof(TestComponent.State), typeof(string));
        var serviceProvider = new ServiceCollection().BuildServiceProvider();
        var logger = NullLogger.Instance;

        // Act & Assert - Should not throw
        var subscription = new PersistentValueProviderComponentSubscription(
            state, componentState, cascadingParameterInfo, serviceProvider, logger);

        Assert.NotNull(subscription);
        subscription.Dispose();
    }
}


Review comment (suggestion):
We could add a test to check if the old exception is still thrown when property does not exist.

```
[Fact]
public void PersistentState_Throws_WhenPropertyIsMissing()
{
    var component = new ComponentWithPrivateGetter();
    var provider = ....

    var ex = Assert.Throws<InvalidOperationException>(() =>
        provider.Subscribe(component, "MissingProperty"));

    Assert.Contains("Property MissingProperty not found", ex.Message);
}
```

Code after:

    [Fact]
    public void Constructor_ThrowsClearException_ForPrivateGetter()
    {
        // Arrange
        var state = new PersistentComponentState(new Dictionary<string, byte[]>(), [], []);
        state.InitializeExistingState(new Dictionary<string, byte[]>(), RestoreContext.InitialValue);
        var renderer = new TestRenderer();
        var component = new ComponentWithPrivateGetter();
        var componentState = CreateComponentState(renderer, component, null, null);
        var cascadingParameterInfo = CreateCascadingParameterInfo(nameof(ComponentWithPrivateGetter.PropertyWithPrivateGetter), typeof(string));
        var serviceProvider = new ServiceCollection().BuildServiceProvider();
        var logger = NullLogger.Instance;

        // Act & Assert
        var exception = Assert.Throws<InvalidOperationException>(() =>
            new PersistentValueProviderComponentSubscription(
                state, componentState, cascadingParameterInfo, serviceProvider, logger));

        // Should throw a clear error about needing a public property with public getter
        Assert.Contains("A public property", exception.Message);
        Assert.Contains("with a public getter wasn't found", exception.Message);
    }

    [Fact]
    public void Constructor_WorksCorrectly_ForPublicProperty()
    {
        // Arrange
        var state = new PersistentComponentState(new Dictionary<string, byte[]>(), [], []);
        state.InitializeExistingState(new Dictionary<string, byte[]>(), RestoreContext.InitialValue);
        var renderer = new TestRenderer();
        var component = new TestComponent { State = "test-value" };
        var componentState = CreateComponentState(renderer, component, null, null);
        var cascadingParameterInfo = CreateCascadingParameterInfo(nameof(TestComponent.State), typeof(string));
        var serviceProvider = new ServiceCollection().BuildServiceProvider();
        var logger = NullLogger.Instance;

        // Act & Assert - Should not throw
        var subscription = new PersistentValueProviderComponentSubscription(
            state, componentState, cascadingParameterInfo, serviceProvider, logger);

        Assert.NotNull(subscription);
        subscription.Dispose();
    }
}