示例#1
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);
示例#2
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);
        }
示例#3
0
        public void IncomingParameterMatchesOverridenParameter_ThatDoesNotHasAttribute()
        {
            // 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 IncomingCascadingValueMatchesCascadingParameter_SetsValue()
        {
            // Arrange
            var builder = new ParameterViewBuilder();

            builder.Add(nameof(HasCascadingParameter.Cascading), "hi", cascading: true);
            var parameters = builder.Build();

            var target = new HasCascadingParameter();

            // Act
            parameters.SetParameterProperties(target);

            // Assert
            Assert.Equal("hi", target.Cascading);
        }
示例#5
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);
        }
示例#6
0
        public void NoIncomingCascadingValueMatchesDeclaredCascadingParameter_LeavesValueUnchanged()
        {
            // Arrange
            var builder    = new ParameterViewBuilder();
            var parameters = builder.Build();

            var target = new HasCascadingParameter()
            {
                Cascading = "bye",
            };

            // Act
            parameters.SetParameterProperties(target);

            // Assert
            Assert.Equal("bye", target.Cascading);
        }
示例#7
0
        public void IncomingCascadingValueMatchesNoDeclaredParameter_Throws()
        {
            // Arrange
            var builder = new ParameterViewBuilder();

            builder.Add("SomethingElse", "hi", cascading: true);
            var parameters = builder.Build();

            var target = new HasCascadingParameter();

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

            // Assert
            Assert.Equal(
                $"Object of type '{typeof(HasCascadingParameter).FullName}' does not have a property " +
                $"matching the name 'SomethingElse'.",
                ex.Message);
        }
        public void IncomingParameterMatchesNoDeclaredParameter_Throws()
        {
            // Arrange
            var target     = new HasPropertyWithoutParameterAttribute();
            var parameters = new ParameterViewBuilder
            {
                { "AnyOtherKey", 123 },
            }.Build();

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

            // Assert
            Assert.Equal(
                $"Object of type '{typeof(HasPropertyWithoutParameterAttribute).FullName}' does not have a property " +
                $"matching the name 'AnyOtherKey'.",
                ex.Message);
        }
示例#9
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);
        }
示例#10
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);
        }