public async Task ArchiveThreadyByIdAsyncTest_WhenThreadIdDoesntExists_ThrowsInvalidRequestException() { 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(); threadMockRepository.Setup(x => x.GetAsync(threadEntity.Id)).ReturnsAsync((ThreadEntity)null); var threadManager = new ThreadManager(partnerMockRepository.Object, threadMockRepository.Object, messageMockRepository.Object, groupMockRepository.Object, mapper, contactMockRepository.Object, teamMockRepository.Object, logMockRepository.Object); var exception = await Assert.ThrowsAsync <InvalidRequestException>(() => threadManager.ArchiveThreadyByIdAsync(chatUserEntity.ChatUserId, threadEntity.Id, true)); Assert.IsType <InvalidRequestException>(exception); threadMockRepository.VerifyAll(); userMockRepository.VerifyAll(); messageMockRepository.VerifyAll(); groupMockRepository.VerifyAll(); partnerMockRepository.VerifyAll(); }
public async Task ArchiveThreadyByIdAsyncTest_WhenThreadIdExists_Returns() { 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(); threadMockRepository.Setup(x => x.GetAsync(threadEntity.Id)).ReturnsAsync(threadEntity); var threadManager = new ThreadManager(partnerMockRepository.Object, threadMockRepository.Object, messageMockRepository.Object, groupMockRepository.Object, mapper, contactMockRepository.Object, teamMockRepository.Object, logMockRepository.Object); await threadManager.ArchiveThreadyByIdAsync(chatUserEntity.ChatUserId, threadEntity.Id, true); threadMockRepository.Verify(x => x.UpdateAsync(threadEntity), Times.Once); threadMockRepository.VerifyAll(); userMockRepository.VerifyAll(); messageMockRepository.VerifyAll(); groupMockRepository.VerifyAll(); partnerMockRepository.VerifyAll(); }
public async Task SearchOrCreateThreadAsyncTest_WhenThreadTypeIsUserAndParticipantGuidExist_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 userId = _rnd.Next(111, 1000); var participantGuid = _rnd.Next(111, 1000); const ThreadType type = ThreadType.User; var mapper = GetMapperForThreadProfile(); var threadEntity = EntityModellers.CreateThreadEntity(); var chatUserEntity = EntityModellers.CreateChatUserEntity(); var messageEntity = EntityModellers.CreateMessageEntity(); var chatUserEntityList = new List <ChatUser> { chatUserEntity }; contactMockRepository.Setup(x => x.GetChatUserDetailAsync(participantGuid)).ReturnsAsync(chatUserEntity); contactMockRepository.Setup(x => x.GetChatUserDetailsAsync(threadEntity.Participants)).ReturnsAsync(chatUserEntityList); threadEntity.Participants.Add(participantGuid); threadMockRepository.Setup(x => x.SearchByParticipantIdsAsync(userId, participantGuid)).ReturnsAsync(threadEntity); messageMockRepository.Setup(x => x.GetByThreadIdAsync(threadEntity.Id)).ReturnsAsync(new List <MessageEntity> { messageEntity }); 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(); teamMockRepository.VerifyAll(); partnerMockRepository.VerifyAll(); }
public async Task GetThreadByUserIdTest_WhenUserIdExists_ReturnsUserThreadResponseModel() { var threadMockRepository = new Mock <IThreadRepository>(); var userMockRepository = new Mock <IUserRepository>(); var messageMockRepository = new Mock <IMessageRepository>(); var groupMockRepository = new Mock <IGroupRepository>(); var contactMockRepository = new Mock <IContactRepository>(); var partnerMockRepository = new Mock <IPartnerRepository>(); var logMockRepository = new Mock <ILogRepository>(); var teamMockRepository = new Mock <ITeamRepository>(); var mapper = GetMapperForThreadProfile(); var threadEntity = EntityModellers.CreateThreadEntity(); var userId = _rnd.Next(111, 1000); var groupId = Guid.NewGuid(); const int defaultLimit = -1; threadEntity.Participants.Add(userId); threadEntity.GroupId = groupId; var chatUserEntity = EntityModellers.CreateChatUserEntity(); chatUserEntity.ChatUserId = userId; var chatUserEntityList = new List <ChatUser> { chatUserEntity }; contactMockRepository.Setup(x => x.GetChatUserDetailsAsync(new List <int> { userId })).ReturnsAsync(chatUserEntityList); var participantDetails = mapper.Map <IEnumerable <IEnumerable <ChatUser> >, IEnumerable <IEnumerable <UserContactResponseModel> > >(new List <List <ChatUser> > { chatUserEntityList }); var expected = mapper.Map <IEnumerable <ThreadEntity>, IEnumerable <ThreadWithContactsResponseModel> >(new List <ThreadEntity> { threadEntity }).Zip(participantDetails, ZipContactsWithThread); threadMockRepository.Setup(x => x.SearchByParticipantIdAsync(userId)).ReturnsAsync(new List <ThreadEntity> { threadEntity }); var threadManager = new ThreadManager(partnerMockRepository.Object, threadMockRepository.Object, messageMockRepository.Object, groupMockRepository.Object, mapper, contactMockRepository.Object, teamMockRepository.Object, logMockRepository.Object); var actual = await threadManager.GetThreadsByUserId(userId, defaultLimit, FetchThreadType.All); Assert.Equal(expected.Count(), actual.Count()); threadMockRepository.VerifyAll(); userMockRepository.VerifyAll(); messageMockRepository.VerifyAll(); groupMockRepository.VerifyAll(); partnerMockRepository.VerifyAll(); teamMockRepository.VerifyAll(); }
public async Task GetThreadByIdTest_WhenThreadIdExists_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 lstUserEntity = new List <ChatUser> { chatUserEntity }; var messageEntity = EntityModellers.CreateMessageEntity(); var lstMessageEntity = new List <MessageEntity> { messageEntity }; threadMockRepository.Setup(x => x.GetAsync(threadEntity.Id)).ReturnsAsync(threadEntity); contactMockRepository.Setup(x => x.GetChatUserDetailsAsync(threadEntity.Participants)).ReturnsAsync(new List <ChatUser> { chatUserEntity }); messageMockRepository.Setup(x => x.GetByThreadIdAsync(threadEntity.Id)).ReturnsAsync(lstMessageEntity); var participantDetails = mapper.Map <IEnumerable <ChatUser>, IEnumerable <UserContactResponseModel> >(lstUserEntity); var messages = mapper.Map <IEnumerable <MessageEntity>, IEnumerable <MessageResponseModel> >(lstMessageEntity); var threads = mapper.Map <ThreadEntity, ThreadWithMessagesResponseModel>(threadEntity); var expected = mapper.Map(participantDetails, mapper.Map(messages, threads)); var threadManager = new ThreadManager(partnerMockRepository.Object, threadMockRepository.Object, messageMockRepository.Object, groupMockRepository.Object, mapper, contactMockRepository.Object, teamMockRepository.Object, logMockRepository.Object); var actual = await threadManager.GetThreadById(threadEntity.Id); Assert.Equal(expected, actual, new LogicEqualityComparer <ThreadWithMessagesResponseModel>()); threadMockRepository.VerifyAll(); userMockRepository.VerifyAll(); messageMockRepository.VerifyAll(); }
public async Task DeleteGroupByIdAsync_WhenGroupIdDoesntExists_ReturnsGroupResponseWithGroupRemoved() { var groupMockRepository = new Mock <IGroupRepository>(); var mockThreadRepository = new Mock <IThreadRepository>(); var contactMockRepository = new Mock <IContactRepository>(); var mapper = GetMapperForGroupProfile(); var groupEntity = EntityModellers.CreateGroupEntity(); var chatUserEntity = EntityModellers.CreateChatUserEntity(); var threadEntity = EntityModellers.CreateThreadEntity(); var expected = mapper.Map <GroupEntity, GroupResponseModel>(new GroupEntity()); groupMockRepository.Setup(x => x.DeleteAsync(groupEntity.Id)).ReturnsAsync(new GroupEntity()); var groupManager = new GroupManager(groupMockRepository.Object, mockThreadRepository.Object, mapper, contactMockRepository.Object); var actual = await groupManager.DeleteGroupByIdAsync(groupEntity.Id); Assert.Equal(expected, actual, new LogicEqualityComparer <GroupResponseModel>()); mockThreadRepository.Verify(x => x.DeleteByMultiIdAsync(groupEntity.Id), Times.Never); groupMockRepository.VerifyAll(); mockThreadRepository.VerifyAll(); }
public async Task GetThreadByUserIdTest_WhenUserIdDoesntExists_ReturnsEmptyThreadResponseModel() { 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(); const int defaultLimit = -1; var userId = _rnd.Next(111, 1000); var groupId = Guid.NewGuid(); threadEntity.GroupId = groupId; var expected = mapper.Map <IEnumerable <ThreadEntity>, IEnumerable <ThreadWithContactsResponseModel> >(new List <ThreadEntity>()); threadMockRepository.Setup(x => x.SearchByParticipantIdAsync(userId)).ReturnsAsync((IEnumerable <ThreadEntity>)null); var threadManager = new ThreadManager(partnerMockRepository.Object, threadMockRepository.Object, messageMockRepository.Object, groupMockRepository.Object, mapper, contactMockRepository.Object, teamMockRepository.Object, logMockRepository.Object); var actual = await threadManager.GetThreadsByUserId(userId, defaultLimit, FetchThreadType.UnArchived); Assert.Equal(expected, actual, new LogicEqualityComparer <IEnumerable <ThreadWithContactsResponseModel> >()); threadMockRepository.VerifyAll(); userMockRepository.VerifyAll(); messageMockRepository.VerifyAll(); groupMockRepository.VerifyAll(); partnerMockRepository.VerifyAll(); }
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(); }