public async Task <IHttpActionResult> Search([FromBody] Models.DTOs.Message.Search search) { if (!ModelState.IsValid) { return(base.ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState))); } var task1 = Task.Run(() => _message.Search(search)); try{ await Task.WhenAll(task1); }catch (ArgumentNullException) { return(BadRequest(Events.MissingParameter.ToString())); }catch (ArgumentOutOfRangeException) { return(BadRequest(Events.MissingObject.ToString())); }catch (AggregateException ae) { var ex = ae.Flatten().InnerException; _logger.Error(String.Format("Error searching log messages [{0}]", Events.GetError), ex); return(StatusCode(HttpStatusCode.InternalServerError)); } if (task1.Status != TaskStatus.RanToCompletion) { _logger.Error(String.Format("Search log messages task did not complet [{0}]", Events.SearchError), task1.Exception); return(StatusCode(HttpStatusCode.InternalServerError)); } return(Ok(task1.Result)); }
public void SearchMessageByType_Success() { // Arrange message.Add(TestInfoMessage, (long)Constants.MessageType.Info); message.Add(TestInfoMessage, (long)Constants.MessageType.Info); message.Add(TestInfoMessage, (long)Constants.MessageType.Info); message.Add(TestErrorMessage, (long)Constants.MessageType.Error); message.Add(TestErrorMessage, (long)Constants.MessageType.Error); // Act Models.DTOs.Message.Search search = new Models.DTOs.Message.Search(null, (long)Constants.MessageType.Info); var result = message.Search(search); // Assert Assert.NotNull(result); Assert.IsAssignableFrom <IEnumerable <Models.DTOs.Message.Get> >(result); Assert.Equal(3, result.Count()); }