public async Task TestPostSuggestionsAsync()
        {
            indexService.Setup(x => x.GetSuggestionsAsync(It.IsAny <ECASuggestionParameters>(), It.IsAny <List <DocumentKey> >())).ReturnsAsync(new DocumentSuggestResponse <ECADocument>());
            var model    = new ECASuggestionParametersBindingModel();
            var response = await controller.PostSuggestionsAsync(1, model);

            Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <DocumentSuggestResponseViewModel>));
            indexService.Verify(x => x.GetSuggestionsAsync(It.IsAny <ECASuggestionParameters>(), It.IsAny <List <DocumentKey> >()), Times.Once());
        }
        public async Task TestPostSuggestionsAsync_InvalidModel()
        {
            controller.ModelState.AddModelError("key", "error");
            indexService.Setup(x => x.GetSuggestionsAsync(It.IsAny <ECASuggestionParameters>(), It.IsAny <List <DocumentKey> >())).ReturnsAsync(new DocumentSuggestResponse <ECADocument>());
            var model    = new ECASuggestionParametersBindingModel();
            var response = await controller.PostSuggestionsAsync(1, model);

            Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult));
        }
        public void TestToECASuggestionsParameters()
        {
            var model = new ECASuggestionParametersBindingModel();

            model.HighlightPostTag = "post";
            model.HighlightPreTag  = "pre";
            model.SearchTerm       = "search";
            var instance = model.ToECASuggestionParameters(new List <IPermission>());

            Assert.AreEqual(model.HighlightPreTag, instance.HighlightPreTag);
            Assert.AreEqual(model.HighlightPostTag, instance.HighlightPostTag);
            Assert.AreEqual(model.SearchTerm, instance.SearchTerm);
        }
Пример #4
0
        public async Task <IHttpActionResult> PostSuggestionsAsync([FromUri] int id, [FromBody] ECASuggestionParametersBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var searchResults = await this.indexService.GetSuggestionsAsync(model.ToECASuggestionParameters(null), null);

                return(Ok(new DocumentSuggestResponseViewModel(searchResults)));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }