public void SetProperty_WhenTryingToSetAReadonlyProperty_ThrowsInvalidOperationException() { var testClass = new PropertyClass(); var exception = Assert.Catch <InvalidOperationException>(() => testClass.SetProperty(a => a.Readonly, It.IsAny <string>())); Assert.AreEqual("Cannot set a restricted property.", exception.Message); }
public void SetProperty_WhenPassingThroughAValueOfDifferentType_ThrowsInvalidOperationException() { var testClass = new PropertyClass(); var exception = Assert.Catch <InvalidOperationException>(() => testClass.SetProperty(a => a.Writable, 3)); Assert.AreEqual("Value type does not match the Property type.", exception.Message); }
public void SetProperty_WhenTypeObjectIsNull_ReturnsTypeObjectUnchanged() { PropertyClass testClass = null; var result = testClass.SetProperty(a => a.Writable, It.IsAny <string>()); Assert.AreEqual(testClass, result); }
public void SetProperty_WhenSettingPropertyWithNonPublicAccessModifiers_ChangesPropertyValue() { var value = "test"; var testClass = new PropertyClass(); testClass.SetProperty(a => a.PrivateWritable, value); Assert.AreEqual(value, testClass.PrivateWritable); }
public void SetProperty_ChangesPropertyValue() { var value = "test"; var testClass = new PropertyClass(); testClass.SetProperty(a => a.Writable, value); Assert.AreEqual(value, testClass.Writable); }
public void SetProperty_WhenPassingNullAsValueForNonNullableProperty_SetPropertyToDefaultValue() { var testClass = new PropertyClass() { NonNullableInt = 1 }; testClass.SetProperty(a => a.NonNullableInt, null); Assert.AreEqual(default(int), testClass.NonNullableInt); }
public void SetProperty_WhenLambdaFunctionIsNotAMemberExpression_ThrowsArgumentException() { var testClass = new PropertyClass(); Assert.Catch <ArgumentException>(() => testClass.SetProperty(a => a.ToString(), It.IsAny <string>())); }