Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public void SetProperty_WhenTypeObjectIsNull_ReturnsTypeObjectUnchanged()
        {
            PropertyClass testClass = null;
            var           result    = testClass.SetProperty(a => a.Writable, It.IsAny <string>());

            Assert.AreEqual(testClass, result);
        }
Exemple #4
0
        public void SetProperty_WhenSettingPropertyWithNonPublicAccessModifiers_ChangesPropertyValue()
        {
            var value     = "test";
            var testClass = new PropertyClass();

            testClass.SetProperty(a => a.PrivateWritable, value);
            Assert.AreEqual(value, testClass.PrivateWritable);
        }
Exemple #5
0
        public void SetProperty_ChangesPropertyValue()
        {
            var value     = "test";
            var testClass = new PropertyClass();

            testClass.SetProperty(a => a.Writable, value);
            Assert.AreEqual(value, testClass.Writable);
        }
Exemple #6
0
        public void SetProperty_WhenPassingNullAsValueForNonNullableProperty_SetPropertyToDefaultValue()
        {
            var testClass = new PropertyClass()
            {
                NonNullableInt = 1
            };

            testClass.SetProperty(a => a.NonNullableInt, null);
            Assert.AreEqual(default(int), testClass.NonNullableInt);
        }
Exemple #7
0
        public void SetProperty_WhenLambdaFunctionIsNotAMemberExpression_ThrowsArgumentException()
        {
            var testClass = new PropertyClass();

            Assert.Catch <ArgumentException>(() => testClass.SetProperty(a => a.ToString(), It.IsAny <string>()));
        }