Esempio n. 1
0
        private static void ChildClassTypeVerifyTest()
        {
            BaseClass childA = new DerivedClassA();
            BaseClass childB = new DerivedClassB();

            if (childA is DerivedClassB)
            {
                Console.WriteLine("childA is DerivedClassB");
            }
            else
            {
                Console.WriteLine(@"childA is DerivedClassA");
            }

            if (childB is DerivedClassB)
            {
                Console.WriteLine("childB is DerivedClassB");
            }
            else
            {
                Console.WriteLine(@"childB is DerivedClassA");
            }

            if (childB is BaseClass)
            {
                Console.WriteLine("childB is derived from BaseClass");
            }
            else
            {
                Console.WriteLine(@"Where childB comes from?");
            }
        }
        public void SpecificationAbstract_OnObject_WithSpecification_IsValid()
        {
            ValidationCatalog.AddSpecification <BaseClassSpecification>();
            ValidationCatalog.AddSpecification <DerivedClassASpecification>();
            ValidationCatalog.AddSpecification <DerivedClassBSpecification>();
            ValidationCatalog.AddSpecification <ClassWithAbstractPropertySpecification>();

            var t = new DerivedClassA();
            var a = new ClassWithAbstractProperty {
                BaseClassProperty = t
            };

            //collection
            a.BaseClassCollectionProperty = new List <BaseClass>();
            //a.BaseClassCollectionProperty.Add(new DerivedClassA());
            a.BaseClassCollectionProperty.Add(new DerivedClassB()
            {
                BaseName = "Valid"
            });


            var n = ValidationCatalog.Validate(a);

            Assert.That(n.IsValid, Is.False);
            Assert.That(n.All().Count(), Is.EqualTo(3));
        }
        public void SpecificationInheritance_OnObject_WithSpecification_IsValid()
        {
            ValidationCatalog.AddSpecification <BaseClassSpecification>();
            ValidationCatalog.AddSpecification <DerivedClassASpecification>();

            var a = new DerivedClassA();
            var n = ValidationCatalog.Validate(a);

            Assert.That(n.IsValid, Is.False);
            Assert.That(n.All().Count(), Is.EqualTo(2));
        }
Esempio n. 4
0
    private static void VerifyModifiers()
    {
        DerivedClassA class_a = new DerivedClassA();
        DerivedClassB class_b = new DerivedClassB();
        BaseClass     base_a  = class_a;
        BaseClass     base_b  = class_b;

        Debug.Assert(class_a.GetCode() == "CODE-2", "class_a.GetCode() should return CODE-2");
        Debug.Assert(class_b.GetCode() == "CODE-3", "class_b.GetCode() should return CODE-3");
        Debug.Assert(base_a.GetCode() == "CODE-1", "base_a.GetCode() should return CODE-1");
        Debug.Assert(base_b.GetCode() == "CODE-1", "base_b.GetCode() should return CODE-1");

        Debug.Assert(class_a.GetDescription() == "CLASS-A", "class_a.GetDescription() sould return CLASS-A");
        Debug.Assert(class_b.GetDescription() == "B", "class_b.GetDescription() should return B");
        Debug.Assert(base_a.GetDescription() == "CLASS-A", "base_1.GetDescription() should return CLASS-A");
        Debug.Assert(base_b.GetDescription() == "B", "base_b.GetDescription() should return B");
    }
    public static void Main()
    {
        /*
         *      If base class referrence is pointing to dirived class object with virtual and override keywork then
         *      derived class method will be invoked then it is called method overriding.
         */
        BaseClass b = new DerivedClassA();

        b.Print();

        /*
         *      If base class referrence is pointing to dirived class object with virtual (Optional) and new keywork then
         *      base class method will be invoked then it is called method hidding.
         */
        BaseClass b1 = new DerivedClassB();

        b1.Print();
    }