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); }
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);
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); }
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); }
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); }
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); }
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); }