Пример #1
0
        public void verify_validation_execution_for_derived_types()
        {
            // just assure that no exception is thrown during validation related to types casting and cached funcs
            var firstDerived  = new FirstDerived();
            var secondDerived = new SecondDerived();

            var firstContext  = new ValidationContext(firstDerived);
            var secondContext = new ValidationContext(secondDerived);

            // initialize annotated property value with null, for deep go-through of RequiredIf logic
            firstDerived.Value1  = null;
            secondDerived.Value1 = null;
            // put into cache different funcs...
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
            // ...and use already cached ones accordingly
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);

            // initialize annotated property value with non-null, for deep go-through of AssertThat logic
            firstDerived.Value1  = new object();
            secondDerived.Value1 = new object();
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
        }
Пример #2
0
        public void no_errors_during_derived_types_validation()
        {
            var firstDerived  = new FirstDerived();
            var secondDerived = new SecondDerived();
            var firstContext  = new ValidationContext(firstDerived);
            var secondContext = new ValidationContext(secondDerived);

            // initialize annotated property value with null, for deep go-through of RequiredIf logic
            firstDerived.Value1  = null;
            secondDerived.Value1 = null;
            // put into cache different funcs...
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
            // ...and use already cached ones accordingly
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);

            // initialize annotated property value with non-null, for deep go-through of AssertThat logic
            firstDerived.Value1  = new object();
            secondDerived.Value1 = new object();
            // put into cache different funcs...
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
            // ...and use already cached ones accordingly
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
        }
Пример #3
0
        static void Main(string[] args)
        {
            ////object initial
            Program objP = new Program();

            //array input
            objP.take_input();
            //array_list
            Student objS = new Student();

            ///inheritence
            objS.set_info();
            objS.print_info();

            ///Polymorphism
            Base objBase;

            objBase = new Base();
            objBase.Show();//    Output ----> Show From Base Class.

            objBase = new Derived();
            objBase.Show();//Output--> Show From Derived Class.

            objBase = new SecondDerived();
            objBase.Show();//Output---> Show From Second Derived Class.
        }
        public void no_errors_during_derived_types_validation()
        {
            var firstDerived = new FirstDerived();
            var secondDerived = new SecondDerived();
            var firstContext = new ValidationContext(firstDerived);
            var secondContext = new ValidationContext(secondDerived);

            // initialize annotated property value with null, for deep go-through of RequiredIf logic
            firstDerived.Value1 = null;
            secondDerived.Value1 = null;
            // put into cache different funcs...
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
            // ...and use already cached ones accordingly
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);

            // initialize annotated property value with non-null, for deep go-through of AssertThat logic
            firstDerived.Value1 = new object();
            secondDerived.Value1 = new object();
            // put into cache different funcs...
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
            // ...and use already cached ones accordingly
            Validator.TryValidateObject(firstDerived, firstContext, null, true);
            Validator.TryValidateObject(secondDerived, secondContext, null, true);
        }
Пример #5
0
    static void Main()                                // Main
    {
        SecondDerived derived = new SecondDerived();  // Use SecondDerived.
        MyBaseClass   mybc    = (MyBaseClass)derived; // Use MyBaseClass.

        derived.Print();
        mybc.Print();
    }
Пример #6
0
    static void Main()
    {
        SecondDerived derived = new SecondDerived();
        BaseClass     mybc    = (BaseClass)derived;

        derived.Print();
        mybc.Print();
    }
    static void Main()
    {
        SecondDerived derived = new SecondDerived();
        // we have cast SecondDerived to the type BaseClass.
        //This is perfectly legal code (as we saw in the Polymorphism example).
        BaseClass mybc = (BaseClass)derived; //upcast

        derived.Print();
        mybc.Print();
    }
        public void verify_logic_with_derived_context()
        {
            var parser = new Parser();
            var firstDerived = new FirstDerived {Value = true};
            var secondDerived = new SecondDerived {Value = true};

            Assert.IsTrue(parser.Parse(firstDerived.GetType(), "Value").Invoke(firstDerived));
            Assert.IsTrue(parser.Parse(secondDerived.GetType(), "Value").Invoke(secondDerived));

            Assert.IsTrue(parser.Parse(typeof(ModelBase), "Value").Invoke(firstDerived));
            Assert.IsTrue(parser.Parse(typeof(ModelBase), "Value").Invoke(secondDerived));
        }