public async Task BadRequest_WithModelDictionary_RendersMessageOnResponse()
        {
            var server         = new TestServerBuilder().Build();
            var methodTemplate = TemplateHelper.CreateFieldTemplate <ActionableController>(nameof(ActionableController.DoStuff));
            var argTemplate    = methodTemplate.Arguments[0];
            var fieldArg       = new GraphArgumentMaker(server.Schema).CreateArgument(argTemplate).Argument;

            // name is marked required, will fail
            var dataItem = new ActionableModelItem()
            {
                Name = null,
                Id   = "5",
            };

            var arg = new ExecutionArgument(fieldArg, dataItem);
            var col = new ExecutionArgumentCollection();

            col.Add(arg);

            var generator       = new ModelStateGenerator();
            var modelDictionary = generator.CreateStateDictionary(col);

            var actionResult = new BadRequestGraphActionResult(modelDictionary);

            var context = this.CreateResolutionContext();
            await actionResult.Complete(context);

            Assert.IsNull(context.Result);
            Assert.IsTrue(context.Messages.Any(x => x.Code == Constants.ErrorCodes.BAD_REQUEST));
            Assert.IsTrue(context.Messages.Any(x => x.Code == Constants.ErrorCodes.MODEL_VALIDATION_ERROR));
        }
Beispiel #2
0
        private ExecutionArgumentCollection CreateArgumentCollection(string key, object value)
        {
            var argSet = new ExecutionArgumentCollection();

            var mockFieldArg = new Mock <IGraphFieldArgument>();

            mockFieldArg.Setup(x => x.ParameterName).Returns(key);

            argSet.Add(new ExecutionArgument(mockFieldArg.Object, value));
            return(argSet);
        }
        /// <summary>
        /// Merges the supplied variable data into a new collection of arguments
        /// capable of fulfilling a request. Any deferred arguments in this instance are resolved
        /// to the data contained in the provided set or null if not found.
        /// </summary>
        /// <param name="variableData">The variable data.</param>
        /// <returns>IInputArgumentCollection.</returns>
        public IExecutionArgumentCollection Merge(IResolvedVariableCollection variableData)
        {
            var collection = new ExecutionArgumentCollection();

            foreach (var arg in _arguments.Values)
            {
                var resolvedValue = arg.Value.Resolve(variableData);
                collection.Add(new ExecutionArgument(arg.Argument, resolvedValue));
            }

            return(collection);
        }