public void SetPropertyValueNullPropertyNameShouldThrow()
        {
            // if property name is null the code should handle it and throw and not silently fail/do nothing
            SomeDemoObject obj = new SomeDemoObject();
            Action         act = () => obj.SetPropertyValue(null, "something");

            act.ShouldThrowExactly <ArgumentNullException>("Property name is null.");
        }
        public void SetPropertyValue()
        {
            // if invalid property name is given it should throw and not just silently skip the setting of the value
            // if silently just skipping the caller doesn't know that the value is not set
            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = 100,
                String  = "some text",
                Type    = "Demo"
            };

            obj.SetPropertyValue("Integer", 65);
            obj.SetPropertyValue("Type", "Test");

            obj.Integer.Should().Be(65);
            obj.Type.Should().Be("Test");
        }
        public void SetPropertyValueNotFoundPropertyNameShouldThrow()
        {
            // if invalid property name is given it should throw and not just silently skip the setting of the value
            // if silently just skipping the caller doesn't know that the value is not set
            SomeDemoObject obj = new SomeDemoObject();
            Action         act = () => obj.SetPropertyValue("NotFound", "something");

            act.ShouldThrowExactly <ArgumentException>("Invalid property name.");
        }
        public void SetPropertyValueNullInstanceShouldThrow()
        {
            // if instance is null and calling the extension method causes currently TargetInvocationException
            // our implementation should throw argumentnullexception or invalidoperationexception because called on null instead of instance
            SomeDemoObject obj = null;
            Action         act = () => obj.SetPropertyValue("Type", "Test");

            act.ShouldThrowExactly <ArgumentException>("Calling SetPropertyValue on null instance.");
        }
        public void SetPropertyValueIntUsingExpression()
        {
            int valueToSet = 6;

            SomeDemoObject obj = new SomeDemoObject();

            obj.SetPropertyValue(x => x.Integer, valueToSet);

            obj.Integer.Should().Be(valueToSet);
        }
        public void SetPropertyValueStringUsingExpression()
        {
            string valueToSet = "ptv";

            SomeDemoObject obj = new SomeDemoObject();

            obj.SetPropertyValue(x => x.String, valueToSet);

            obj.String.Should().Be(valueToSet);
        }
        public void SetPropertyValueUsingInvalidExpressionShouldThrow()
        {
            string valueToSet = "ptv";

            SomeDemoObject obj = new SomeDemoObject();

            // invalid "memberacces" expression
            System.Linq.Expressions.Expression <Func <SomeDemoObject, string> > f = (sdo) => sdo.ToString();

            Action act = () => obj.SetPropertyValue(f, valueToSet);

            // currently if invalid expression is given the value is not set which can lead to cases that intrdocude hard to find bugs to our app
            // if implementation is changed to throw, change the expected exception type
            act.ShouldThrow <Exception>("Maybe this should throw because the value is not set. Currently just silently does nothing because of invalid memberexpression.");
        }