public async Task SendMessage_ShouldSendMessage()
        {
            //Arrange
            var handler             = new MessageQueryHandler();
            var messagesFromHandler = await handler.HandleAsync(new MessageQuery());

            var messagesFromHandlerCount = messagesFromHandler.ToList().Count;

            var firstGamblerFromDatabase = this.context.Gamblers.FirstOrDefault();
            var lastGamblerFromDatabase  = this.context.Gamblers.LastOrDefault();

            //Act - do something

            string body    = "Test body!";
            string subject = "Test subject!";

            SendMessageCommand command = new SendMessageCommand
            {
                Body          = body,
                Subject       = subject,
                Id            = Guid.NewGuid(),
                FromGamblerId = firstGamblerFromDatabase.Id, //sender id
                ToGamblerId   = lastGamblerFromDatabase.Id   // receiver id
            };

            //Assert - check results
            await this.sendMessageHandler.HandleAsync(command);

            var messagesFromDatabaseCount = this.context.Tickets.Count();

            Assert.AreNotEqual(messagesFromDatabaseCount, messagesFromHandlerCount);
        }
        public async Task MessagesCount_ShouldReturnMessageCount()
        {
            //Arrange
            var handler             = new MessageQueryHandler();
            var messagesFromHandler = await handler.HandleAsync(new MessageQuery());

            var messages = messagesFromHandler.ToList();

            //Act - do something
            var messagesFromHandlerCount = messagesFromHandler.ToList().Count;

            var messagesFromDatabaseCount = this.context.Messages.Count();

            //Assert - check results
            Assert.AreEqual(messagesFromHandlerCount, messagesFromDatabaseCount);
        }
        public async Task <IActionResult> Messages(string message, string error)
        {
            ViewData[StaticConstants.Message] = message;
            ViewData[StaticConstants.Error]   = error;

            var handler = new MessageQueryHandler();

            var messagesFromHandler = await handler.HandleAsync(new MessageQuery());

            //get all gamblers
            IEnumerable <Gambler> gamblersList = await new GamblerQueryHandler().HandleAsync(new GamblerQuery());

            var messages = messagesFromHandler.ToList();

            foreach (Message m in messages)
            {
                m.ToGambler = gamblersList.ToList().FirstOrDefault(g => g.Id == m.ToGamblerId);
            }


            IEnumerable <Gambler> gamblers = await new GamblerQueryHandler().HandleAsync(new GamblerQuery());

            return(View(model: messages));
        }