public void AddMessageWithChannelTest()
        {
            string message = "Test 123";
            var    author  = new EntityDummyCreator().Create();
            var    channel = new ShoutboxChannelDummyCreator().SetName("Test Channel").Create();


            shoutBoxService.SendMessage(message, author, channel);

            shoutboxMessageRepository.Verify(x => x.SaveChanges(), Times.Once());
            shoutboxMessageRepository.Verify(x => x.Add(It.Is <ShoutboxMessage>(msg =>
                                                                                msg.Message == message &&
                                                                                msg.AuthorID == author.EntityID &&
                                                                                msg.ChannelID == channel.ID
                                                                                )));
        }
        public JsonResult WriteMessage(int channelID, int?parentID, string content)
        {
            try
            {
                var channel = shoutboxChannelRepository.GetById(channelID);
                var author  = SessionHelper.CurrentEntity;

                MethodResult result = shoutBoxService.CanSendMessage(content, channel, author);
                if (result.IsError)
                {
                    return(JsonError(result));
                }

                ShoutboxMessage message = null;

                if (parentID.HasValue)
                {
                    var parent = shoutboxMessageRepository.GetById(parentID.Value);
                    if (parent == null)
                    {
                        return(JsonError("Error"));
                    }

                    message = shoutBoxService.SendMessage(content, author, parent);
                }
                else
                {
                    message = shoutBoxService.SendMessage(content, author, channel);
                }

                return(JsonData(new ShoutboxMessageViewModel(message)));
            }
            catch (UserReadableException e)
            {
                return(JsonError(e));
            }
            catch (Exception)
            {
                return(JsonError("Unspecified error ocurred"));

                throw;
            }
        }