Exemplo n.º 1
0
        public void GetPropertyValueTyped()
        {
            int    number   = 7;
            string txt      = "vrk ptv";
            string typeText = "Test";

            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = number,
                String  = txt,
                Type    = typeText
            };

            obj.SomeList.Add("ptv");
            obj.SomeList.Add("vrk");

            obj.GetPropertyValue <SomeDemoObject, int>("Integer").Should().Be(number);
            obj.GetPropertyValue <SomeDemoObject, string>("String").Should().Be(txt);
            obj.GetPropertyValue <SomeDemoObject, string>("Type").Should().Be(typeText);

            IList <string> theList = obj.GetPropertyValue <SomeDemoObject, IList <string> >("SomeList");

            theList.Should().NotBeNullOrEmpty();
            theList.Count.Should().Be(2);
        }
Exemplo n.º 2
0
        public void GetPropertyValueTypedPropertyNameIsNullShouldThrow()
        {
            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = 8,
                String  = "vrk ptv",
                Type    = "Demo"
            };

            obj.SomeList.Add("ptv");
            obj.SomeList.Add("vrk");

            // extension should throw an ArgumentNullException
            Action act = () => obj.GetPropertyValue <SomeDemoObject, int>(null);

            act.ShouldThrowExactly <ArgumentNullException>("Property name is null.");
        }
Exemplo n.º 3
0
        public void GetPropertyValueObjectPropertyMissingShouldThrow()
        {
            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = 8,
                String  = "vrk ptv",
                Type    = "Demo"
            };

            obj.SomeList.Add("ptv");
            obj.SomeList.Add("vrk");

            // extension should throw an argumenexception when a property is not found
            // why? because otherwise the caller doesn't know that the property is missing from the object
            Action act = () => obj.GetPropertyValue <SomeDemoObject, int>("NotFoundPropertyName");

            act.ShouldThrowExactly <ArgumentException>("Property not found from object.");
        }
Exemplo n.º 4
0
        public void GetPropertyValueTypedInvalidPropertyNameShouldThrow(string propertyName)
        {
            SomeDemoObject obj = new SomeDemoObject()
            {
                Integer = 8,
                String  = "vrk ptv",
                Type    = "Demo"
            };

            obj.SomeList.Add("ptv");
            obj.SomeList.Add("vrk");

            // extension should throw an argumenexception when a known invalid propertyname is passed or a property is not found
            // why? because otherwise the caller doesn't know that the property is missing from the object
            Action act = () => obj.GetPropertyValue <SomeDemoObject, int>(propertyName);

            act.ShouldThrowExactly <ArgumentException>("Known invalid property name.");
        }