public PolicyConfiguration Invoke(int projectId, Policy policy)
        {
            var project = projectRepository.GetById(projectId);

            if (project == null)
            {
                throw new ArgumentNullException($"Could not find project with id: {projectId}.");
            }

            var projectPolicy = project.ProjectPolicies.FirstOrDefault(pp => pp.Policy == policy);

            if (projectPolicy != null)
            {
                try
                {
                    return(jsonConvertService.Deserialize(projectPolicy.Policy,
                                                          projectPolicy.SerializedProjectPolicySetting));
                }
                catch (Exception e)
                {
                    throw new Exception(
                              $"There was a problem with deserializing policy configurations of project with id: {projectId}, " +
                              $"policy: {policy}, exception message: {e.Message}.");
                }
            }

            switch (policy)
            {
            case Policy.AccountExpirationDate:
                return(new AccountExpirationDateConfiguration());

            case Policy.MinimumPasswordLength:
                return(new MinimumPasswordLengthConfiguration());

            case Policy.PasswordExpirationDate:
                return(new PasswordExpirationDateConfiguration());

            case Policy.RequiredPasswordCharacters:
                return(new RequiredPasswordCharactersConfiguration());

            case Policy.ExcludeCommonPasswords:
                return(new ExcludeCommonPasswordsConfiguration());

            default:
                throw new Exception($"Wrong policy ({policy}) given to GetPolicyConfigurationOrDefaultFromProject.");
            }
        }
        public List <Tuple <Policy, PolicyConfiguration> > Invoke(int projectId)
        {
            var project = projectRepository.GetById(projectId);

            if (project == null)
            {
                throw new ArgumentNullException($"Could not find project with id: {projectId}.");
            }

            try
            {
                return(project.ProjectPolicies
                       .Select(pp => new Tuple <Policy, PolicyConfiguration>
                                   (pp.Policy, jsonConvertService.Deserialize(pp.Policy, pp.SerializedProjectPolicySetting)))
                       .ToList());
            }
            catch (Exception e)
            {
                throw new Exception(
                          $"There was a problem with deserializing policy configurations of project with id: {projectId}, " +
                          $"exception message: {e.Message}.");
            }
        }