示例#1
0
    public void IncomingParameterMatchesDeclaredParameterCaseInsensitively_SetsValue()
    {
        // Arrange
        var parameters = new ParameterViewBuilder
        {
            { nameof(HasInstanceProperties.IntProp).ToLowerInvariant(), 123 }
        }.Build();
        var target = new HasInstanceProperties();

        // Act
        parameters.SetParameterProperties(target);

        // Assert
        Assert.Equal(123, target.IntProp);
    }
示例#2
0
    public void IncomingParameterMatchesPropertyNotDeclaredAsParameter_Throws()
    {
        // Arrange
        var target     = new HasPropertyWithoutParameterAttribute();
        var parameters = new ParameterViewBuilder
        {
            { nameof(HasPropertyWithoutParameterAttribute.IntProp), 123 },
        }.Build();

        // Act
        var ex = Assert.Throws <InvalidOperationException>(
            () => parameters.SetParameterProperties(target));

        // Assert
        Assert.Equal(default, target.IntProp);
示例#3
0
    public void IncomingParameterMatchesOverriddenParameter_ThatDoesNotHaveAttribute()
    {
        // Test for https://github.com/dotnet/aspnetcore/issues/13162
        // Arrange
        var parameters = new ParameterViewBuilder
        {
            { nameof(DerivedType.VirtualProp), 123 },
        }.Build();
        var target = new DerivedType();

        // Act
        parameters.SetParameterProperties(target);

        // Assert
        Assert.Equal(123, target.VirtualProp);
    }
示例#4
0
    public void IncomingParameterMatchesInheritedDeclaredParameter_SetsValue()
    {
        // Arrange
        var parameters = new ParameterViewBuilder
        {
            { nameof(HasInheritedProperties.IntProp), 123 },
            { nameof(HasInheritedProperties.DerivedClassIntProp), 456 },
        }.Build();
        var target = new HasInheritedProperties();

        // Act
        parameters.SetParameterProperties(target);

        // Assert
        Assert.Equal(123, target.IntProp);
        Assert.Equal(456, target.DerivedClassIntProp);
    }
示例#5
0
    public void IncomingParameterMatchesAnnotatedPrivateProperty_SetsValue()
    {
        // Arrange
        var someObject = new object();
        var parameters = new ParameterViewBuilder
        {
            { nameof(HasInstanceProperties.IntProp), 123 },
            { nameof(HasInstanceProperties.StringProp), "Hello" },
            { HasInstanceProperties.ObjectPropName, someObject },
        }.Build();
        var target = new HasInstanceProperties();

        // Act
        parameters.SetParameterProperties(target);

        // Assert
        Assert.Equal(123, target.IntProp);
        Assert.Equal("Hello", target.StringProp);
        Assert.Same(someObject, target.ObjectPropCurrentValue);
    }
示例#6
0
    public void NoIncomingParameterMatchesDeclaredParameter_LeavesValueUnchanged()
    {
        // Arrange
        var existingObjectValue = new object();
        var target = new HasInstanceProperties
        {
            IntProp                = 456,
            StringProp             = "Existing value",
            ObjectPropCurrentValue = existingObjectValue
        };

        var parameters = new ParameterViewBuilder().Build();

        // Act
        parameters.SetParameterProperties(target);

        // Assert
        Assert.Equal(456, target.IntProp);
        Assert.Equal("Existing value", target.StringProp);
        Assert.Same(existingObjectValue, target.ObjectPropCurrentValue);
    }