Ejemplo n.º 1
0
        public async Task TheWriteResponseBodyAsyncMethodShouldReturnStatusCode400IfFieldsMalformed()
        {
            // Arrange
            Mock.Get(this.httpResponse)
            .SetupGet(httpResponse => httpResponse.StatusCode)
            .Returns(200);

            Mock.Get(this.fieldsParser)
            .Setup(fieldsParser => fieldsParser.Parse(this.httpRequest))
            .Returns(FieldsParserResult.Failed());

            this.mvcPartialJsonOptions.IgnoreParseErrors = false;
            this.mvcPartialJsonOptions.IgnoreCase        = false;

            var writeContext = this.CreateWriteContext(new { });

            // Act
            await this.formatter.WriteResponseBodyAsync(writeContext, Encoding.UTF8);

            // Assert
            Mock.Get(this.httpResponse)
            .VerifySet(httpResponse => httpResponse.StatusCode = 400);

            Assert.Equal(0, this.body.Length);
        }
Ejemplo n.º 2
0
        public virtual Query <TEntity> Parse(HttpRequest request, ActionDescriptor action, bool isCollectionCall)
        {
            var query = new Query <TEntity>
                        (
                _fieldsParser.Parse <TEntity>(request, isCollectionCall),
                _orderByParser.Parse <TEntity>(request),
                _pagingParser.Parse(request),
                _filterParser.Parse(request, action, _webFilterConverter),
                GetVerb(request)
                        )
            {
                TypeFilter = _typeFilterParser.Parse(request)
            };

            if (query.Fields.Contains((ISelection c) => c.Count))
            {
                query.Options.NeedsCount       = true;
                query.Options.NeedsEnumeration = query.Fields.Children.Count != 1;
            }

            if (query.Verb == HttpVerbs.Get)
            {
                query.Options.NeedsDataTracking = false;
            }

            return(query);
        }
Ejemplo n.º 3
0
        public async Task TheExecuteAsyncMethodShouldReturnStatusCode400IfFieldsMalformed()
        {
            // Arrange
            Mock.Get(this.fieldsParser)
            .Setup(fieldsParser => fieldsParser.Parse(this.httpRequest))
            .Returns(FieldsParserResult.Failed());

            var partialJsonResult = new PartialJsonResult(new { });

            // Act
            await this.executor.ExecuteAsync(this.actionContext, partialJsonResult);

            // Assert
            Mock.Get(this.httpResponse)
            .VerifySet(httpResponse => httpResponse.StatusCode = 400);

            Assert.Equal(0, this.body.Length);
        }