public async Task AddNewMessageAsyncTest_WhenUserThreadIdExists_ReturnsThreadWithMessagesResponseModel() { var threadMockRepository = new Mock <IThreadRepository>(); var userMockRepository = new Mock <IUserRepository>(); var messageMockRepository = new Mock <IMessageRepository>(); var groupMockRepository = new Mock <IGroupRepository>(); var partnerMockRepository = new Mock <IPartnerRepository>(); var contactMockRepository = new Mock <IContactRepository>(); var logMockRepository = new Mock <ILogRepository>(); var teamMockRepository = new Mock <ITeamRepository>(); var mapper = GetMapperForThreadProfile(); var threadEntity = EntityModellers.CreateThreadEntity(); var chatUserEntity = EntityModellers.CreateChatUserEntity(); var newMessageRequestModel = EntityModellers.CreateNewMessageRequestModel(); var tempMessageEntity = new MessageEntity { Id = Guid.NewGuid(), ThreadId = threadEntity.Id, Content = newMessageRequestModel.Content, FromUserId = newMessageRequestModel.FromUserId, FromUserName = newMessageRequestModel.FromUserName, CreatedAt = DateTime.UtcNow }; var tempMessages = new List <MessageEntity> { tempMessageEntity, new MessageEntity { Id = Guid.NewGuid(), ThreadId = threadEntity.Id, Content = "content", FromUserId = newMessageRequestModel.FromUserId, FromUserName = newMessageRequestModel.FromUserName, CreatedAt = DateTime.UtcNow } }; var lstUserEntity = new List <ChatUser> { chatUserEntity }; threadMockRepository.Setup(x => x.GetAsync(newMessageRequestModel.ThreadId)).ReturnsAsync(threadEntity); messageMockRepository.Setup(x => x.AddAndGetAsync(It.IsAny <MessageEntity>())).ReturnsAsync(tempMessages); contactMockRepository.Setup(x => x.GetChatUserDetailsAsync(threadEntity.Participants)).ReturnsAsync(lstUserEntity); var messagesResponse = mapper.Map <IEnumerable <MessageEntity>, IEnumerable <MessageResponseModel> >(tempMessages); var participantResponse = mapper.Map <IEnumerable <ChatUser>, IEnumerable <UserContactResponseModel> >(lstUserEntity); var threadResponse = mapper.Map <ThreadEntity, ThreadWithMessagesResponseModel>(threadEntity); var threadWithMessages = mapper.Map(messagesResponse, threadResponse); var expected = mapper.Map(participantResponse, threadWithMessages); var threadManager = new ThreadManager(partnerMockRepository.Object, threadMockRepository.Object, messageMockRepository.Object, groupMockRepository.Object, mapper, contactMockRepository.Object, teamMockRepository.Object, logMockRepository.Object); var actual = await threadManager.AddNewMessageAsync(newMessageRequestModel); expected.ModifiedAt = actual.ModifiedAt; Assert.Equal(expected, actual, new LogicEqualityComparer <ThreadWithMessagesResponseModel>()); threadMockRepository.VerifyAll(); userMockRepository.VerifyAll(); messageMockRepository.VerifyAll(); groupMockRepository.VerifyAll(); partnerMockRepository.VerifyAll(); teamMockRepository.VerifyAll(); }