public void GetListClientUsers_GivenUserAsAdmin_ReturnListWithThreeClientUsers()
        {
            // Arrange
            int processed       = 0;
            var userId          = "810";
            var isAdmin         = true;
            var economicGroupId = 1;

            var listClientUserSpected = ClientUserServiceData.GetListClientUserWithThreeElements();

            clientUserRepository.GetClientsByUserIdAsync(economicGroupId: Arg.Any <int>()).Returns(listClientUserSpected);
            clientUserRepository.When(fx => fx.GetClientsByUserIdAsync(economicGroupId: Arg.Any <int>())).Do(fx => ++ processed);

            // Act
            var clientUserSpectedTask = clientUserService.GetClientsByUserIdAsync(userId, isAdmin, economicGroupId);

            clientUserSpectedTask.Wait();

            // Assert
            Assert.IsTrue(clientUserSpectedTask.Status == TaskStatus.RanToCompletion);
            Assert.IsNotNull(clientUserSpectedTask.Result);
            Assert.AreEqual(3, clientUserSpectedTask.Result.Count);
            Assert.AreEqual(1, processed);
            clientUserRepository.Received(1).GetClientsByUserIdAsync(economicGroupId: Arg.Any <int>());
        }
        /// <summary>
        /// Gets the clients by user identifier asynchronous.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="isAdmin">if set to <c>true</c> [is admin].</param>
        /// <param name="economicGroupId">The economic group identifier.</param>
        /// <returns></returns>
        public async Task <IList <ClientUserDto> > GetClientsByUserIdAsync(string userId, bool isAdmin, int economicGroupId)
        {
            log.Debug("INICIO BUSCAR DATOS EN BD - CLIENTES");
            IList <ClientUser> clientsUsers = isAdmin ?
                                              await clientUserRepository.GetClientsByUserIdAsync(economicGroupId : economicGroupId).ConfigureAwait(false) :
                                              await clientUserRepository.GetClientsByUserIdAsync(userId, economicGroupId).ConfigureAwait(false);

            log.Debug("FIN BUSCAR DATOS EN BD - CLIENTES");
            log.Debug("INICIO BUSCAR DATOS EN CACHE - CLIENTES");
            if (clientsUsers.Any())
            {
                var firstClientId = clientsUsers.OrderBy(x => x.ClientName).FirstOrDefault().Id;
                log.Debug("INICIO BUSCAR DATOS EN CACHE - CLIENTES");
                var clientId = cache.Find($"{Constant.CLIENT_ID_CACHE_NAME}{userId}", () => firstClientId);
                log.Debug("FIN BUSCAR DATOS EN CACHE - CLIENTES");
                var existClient = clientsUsers.Any(t => t.Id == clientId);
                if (!existClient)
                {
                    clientId = firstClientId;
                    cache.Set($"{Constant.CLIENT_ID_CACHE_NAME}{userId}", clientId);
                }

                foreach (var clientsUser in clientsUsers.Where(clientsUser => clientsUser.Id == clientId))
                {
                    clientsUser.Selected = true;
                }

                log.Debug("INICIO SET DE DATOS EN CACHE - CLIENTES");
                cache.Set($"{Constant.ECONMIC_GROUP_ID_CACHE_NAME}{userId}", economicGroupId);
                log.Debug("FIN SET DE DATOS EN CACHE - CLIENTES");
            }

            return(mapper.Map <IList <ClientUserDto> >(clientsUsers.OrderBy(x => x.ClientName)));
        }