Пример #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);
    }