Exemplo n.º 1
0
        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>());
        }
Exemplo n.º 2
0
        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();
        }