Example #1
0
        /// <summary>
        /// Builds out this field template parsing out the required type declarations unions, nameing scheme etc.  This method should be
        /// overridden in any child classes for additional decalration requirements.
        /// </summary>
        protected override void ParseTemplateDefinition()
        {
            // ensure type extension right out of the gate
            // the field can't be built otherwise
            _typeAttrib = this.SingleAttributeOfTypeOrDefault <TypeExtensionAttribute>();
            if (_typeAttrib == null)
            {
                return;
            }

            _sourceType = _typeAttrib.TypeToExtend;

            base.ParseTemplateDefinition();

            var returnType = GraphValidation.EliminateWrappersFromCoreType(this.DeclaredReturnType);

            if (returnType != typeof(IGraphActionResult))
            {
                // inspect the return type, if its a valid dictionary extract the return type from the value
                // and set the type modifiers and method type based on the value of each dictionary entry
                if (_typeAttrib.ExecutionMode == FieldResolutionMode.Batch)
                {
                    returnType          = returnType.GetValueTypeOfDictionary();
                    this.ObjectType     = GraphValidation.EliminateWrappersFromCoreType(returnType);
                    this.TypeExpression = GraphValidation.GenerateTypeExpression(returnType, this);
                    this.PossibleTypes.Insert(0, this.ObjectType);
                }
            }
        }
Example #2
0
        public void TypeExtension_TypeConsturctor_PropertyCheck()
        {
            var attrib = new TypeExtensionAttribute(typeof(AttributeDataIntegrityTests), "myField");

            Assert.AreEqual("myField", attrib.Template);
            Assert.AreEqual(typeof(AttributeDataIntegrityTests), attrib.TypeToExtend);
            Assert.AreEqual(0, attrib.Types.Count);
        }
Example #3
0
        public void TypeExtension_ReturnConsturctor_PropertyCheck()
        {
            var attrib = new TypeExtensionAttribute(typeof(AttributeDataIntegrityTests), "myField", typeof(string));

            Assert.AreEqual("myField", attrib.Template);
            Assert.AreEqual(typeof(AttributeDataIntegrityTests), attrib.TypeToExtend);
            Assert.AreEqual(1, attrib.Types.Count);
            Assert.IsTrue(attrib.Types.Contains(typeof(string)));
        }
Example #4
0
        public void TypeExtension_UnionConstructor_PropertyCheck()
        {
            var attrib = new TypeExtensionAttribute(typeof(AttributeDataIntegrityTests), "myField", "myUnionType", typeof(GraphFieldAttribute), typeof(string));

            Assert.AreEqual(GraphCollection.Types, attrib.FieldType);
            Assert.AreEqual(typeof(AttributeDataIntegrityTests), attrib.TypeToExtend);
            Assert.AreEqual("myField", attrib.Template);
            Assert.AreEqual("myUnionType", attrib.UnionTypeName);
            Assert.AreEqual(2, attrib.Types.Count);
            Assert.AreEqual(typeof(GraphFieldAttribute), attrib.Types[0]);
            Assert.AreEqual(typeof(string), attrib.Types[1]);
            Assert.AreEqual(FieldResolutionMode.PerSourceItem, attrib.ExecutionMode);
        }