public async Task TestGetDocumentById_DocumentDoesNotExist() { indexService.Setup(x => x.GetDocumentByIdAsync(It.IsAny <string>())).ReturnsAsync(null); var model = new ECASearchParametersBindingModel(); var response = await controller.GetDocumentByIdAsync(1, "key"); Assert.IsInstanceOfType(response, typeof(NotFoundResult)); }
public async Task TestGetDocumentById() { indexService.Setup(x => x.GetDocumentByIdAsync(It.IsAny <string>())).ReturnsAsync(new ECADocument()); var model = new ECASearchParametersBindingModel(); var response = await controller.GetDocumentByIdAsync(1, "key"); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <ECADocumentViewModel>)); }
public async Task TestPostSearchDocumentsAsync_InvalidModel() { controller.ModelState.AddModelError("key", "error"); var model = new ECASearchParametersBindingModel(); var response = await controller.PostSearchDocumentsAsync(1, model); Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult)); }
public async Task TestPostSearchDocumentsAsync() { userProvider.Setup(x => x.GetCurrentUser()).Returns(new DebugWebApiUser()); userProvider.Setup(x => x.GetPermissionsAsync(It.IsAny <IWebApiUser>())).ReturnsAsync(new List <IPermission>()); indexService.Setup(x => x.SearchAsync(It.IsAny <ECASearchParameters>(), It.IsAny <List <DocumentKey> >())).ReturnsAsync(new DocumentSearchResponse <ECADocument>()); var model = new ECASearchParametersBindingModel(); var response = await controller.PostSearchDocumentsAsync(1, model); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <DocumentSearchResponseViewModel>)); indexService.Verify(x => x.SearchAsync(It.IsAny <ECASearchParameters>(), It.IsAny <List <DocumentKey> >()), Times.Once()); userProvider.Verify(x => x.GetCurrentUser(), Times.Once()); userProvider.Verify(x => x.GetPermissionsAsync(It.IsAny <IWebApiUser>()), Times.Once()); }
public void Test() { var model = new ECASearchParametersBindingModel(); model.Facets = new List <string>(); model.SelectFields = new List <string>(); model.Filter = "filter"; model.Limit = 10; model.SearchTerm = "search"; model.Start = 1; model.HighlightPreTag = "pre"; model.HighlightPostTag = "post"; var permissions = new List <IPermission>(); var instance = model.ToECASearchParameters(permissions); Assert.AreEqual(model.Limit, instance.Limit); Assert.AreEqual(model.Start, instance.Start); Assert.AreEqual(model.Filter, instance.Filter); Assert.AreEqual(model.HighlightPreTag, instance.HighlightPreTag); Assert.AreEqual(model.HighlightPostTag, instance.HighlightPostTag); Assert.IsTrue(Object.ReferenceEquals(model.Facets, instance.Facets)); Assert.IsTrue(Object.ReferenceEquals(model.SelectFields, instance.SelectFields)); }
public async Task <IHttpActionResult> PostSearchDocumentsAsync([FromUri] int id, [FromBody] ECASearchParametersBindingModel search) { if (ModelState.IsValid) { var currentUser = this.userProvider.GetCurrentUser(); var permissions = await this.userProvider.GetPermissionsAsync(currentUser); var searchResults = await this.indexService.SearchAsync(search.ToECASearchParameters(permissions), null); return(Ok(new DocumentSearchResponseViewModel(searchResults))); } else { return(BadRequest(ModelState)); } }