예제 #1
0
        protected override void OnCompleteType(
            ICompletionContext context,
            TDefinition definition)
        {
            base.OnCompleteType(context, definition);

            _syntaxNode = definition.SyntaxNode;

            var directives = new DirectiveCollection(this, definition.Directives);

            directives.CompleteCollection(context);
            _directives = directives;
        }
예제 #2
0
        internal void CompleteValue(ITypeCompletionContext context)
        {
            var directives = new DirectiveCollection(
                this, _definition.Directives);

            directives.CompleteCollection(context);
            Directives = directives;

            OnCompleteValue(context, _definition);

            _contextData = new Dictionary <string, object>(
                _definition.ContextData);
            _definition = null;
        }
예제 #3
0
        protected virtual void OnCompleteField(
            ICompletionContext context,
            TDefinition definition)
        {
            DeclaringType = context.Type;
            Type          = context.GetType <TType>(_definition.Type);
            ClrType       = Type is IHasClrType hasClrType
                ? hasClrType.ClrType
                : typeof(object);

            var directives = new DirectiveCollection(
                this, _definition.Directives);

            directives.CompleteCollection(context);
            Directives = directives;
        }
예제 #4
0
        internal void CompleteField(ICompletionContext context)
        {
            DeclaringType = context.Type;
            Type          = context.GetType <TType>(_definition.Type);
            ClrType       = Type.NamedType() is IHasClrType hasClrType
                ? hasClrType.ClrType
                : typeof(object);

            var directives = new DirectiveCollection(
                this, _definition.Directives);

            directives.CompleteCollection(context);
            Directives = directives;

            OnCompleteField(context, _definition);
            _definition = null;
        }
예제 #5
0
        public void DirectiveNotRepeatable()
        {
            // act
            var someType = new ObjectType(t => t.Name("Foo"));
            var directiveDescriptions = new List <DirectiveDescription>
            {
                new DirectiveDescription(new DirectiveNode("foo")),
                new DirectiveDescription(new DirectiveNode("foo"))
            };

            var foo = new DirectiveType(d =>
                                        d.Name("foo").Location(DirectiveLocation.Field));

            var errors = new List <SchemaError>();

            var context = new Mock <ITypeInitializationContext>();

            context.Setup(
                t => t.GetDirectiveType(It.IsAny <DirectiveReference>()))
            .Returns(new Func <DirectiveReference, DirectiveType>(
                         r => foo));
            context.Setup(t => t.ReportError(It.IsAny <SchemaError>()))
            .Callback(new Action <SchemaError>(errors.Add));

            // act
            var collection = new DirectiveCollection(
                someType, DirectiveLocation.Field,
                directiveDescriptions);

            ((INeedsInitialization)collection)
            .RegisterDependencies(context.Object);
            ((INeedsInitialization)collection)
            .CompleteType(context.Object);

            // assert
            Assert.Collection(errors,
                              t => Assert.Equal(
                                  "The specified directive `@foo` " +
                                  "is unique and cannot be added twice.",
                                  t.Message));
        }