예제 #1
0
            public async Task InvalidRequestBody_ReturnNull()
            {
                var skillRequest = new SkillRequest
                {
                    Session = new Session(),
                    Context = new Context(),
                    Request = new IntentRequest {
                        Intent = new Intent {
                            Name = "Test"
                        }
                    }
                };
                var routeData = new RouteData("TestController", "TestAction");

                _skillRequestParser.Setup(x => x.ParseHttpRequestAsync(_httpRequest.Object)).Throws <JsonException>();
                _routeDataService.Setup(x => x.TryGetRoute(skillRequest.Request, out routeData)).Returns(true);
                _httpRequest.Setup(x => x.Path).Returns("/");
                _httpRequest.Setup(x => x.Method).Returns("POST");
                _httpRequest.Setup(x => x.ContentType).Returns("application/json");
                _httpContext.Setup(x => x.Request).Returns(_httpRequest.Object);
                _httpContext.Setup(x => x.Items).Returns(new Dictionary <object, object>());

                var routeValueTransformer =
                    new SkillionRouteValueTransformer(_skillRequestParser.Object, _routeDataService.Object);
                var routeValueDictionary = new RouteValueDictionary();
                var values = await routeValueTransformer.TransformAsync(_httpContext.Object, routeValueDictionary);

                Assert.Null(values);
            }
예제 #2
0
            public async Task RouteExists_ReturnRouteValueDictionary()
            {
                var skillRequest = new SkillRequest
                {
                    Session = new Session(),
                    Context = new Context(),
                    Request = new IntentRequest {
                        Intent = new Intent {
                            Name = "Test"
                        }
                    }
                };
                var routeData = new RouteData("TestController", "TestAction");

                _skillRequestParser.Setup(x => x.ParseHttpRequestAsync(_httpRequest.Object))
                .ReturnsAsync(skillRequest);
                _routeDataService.Setup(x => x.TryGetRoute(skillRequest.Request, out routeData)).Returns(true);
                _httpRequest.Setup(x => x.Path).Returns("/");
                _httpRequest.Setup(x => x.Method).Returns("POST");
                _httpRequest.Setup(x => x.ContentType).Returns("application/json");
                _httpContext.Setup(x => x.Request).Returns(_httpRequest.Object);
                _httpContext.Setup(x => x.Items).Returns(new Dictionary <object, object>());

                var routeValueTransformer =
                    new SkillionRouteValueTransformer(_skillRequestParser.Object, _routeDataService.Object);
                var routeValueDictionary = new RouteValueDictionary();
                var values = await routeValueTransformer.TransformAsync(_httpContext.Object, routeValueDictionary);

                Assert.True(values["controller"].Equals(routeData.Controller));
                Assert.True(values["action"].Equals(routeData.Action));
            }