public void FindCascadingParameters_MismatchingNameButMatchingType_ReturnsNull() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new ValueType1(), "MismatchName"), new ComponentWithNamedCascadingParam()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Null(result); }
public void FindCascadingParameters_ConsumerSpecifiesNameButSupplierDoesNot_ReturnsNull() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new ValueType1()), new ComponentWithNamedCascadingParam()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Null(result); }
public void FindCascadingParameters_TypeAssignmentIsInvalidForNullValue_ReturnsNull() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent((object)null), new ComponentWithGenericCascadingParam <ValueType1>()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Null(result); }
public void FindCascadingParameters_ComponentRequestsDerivedType_ReturnsNull() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new CascadingValueTypeBaseClass()), new ComponentWithGenericCascadingParam <CascadingValueTypeDerivedClass>()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Null(result); }
public void FindCascadingParameters_SupplierSpecifiesNameButConsumerDoesNot_ReturnsEmpty() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new ValueType1(), "MatchOnName"), new ComponentWithCascadingParams()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Empty(result); }
public void FindCascadingParameters_IfHasNoMatchesInAncestors_ReturnsNull() { // Arrange: Build the ancestry list var states = CreateAncestry( new ComponentWithNoParams(), CreateCascadingValueComponent("Hello"), new ComponentWithNoParams(), new ComponentWithCascadingParams()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Null(result); }
/// <summary> /// Constructs an instance of <see cref="ComponentState"/>. /// </summary> /// <param name="renderer">The <see cref="Renderer"/> with which the new instance should be associated.</param> /// <param name="componentId">The externally visible identifier for the <see cref="IComponent"/>. The identifier must be unique in the context of the <see cref="Renderer"/>.</param> /// <param name="component">The <see cref="IComponent"/> whose state is being tracked.</param> /// <param name="parentComponentState">The <see cref="ComponentState"/> for the parent component, or null if this is a root component.</param> public ComponentState(Renderer renderer, int componentId, IComponent component, ComponentState parentComponentState) { ComponentId = componentId; ParentComponentState = parentComponentState; Component = component ?? throw new ArgumentNullException(nameof(component)); _renderer = renderer ?? throw new ArgumentNullException(nameof(renderer)); _cascadingParameters = CascadingParameterState.FindCascadingParameters(this); CurrentRenderTree = new RenderTreeBuilder(); _renderTreeBuilderPrevious = new RenderTreeBuilder(); if (_cascadingParameters != null) { _hasAnyCascadingParameterSubscriptions = AddCascadingParameterSubscriptions(); } }
public void FindCascadingParameters_MatchingNameAndType_ReturnsMatches() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new ValueType1(), "matchonNAME"), // To show it's case-insensitive new ComponentWithNamedCascadingParam()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Collection(result, match => { Assert.Equal(nameof(ComponentWithNamedCascadingParam.SomeLocalName), match.LocalValueName); Assert.Same(states[0].Component, match.ValueSupplier); }); }
public void FindCascadingParameters_TypeAssignmentIsValidForNullValue_ReturnsMatches() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent((CascadingValueTypeDerivedClass)null), new ComponentWithGenericCascadingParam <CascadingValueTypeBaseClass>()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Collection(result, match => { Assert.Equal(nameof(ComponentWithGenericCascadingParam <object> .LocalName), match.LocalValueName); Assert.Same(states[0].Component, match.ValueSupplier); }); }
public void FindCascadingParameters_ComponentRequestsImplementedInterface_ReturnsMatches() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new CascadingValueTypeDerivedClass()), new ComponentWithGenericCascadingParam <ICascadingValueTypeDerivedClassInterface>()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Collection(result, match => { Assert.Equal(nameof(ComponentWithGenericCascadingParam <object> .LocalName), match.LocalValueName); Assert.Same(states[0].Component, match.ValueSupplier); }); }
public void FindCascadingParameters_IfHasPartialMatchesInAncestors_ReturnsMatches() { // Arrange var states = CreateAncestry( new ComponentWithNoParams(), CreateCascadingValueComponent(new ValueType2()), new ComponentWithNoParams(), new ComponentWithCascadingParams()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Collection(result, match => { Assert.Equal(nameof(ComponentWithCascadingParams.CascadingParam2), match.LocalValueName); Assert.Same(states[1].Component, match.ValueSupplier); }); }
public void FindCascadingParameters_CanOverrideNonNullValueWithNull() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new ValueType1()), CreateCascadingValueComponent((ValueType1)null), new ComponentWithCascadingParams()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Collection(result.OrderBy(x => x.LocalValueName), match => { Assert.Equal(nameof(ComponentWithCascadingParams.CascadingParam1), match.LocalValueName); Assert.Same(states[1].Component, match.ValueSupplier); Assert.Null(match.ValueSupplier.CurrentValue); }); }
public void FindCascadingParameters_InheritedParameters_ReturnsMatches() { // Arrange var states = CreateAncestry( CreateCascadingValueComponent(new ValueType1()), CreateCascadingValueComponent(new ValueType3()), new ComponentWithInheritedCascadingParams()); // Act var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert Assert.Collection(result.OrderBy(x => x.LocalValueName), match => { Assert.Equal(nameof(ComponentWithCascadingParams.CascadingParam1), match.LocalValueName); Assert.Same(states[0].Component, match.ValueSupplier); }, match => { Assert.Equal(nameof(ComponentWithInheritedCascadingParams.CascadingParam3), match.LocalValueName); Assert.Same(states[1].Component, match.ValueSupplier); }); }