public void GetEdmType_Returns_TypeFromTypeNameIfNotNull()
        {
            SelectExpandWrapper<int> wrapper = new SelectExpandWrapper<int> { TypeName = _model.Customer.FullName(), ModelID = _modelID };

            IEdmTypeReference result = wrapper.GetEdmType();

            Assert.Same(_model.Customer, result.Definition);
        }
        public void GetEdmType_ThrowsODataException_IfTypeFromTypeNameIsNotFoundInModel()
        {
            _modelID = ModelContainer.GetModelID(EdmCoreModel.Instance);
            SelectExpandWrapper<int> wrapper = new SelectExpandWrapper<int> { TypeName = _model.Customer.FullName(), ModelID = _modelID };

            Assert.Throws<InvalidOperationException>(
                () => wrapper.GetEdmType(),
                "Cannot find the entity type 'NS.Customer' in the model.");
        }
        public void GetEdmType_Returns_ElementTypeIfInstanceIsNull()
        {
            _model.Model.SetAnnotationValue(_model.Customer, new ClrTypeAnnotation(typeof(TestEntity)));
            _model.Model.SetAnnotationValue(_model.SpecialCustomer, new ClrTypeAnnotation(typeof(DerivedEntity)));
            SelectExpandWrapper<TestEntity> wrapper = new SelectExpandWrapper<TestEntity> { ModelID = _modelID };

            IEdmTypeReference edmType = wrapper.GetEdmType();

            Assert.Same(_model.Customer, edmType.Definition);
        }
示例#4
0
        public void GetEdmType_Returns_ElementTypeIfInstanceIsNull()
        {
            _model.Model.SetAnnotationValue(_model.Customer, new ClrTypeAnnotation(typeof(TestEntity)));
            _model.Model.SetAnnotationValue(_model.SpecialCustomer, new ClrTypeAnnotation(typeof(DerivedEntity)));
            SelectExpandWrapper <TestEntity> wrapper = new SelectExpandWrapper <TestEntity> {
                Model = _model.Model
            };

            IEdmTypeReference edmType = wrapper.GetEdmType();

            Assert.Same(_model.Customer, edmType.Definition);
        }
        /// <summary>
        /// Gets the EdmType from the Instance which may be a select expand wrapper.
        /// </summary>
        /// <param name="value">Instance for which the edmType needs to be computed.</param>
        /// <param name="model">IEdmModel</param>
        /// <returns>The EdmType of the underlying instance.</returns>
        private static IEdmType GetTypeFromObject(object value, IEdmModel model)
        {
            SelectExpandWrapper selectExpand = value as SelectExpandWrapper;

            if (selectExpand != null)
            {
                IEdmTypeReference typeReference = selectExpand.GetEdmType();
                return(typeReference.Definition);
            }

            Type clrType = value.GetType();

            return(model.GetTypeMappingCache().GetEdmType(clrType, model)?.Definition);
        }
示例#6
0
        /// <summary>
        /// Gets the EdmType from the Instance which may be a select expand wrapper.
        /// </summary>
        /// <param name="value">Instance for which the edmType needs to be computed.</param>
        /// <param name="model">IEdmModel</param>
        /// <returns>The EdmType of the underlying instance.</returns>
        private static IEdmType GetTypeFromObject(object value, IEdmModel model)
        {
            SelectExpandWrapper selectExpand = value as SelectExpandWrapper;

            if (selectExpand != null)
            {
                IEdmTypeReference typeReference = selectExpand.GetEdmType();
                return(typeReference.Definition);
            }

            Type clrType = value.GetType();

            return(EdmLibHelpers.GetEdmType(model, clrType));
        }