public void TrySetProperty_WhenClassDoesNotHaveProperty_ReturnsUnchangedObject() { var testClass = new PropertyClass(); var result = testClass.TrySetProperty("Random", It.IsAny <string>()); Assert.AreEqual(testClass, result); }
public void TrySetProperty_WhenValueTypeDoesNotMatchProperty_ThrowsInvalidOperationException() { var testClass = new PropertyClass(); var exception = Assert.Catch <InvalidOperationException>(() => testClass.TrySetProperty(nameof(PropertyClass.Writable), 0)); Assert.AreEqual("Property type is not assignable from the Value type.", exception.Message); }
public void TrySetProperty_WhenClassObjectIsNull_ReturnsUnchangedObject() { PropertyClass testClass = null; var result = testClass.TrySetProperty(nameof(PropertyClass.Writable), It.IsAny <string>()); Assert.AreEqual(testClass, result); }
public void TrySetProperty_WhenTryingToSetAReadonlyProperty_ThrowsInvalidOperationException() { var testClass = new PropertyClass(); var exception = Assert.Catch <InvalidOperationException>(() => testClass.TrySetProperty(nameof(PropertyClass.Readonly), It.IsAny <string>())); Assert.AreEqual("Cannot set a restricted property.", exception.Message); }
public void TrySetProperty_WhenSettingPropertyWithNonPublicAccessModifiers_ChangesPropertyValue() { var value = "test"; var testClass = new PropertyClass(); testClass.TrySetProperty(nameof(PropertyClass.PrivateWritable), value); Assert.AreEqual(value, testClass.PrivateWritable); }
public void TrySetProperty_ChangesPropertyValue() { var value = "test"; var testClass = new PropertyClass(); testClass.TrySetProperty(nameof(PropertyClass.Writable), value); Assert.AreEqual(value, testClass.Writable); }
public void TrySetProperty_WhenPassingNullAsValueForNonNullableProperty_SetPropertyToDefaultValue() { var testClass = new PropertyClass() { NonNullableInt = 1 }; testClass.TrySetProperty(nameof(PropertyClass.NonNullableInt), null); Assert.AreEqual(default(int), testClass.NonNullableInt); }
public void TrySetProperty_WhenSettingANonNullableProperty_DoesNotThrowException() { var testClass = new PropertyClass(); Assert.DoesNotThrow(() => testClass.TrySetProperty(nameof(PropertyClass.DateTime2), DateTime.UtcNow)); }