private void Verify(Parent[] parms,EnumInvokeVersion invokeVersion)
 {
     Utility util = new Utility();
     foreach (Parent parm in parms)
     {
         parm.Method1(util);
         Assert.AreEqual(invokeVersion,util.InvokeVersion);
         util.InvokeVersion = EnumInvokeVersion.UNDEFINED;
     }
 }
 public void TestRealParent()
 {
     Parent[] realParents = new Parent[] { new Parent(), new Parent() };
     Verify(realParents,EnumInvokeVersion.PARENT_CALLED);
 }
 public void TestParentRefChild()
 {
     Parent[] realParents = new Parent[] { new Child(), new Child() };
     Verify(realParents, EnumInvokeVersion.CHILD_CALLED);
 }
 public void Function1(Parent obj)
 {
     m_invokeVersion = EnumInvokeVersion.PARENT_CALLED;
 }
        public void TestVirtualOverride()
        {
            #region [parent version called]
            Utility parm1 = new Utility();
            Assert.AreEqual(EnumInvokeVersion.UNDEFINED, parm1.InvokeVersion);

            Parent parentObj = new Parent();
            parentObj.Method1(parm1);
            Assert.AreEqual(EnumInvokeVersion.PARENT_CALLED, parm1.InvokeVersion);
            #endregion

            #region [child version called]
            Utility parm2 = new Utility();

            Child childObj = new Child();
            childObj.Method1(parm2);
            Assert.AreEqual(EnumInvokeVersion.CHILD_CALLED, parm2.InvokeVersion);
            #endregion
        }
        public void TestFailedCast()
        {
            var parent = new Parent();
            Assert.IsNull(parent as Child);

            // below codes will throw exception
            Assert.Throws<InvalidCastException>(() => { var failed = (Child) parent; });
        }
        public void TestAssignableInNUnit()
        {
            Parent parentObj = new Parent();
            Child childObj = new Child();

            Assert.IsInstanceOf<Parent>(parentObj);
            Assert.IsNotInstanceOf<Child>(parentObj);
            Assert.IsAssignableFrom<Parent>(parentObj);
            Assert.IsAssignableFrom<Child>(parentObj);

            Assert.IsInstanceOf<Child>(childObj);
            Assert.IsInstanceOf<Parent>(childObj);
            Assert.IsAssignableFrom<Child>(childObj);
            Assert.IsNotAssignableFrom<Parent>(childObj);
        }