コード例 #1
0
        public void should_perform_real_copy_operation_for_value_type()
        {
            var original = new ValueTypeDemoClass();

            ValueTypeDemoClass copy = original;
            bool isSameReference;

            // use unsafe keyword permit use pointer and perform c++-style pointer operations
            unsafe
            {
                // & returns a pointer to the address of variable
                // * returns the variable at the address of a pointer
                // -> ponit-to-member operator, x->y is equivalent to(*x).y
                ValueTypeDemoClass *originalPtr = &original;
                ValueTypeDemoClass *copyPtr     = ©

                // originalPtr -> original
                // copyPtr -> copy
                isSameReference = originalPtr == copyPtr;
            }

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

            Assert.Equal(expectedIsSameReference, isSameReference);
        }
コード例 #2
0
        public void should_be_sealed_for_value_type()
        {
            var customValueTypeObject = new ValueTypeDemoClass();

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

            Assert.Equal(isValueTypeSealed, customValueTypeObject.GetType().IsSealed);
        }
コード例 #3
0
        public void should_be_sealed_for_value_type()
        {
            var customValueTypeObject = new ValueTypeDemoClass();

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

            Assert.Equal(isValueTypeSealed, customValueTypeObject.GetType().IsSealed);
        }
コード例 #4
0
        public void should_be_sealed_for_value_type()
        {
            // sealed keyword to prevent it from being overridden by further subclasses
            // value type are sealed
            var customValueTypeObject = new ValueTypeDemoClass();

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

            Assert.Equal(isValueTypeSealed, customValueTypeObject.GetType().IsSealed);
        }
コード例 #5
0
        public void should_perform_real_copy_operation_for_value_type()
        {
            var original = new ValueTypeDemoClass();

            ValueTypeDemoClass copy = original;
            bool isSameReference;

            unsafe
            {
                ValueTypeDemoClass *originalPtr = &original;
                ValueTypeDemoClass *copyPtr     = ©

                isSameReference = originalPtr == copyPtr;
            }

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

            Assert.Equal(expectedIsSameReference, isSameReference);
        }
コード例 #6
0
        public void should_derived_from_value_type_for_value_type()
        {
            int      intObject             = 1;
            DateTime dateTimeObject        = DateTime.Now;
            var      customValueTypeObject = new ValueTypeDemoClass();

            // change the variable values for the following 3 lines to fix the test.
            const bool isIntObjectValueType             = false;
            const bool isDateTimeObjectValueType        = false;
            const bool isCustomValueTypeObjectValueType = false;

            Assert.Equal(
                isIntObjectValueType,
                intObject.GetType().IsSubclassOf(typeof(ValueType)));
            Assert.Equal(
                isDateTimeObjectValueType,
                dateTimeObject.GetType().IsSubclassOf(typeof(ValueType)));
            Assert.Equal(
                isCustomValueTypeObjectValueType,
                customValueTypeObject.GetType().IsSubclassOf(typeof(ValueType)));
        }
コード例 #7
0
        public void should_derived_from_value_type_for_value_type()
        {
            int intObject = 1;
            DateTime dateTimeObject = DateTime.Now;
            var customValueTypeObject = new ValueTypeDemoClass();

            // change the variable values for the following 3 lines to fix the test.
            const bool isIntObjectValueType = false;
            const bool isDateTimeObjectValueType = false;
            const bool isCustomValueTypeObjectValueType = false;

            Assert.Equal(
                isIntObjectValueType,
                intObject.GetType().IsSubclassOf(typeof(ValueType)));
            Assert.Equal(
                isDateTimeObjectValueType,
                dateTimeObject.GetType().IsSubclassOf(typeof(ValueType)));
            Assert.Equal(
                isCustomValueTypeObjectValueType,
                customValueTypeObject.GetType().IsSubclassOf(typeof(ValueType)));
        }
コード例 #8
0
        public void should_perform_real_copy_operation_for_value_type()
        {
            var original = new ValueTypeDemoClass();

            ValueTypeDemoClass copy = original;
            bool isSameReference;

            unsafe
            {
                ValueTypeDemoClass* originalPtr = &original;
                ValueTypeDemoClass* copyPtr = ©

                isSameReference = originalPtr == copyPtr;
            }

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

            Assert.Equal(expectedIsSameReference, isSameReference);
        }