public void AddInfoMessage_Success() { // Arrange // Act var msgId = message.Add(TestInfoMessage, (long)Constants.MessageType.Info); // Assert Assert.IsType <long>(msgId); Assert.True(msgId > 0); }
private async Task <IHttpActionResult> Add(Models.DTOs.Message.Add message, long messageTypeId) { if (!ModelState.IsValid) { return(base.ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState))); } var task1 = Task.Run(() => _message.Add(message, messageTypeId)); try{ await Task.WhenAll(task1); }catch (ArgumentNullException) { return(BadRequest(Events.MissingParameter.ToString())); }catch (NullReferenceException) { return(BadRequest(Events.MissingObject.ToString())); }catch (AggregateException ae) { var ex = ae.Flatten().InnerException; if (ex is ArgumentNullException) { return(BadRequest(Events.MissingParameter.ToString())); } _logger.Error(String.Format("Error adding log message [{0}]", Events.AddError), ex); return(StatusCode(HttpStatusCode.InternalServerError)); } if (task1.Status != TaskStatus.RanToCompletion) { _logger.Error(String.Format("Add log message task did not complete [{0}]", Events.AddError), task1.Exception); return(StatusCode(HttpStatusCode.InternalServerError)); } return(StatusCode(HttpStatusCode.Created)); }
public async Task GetMessage_Success() { // Arrange var msgId = message.Add(TestInfoMessage, (long)Constants.MessageType.Info); // Act var msg = await message.Get(msgId); // Assert Assert.NotNull(msg); Assert.IsType <Models.DTOs.Message.Get>(msg); Assert.Equal(msg.Text, TestInfoMessage.Text); Assert.Equal(msg.Id, msgId); Assert.IsType <Models.DTOs.MessageType.Get>(msg.MessageType); Assert.Equal(msg.MessageType.Id, (long)Constants.MessageType.Info); Assert.Equal(msg.MessageType.Name, Enum.GetName(typeof(Constants.MessageType), (long)Constants.MessageType.Info)); }
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()); }