public async void GetTeamMembersAsyncTest_WhenTeamIdExists_ReturnsTeamMemberDto() { var mockPartnerRepository = new Mock <IPartnerRepository>(); var mockContactRepository = new Mock <IContactRepository>(); var mockTeamRepository = new Mock <ITeamRepository>(); var mapper = GetMapperForTeamProfile(); var teamId = _rnd.Next(111, 1000); var userIdList = new List <int> { teamId }; var partner = EntityModellers.CreatePartnerEntity(); var chatUser = EntityModellers.CreateChatUserEntity(); var team = EntityModellers.CreateTeamEntity(); var teamEntityList = new List <TeamEntity> { team }; var chatUserList = new List <ChatUser> { chatUser }; mockPartnerRepository.Setup(x => x.GetTeamMembers(teamId)).Returns(userIdList); mockPartnerRepository.Setup(x => x.GetPartnerDetail()).Returns(partner); mockContactRepository.Setup(x => x.GetChatUsersAsync(userIdList, partner.PartnerId)).ReturnsAsync(chatUserList); mockTeamRepository.Setup(x => x.GetAllAsync()).ReturnsAsync(teamEntityList); var expected = mapper.Map <ICollection <ChatUser>, ICollection <TeamMemberDto> >(chatUserList); var teamManager = new TeamManager(mockTeamRepository.Object, mockPartnerRepository.Object, mockContactRepository.Object, mapper); var actual = await teamManager.GetTeamMembersAsync(teamId); Assert.Equal(expected, actual, new LogicEqualityComparer <TeamMemberDto>()); mockPartnerRepository.VerifyAll(); mockContactRepository.VerifyAll(); }
public async Task SearchOrCreateThreadAsyncTest_WhenThreadTypeIsTeamAndParticipantGuidExist_ThreadWithMessagesResponseModel() { 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 messageEntity = EntityModellers.CreateMessageEntity(); var groupEntity = EntityModellers.CreateGroupEntity(); var teamEntity = EntityModellers.CreateTeamEntity(); var userId = _rnd.Next(111, 1000); var participantGuid = Guid.NewGuid(); const ThreadType type = ThreadType.Team; var teamMembers = new List <int> { teamEntity.TeamId }; var chatUsers = new List <ChatUser> { chatUserEntity }; teamEntity.Id = participantGuid; groupEntity.Id = participantGuid; threadEntity.Participants = new List <int> { userId }; teamMockRepository.Setup(x => x.GetAsync(teamEntity.Id)).ReturnsAsync(teamEntity); partnerMockRepository.Setup(x => x.GetTeamMembers(teamEntity.TeamId)).Returns(teamMembers); threadMockRepository.Setup(x => x.GetAsync(participantGuid)).ReturnsAsync(threadEntity); messageMockRepository.Setup(x => x.GetByThreadIdAsync(threadEntity.Id)).ReturnsAsync(new List <MessageEntity> { messageEntity }); contactMockRepository.Setup(x => x.GetChatUserDetailsFromUserIdsAsync(teamMembers)).ReturnsAsync(chatUsers); contactMockRepository.Setup(x => x.GetChatUserDetailsAsync(It.Is <IEnumerable <int> >(l => new CompareLogic().Compare(l, threadEntity.Participants).AreEqual))) .ReturnsAsync(chatUsers); var participantResponse = mapper.Map <IEnumerable <ChatUser>, IEnumerable <UserContactResponseModel> >(new List <ChatUser> { chatUserEntity }); var messagesResponse = mapper.Map <IEnumerable <MessageEntity>, IEnumerable <MessageResponseModel> >(new List <MessageEntity> { messageEntity }); 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.SearchOrCreateThreadAsync(userId, participantGuid.ToString(), type); Assert.Equal(expected, actual, new LogicEqualityComparer <ThreadWithMessagesResponseModel>()); threadMockRepository.VerifyAll(); userMockRepository.VerifyAll(); messageMockRepository.VerifyAll(); groupMockRepository.VerifyAll(); }