Beispiel #1
0
        public void Should_Bind_All_Properties_with_Default_Values()
        {
            //Create a new instance of our test class
            var testInstance = new DefaultValueTestClass();

            //Match all of the properties of the test instance...
            _matcher.Match(testInstance);

            //Test to see that proper values have been assigned to the DateTime properties
            Assert.AreNotEqual(testInstance.DateTime1, default(DateTime));
            Assert.AreNotEqual(testInstance.DateTime2, default(DateTime));

            //Test to see that the proper values have been assigned to the float properties
            Assert.AreNotEqual(testInstance.TestFloat, default(float));
            Assert.AreNotEqual(testInstance.TestFloat2, default(float));

            //Test to see that proper values have been assigned to the integer properties
            Assert.AreNotEqual(testInstance.TestInt, default(int));

            //Test to see that proper values have been assigned to the long properties
            Assert.AreNotEqual(testInstance.TestLong, default(long));

            //Test to see that proper values have been assigned to the Guid properties
            Assert.AreNotEqual(testInstance.TestGuid, default(Guid));

            //Test to see that proper values have been assigned ot the string properties
            Assert.IsNotNullOrEmpty(testInstance.RandomString);
        }
Beispiel #2
0
    static void Main()
    {
        Application.EnableVisualStyles();
        using (var form = new Form())
            using (var grid = new PropertyGrid())
            {
                grid.Dock = DockStyle.Fill;
                var obj = new DefaultValueTestClass
                {   // TODO - try with other numbers to
                    // see bold / not bold
                    Foo = 10000
                };
                // note in the grid the value is shown not-bold; that is
                // because System.ComponentModel is saying
                // "this property doesn't need to be serialized"
                // - or to show it more explicitly:
                var  prop            = TypeDescriptor.GetProperties(obj)["Foo"];
                bool shouldSerialize = prop.ShouldSerializeValue(obj);
                // ^^^ false, because of the DefaultValueAttribute
                form.Text = shouldSerialize.ToString(); // win title

                grid.SelectedObject = obj;
                form.Controls.Add(grid);
                Application.Run(form);
            }
    }
        public void Should_Bind_All_Properties_with_Default_Values()
        {
            //Create a new instance of our test class
            var testInstance = new DefaultValueTestClass();

            //Match all of the properties of the test instance...
            _matcher.Match(testInstance);

            //Test to see that proper values have been assigned to the DateTime properties
            Assert.AreNotEqual(testInstance.DateTime1, default(DateTime));
            Assert.AreNotEqual(testInstance.DateTime2, default(DateTime));

            //Test to see that the proper values have been assigned to the float properties
            Assert.AreNotEqual(testInstance.TestFloat, default(float));
            Assert.AreNotEqual(testInstance.TestFloat2, default(float));

            //Test to see that proper values have been assigned to the integer properties
            Assert.AreNotEqual(testInstance.TestInt, default(int));

            //Test to see that proper values have been assigned to the long properties
            Assert.AreNotEqual(testInstance.TestLong, default(long));

            //Test to see that proper values have been assigned to the Guid properties
            Assert.AreNotEqual(testInstance.TestGuid, default(Guid));

            //Test to see that proper values have been assigned ot the string properties
            Assert.IsNotNullOrEmpty(testInstance.RandomString);
        }
Beispiel #4
0
        public void Should_Skip_Types_Without_Selectors()
        {
            //Create a new TypTable that doesn't use any of the default types
            var typeTable = new TypeTable(false);

            //Add just the Float and DateTime selectors
            typeTable.AddSelector(new FloatSelector());
            typeTable.AddSelector(new DateTimeSelector());

            //Create a new matcher that users only the type selectors we've specified
            var typlessMatcher = new Matcher(typeTable);

            //Create a new instance of our test class
            var testInstance = new DefaultValueTestClass();

            //Match the properties for which we have selectors
            typlessMatcher.Match(testInstance);

            /* ASSERT THAT THE PROPERTIES FOR WHICH WE HAVE INJECTORS ARE ALL SET */

            //Test to see that proper values have been assigned to the DateTime properties
            Assert.AreNotEqual(testInstance.DateTime1, default(DateTime));
            Assert.AreNotEqual(testInstance.DateTime2, default(DateTime));

            //Test to see that the proper values have been assigned to the float properties
            Assert.AreNotEqual(testInstance.TestFloat, default(float));
            Assert.AreNotEqual(testInstance.TestFloat, float.PositiveInfinity);
            Assert.AreNotEqual(testInstance.TestFloat, float.NegativeInfinity);
            Assert.AreNotEqual(testInstance.TestFloat2, default(float));
            Assert.AreNotEqual(testInstance.TestFloat2, float.PositiveInfinity);
            Assert.AreNotEqual(testInstance.TestFloat2, float.NegativeInfinity);

            /* ASSERT THAT THE PROPERTIES THAT DON'T HAVE ANY SELECTORS ARE NOT SET */

            Assert.AreEqual(testInstance.TestInt, default(int));
            Assert.AreEqual(testInstance.TestLong, default(long));
            Assert.AreEqual(testInstance.TestGuid, default(Guid));
            Assert.IsNullOrEmpty(testInstance.RandomString);
        }
        public void Should_Skip_Types_Without_Selectors()
        {
            //Create a new TypTable that doesn't use any of the default types
            var typeTable = new TypeTable(false);

            //Add just the Float and DateTime selectors
            typeTable.AddSelector(new FloatSelector());
            typeTable.AddSelector(new DateTimeSelector());

            //Create a new matcher that users only the type selectors we've specified
            var typlessMatcher = new Matcher(typeTable);

            //Create a new instance of our test class
            var testInstance = new DefaultValueTestClass();

            //Match the properties for which we have selectors
            typlessMatcher.Match(testInstance);

            /* ASSERT THAT THE PROPERTIES FOR WHICH WE HAVE INJECTORS ARE ALL SET */

            //Test to see that proper values have been assigned to the DateTime properties
            Assert.AreNotEqual(testInstance.DateTime1, default(DateTime));
            Assert.AreNotEqual(testInstance.DateTime2, default(DateTime));

            //Test to see that the proper values have been assigned to the float properties
            Assert.AreNotEqual(testInstance.TestFloat, default(float));
            Assert.AreNotEqual(testInstance.TestFloat, float.PositiveInfinity);
            Assert.AreNotEqual(testInstance.TestFloat, float.NegativeInfinity);
            Assert.AreNotEqual(testInstance.TestFloat2, default(float));
            Assert.AreNotEqual(testInstance.TestFloat2, float.PositiveInfinity);
            Assert.AreNotEqual(testInstance.TestFloat2, float.NegativeInfinity);

            /* ASSERT THAT THE PROPERTIES THAT DON'T HAVE ANY SELECTORS ARE NOT SET */

            Assert.AreEqual(testInstance.TestInt, default(int));
            Assert.AreEqual(testInstance.TestLong, default(long));
            Assert.AreEqual(testInstance.TestGuid, default(Guid));
            Assert.IsNullOrEmpty(testInstance.RandomString);
        }