public async Task GetChatLogAsyncTest_WhenUserId_ReturnsChatLogs() { var mockLogRepository = new Mock <ILogRepository>(); var mockContactRepository = new Mock <IContactRepository>(); var mockLogManager = new Mock <ILogManager>(); var mapper = new Mock <IMapper>(); var chatUser = EntityModellers.CreateChatUserEntity(); var chatUserList = new List <ChatUser> { chatUser }; var userId = _rnd.Next(111, 1000); var partnerId = _rnd.Next(111, 1000); var senderId = _rnd.Next(111, 1000); var teamId = _rnd.Next(111, 1000); var log = EntityModellers.GetLogEntity(); var logs = new List <LogEntity> { log }; var chatResponse = EntityModellers.GetChatLogResponse(); var expected = new List <ChatLogResponse> { chatResponse }; mockContactRepository.Setup(x => x.GetChatUserAsync(userId, partnerId)).ReturnsAsync(chatUser); mockLogRepository.Setup(x => x.GetByuserIdAsync(chatUser.ChatUserId)).ReturnsAsync(logs); mapper.Setup(x => x.Map <IEnumerable <LogEntity>, IEnumerable <ChatLogResponse> >(logs)).Returns(expected); var logManager = new LogManager(mockContactRepository.Object, mockLogRepository.Object, mapper.Object); var actual = await logManager.ChatLogAsync(userId, partnerId); Assert.Equal(expected, actual, new LogicEqualityComparer <ChatLogResponse>()); mockLogRepository.VerifyAll(); }
public async Task FetchByIdAsyncTest_WhenGroupIdExists_ReturnsGroupWithUsersResponseModel() { 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 chatUserEntityList = new List <ChatUser> { chatUserEntity }; groupMockRepository.Setup(x => x.GetAsync(groupEntity.Id)).ReturnsAsync(groupEntity); contactMockRepository.Setup(x => x.GetChatUserDetailsAsync(groupEntity.Members)).ReturnsAsync(chatUserEntityList); var userResponse = mapper.Map <IEnumerable <ChatUser>, IEnumerable <UserContactResponseModel> >(chatUserEntityList); var groupResponse = mapper.Map <GroupEntity, GroupWithUsersResponseModel>(groupEntity); var expected = mapper.Map(userResponse, groupResponse); var groupManager = new GroupManager(groupMockRepository.Object, mockThreadRepository.Object, mapper, contactMockRepository.Object); var actual = await groupManager.FetchByIdAsync(groupEntity.Id); Assert.Equal(expected, actual, new LogicEqualityComparer <GroupWithUsersResponseModel>()); Assert.NotNull(actual); groupMockRepository.VerifyAll(); }
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 GetUserChatConfigurationAsyncTest() { var mockPartnerRepository = new Mock <IPartnerRepository>(); var mockContactRepository = new Mock <IContactRepository>(); var userId = _rnd.Next(111, 1000); var user = EntityModellers.CreateUserEntity(userId); var partner = EntityModellers.CreatePartnerEntity(); var chatUser = EntityModellers.CreateChatUserEntity(); var userRights = EntityModellers.GetUserRights(); var userRightsFor = new[] { "SendBroadcast" }; mockPartnerRepository.Setup(x => x.GetUser(userId)).Returns(user); mockPartnerRepository.Setup(x => x.GetPartnerDetail()).Returns(partner); mockContactRepository.Setup(x => x.GetChatUserAsync(user.Id, partner.PartnerId)).ReturnsAsync(chatUser); mockPartnerRepository.Setup(x => x.GetPermissions(userId, userRights)).Returns(userRightsFor); var userConfiguration = new UserConfigurationDto { LoggedUserDetail = new LoggedUserDetailDto { UserId = user.Id, ChatUserId = chatUser.ChatUserId, UserName = $"{user.FirstName} {user.LastName}", UserRole = user.UserRole, IsEnableChat = user.IsEnableChat, IsBroadcastEnable = userRightsFor.Contains("SendBroadcast"), IsAdmin = user.ProfileCode.Equals("ADMIN"), IsHighImportanceEnable = user.IsHighImportanceEnable, IsChatAllTeams = userRightsFor.Contains("ChatAllTeams"), IsEmployeeMessageLogViewAll = userRightsFor.Contains(""), IsAppointmentArrivalMessage = userRightsFor.Contains(""), IsSendEmpMessage = userRightsFor.Contains(""), UserStatus = chatUser.Status ?? UserStatus.Available.ToString() }, Partner = partner }; var expected = userConfiguration; var chatServiceManager = new UserConfigurationManager(mockPartnerRepository.Object, mockContactRepository.Object); var actual = await chatServiceManager.GetUserChatConfigurationAsync(userId); Assert.Equal(expected, actual, new LogicEqualityComparer <UserConfigurationDto>()); }
public async Task UpdateUserStatusAsyncTest_WhenUserIdDoesntExistsAndStatusIsAvailable_ReturnsUserResponseModelWithUpdatedStatus() { var mockUserRepository = new Mock <IUserRepository>(); var mockThreadRepository = new Mock <IThreadRepository>(); var mapper = new Mock <IMapper>(); var chatUserEntity = EntityModellers.CreateChatUserEntity(); var status = UserStatus.Available; var userId = _rnd.Next(111, 1000); mockUserRepository.Setup(x => x.UpdateChatStatusAsync(userId, status.ToString())).ReturnsAsync(false); var expected = false; //Action var userManager = new UserManager(mockUserRepository.Object, mockThreadRepository.Object, mapper.Object); var actual = await userManager.UpdateUserStatusAsync(userId, status); //Assert Assert.Equal(expected, actual); mockUserRepository.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 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 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 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(); }