Ejemplo n.º 1
0
        public void should_access_member_of_most_derived_class()
        {
            var demoClass = new PolymorphismDemoClass();
            var castToBaseClass = (PolymorphismDemoClassBase) demoClass;

            string actualValue = castToBaseClass.VirtualMethod();

            // please change the variable value to fix the test.
            const string expected = "";

            Assert.Equal(expected, actualValue);
        }
Ejemplo n.º 2
0
        public void should_throw_exception_if_it_is_not_castable()
        {
            var demoClass = new PolymorphismDemoClass();
            object castToObject = demoClass;

            // please change the variable value to fix the test.
            Type expectedExceptionType = typeof(ArgumentException);

            Assert.NotEqual(typeof(SystemException), expectedExceptionType);
            Assert.NotEqual(typeof(Exception), expectedExceptionType);

            Assert.Throws(expectedExceptionType, () => (StringBuilder) castToObject);
        }
Ejemplo n.º 3
0
        public void should_return_casted_result_if_it_is_castable()
        {
            var demoClass = new PolymorphismDemoClass();
            var castToBaseClass = demoClass as PolymorphismDemoClassBase;

            bool isNull = castToBaseClass == null;

            // please change the variable value to fix the test.
            const bool expected = true;

            Assert.Equal(expected, isNull);
        }
Ejemplo n.º 4
0
        public void should_return_null_if_it_is_not_castable()
        {
            var demoClass = new PolymorphismDemoClass();
            object castToObject = demoClass;

            var castResult = castToObject as StringBuilder;
            bool isNull = castResult == null;

            // please change the variable value to fix the test.
            const bool expected = false;

            Assert.Equal(expected, isNull);
        }
Ejemplo n.º 5
0
        public void should_reference_to_same_object_after_casting()
        {
            var demoClass = new PolymorphismDemoClass();
            var castToBaseClass = (PolymorphismDemoClassBase)demoClass;

            bool referenceEqual = ReferenceEquals(demoClass, castToBaseClass);

            // please change the variable value to fix the test.
            const bool expected = false;

            Assert.Equal(expected, referenceEqual);
        }