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

            Assert.AreEqual(testClass, result);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        public void SetProperty_ChangesPropertyValue()
        {
            var value     = "test";
            var testClass = new PropertyClass();

            testClass.SetProperty(a => a.Writable, value);
            Assert.AreEqual(value, testClass.Writable);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
        public void SetProperty_WhenLambdaFunctionIsNotAMemberExpression_ThrowsArgumentException()
        {
            var testClass = new PropertyClass();

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