Пример #1
0
        public async Task PostNewMessagesCallsTheRepositoryInsertMethod(
            Mock<IUsernameProvider> usernameProvider,
            Mock<IRepository<ChatMessageDataModel>> messageRepository,
            string hubId,
            string channelId,
            string username,
            NewMessageModel newMessage,
            ChatMessageDataModel createdMessage)
        {
            AutoMapper.Mapper.CreateMap<ChatMessage, ChatMessageDataModel>();

            usernameProvider.Setup(p => p.GetUsername()).Returns(Task.FromResult(username));
            messageRepository.Setup(r => r.Insert(It.IsAny<ChatMessageDataModel>())).Returns(Task.FromResult(createdMessage));

            var controllerUnderTest = new MessagesController(usernameProvider.Object, messageRepository.Object);

            await controllerUnderTest.PostNewMessage(hubId, channelId, newMessage);

            var expectedMessageParameter = new ChatMessage(username, channelId, newMessage.Message, DateTime.Now);
            
            messageRepository.Verify(mock => mock.Insert(It.Is<ChatMessageDataModel>(parameter =>
                parameter.ChannelId == channelId && 
                parameter.Message == newMessage.Message &&
                parameter.Username == username
            )), Times.Once());
        }