//Code to perform at the time of uninstalling application
    public override void Uninstall(System.Collections.IDictionary savedState)
    {
        //if (Debugger.IsAttached == false) Debugger.Launch();
        CustomParameters cParams = new CustomParameters(savedState);
        string           sBase   = cParams.GetValue("InstallPath");

        //Continue with uninstall process
        base.Uninstall(savedState);
        try
        {
            //Delete all files in the base folder recursively except service or exe files
            string[] files = System.IO.Directory.GetFiles(sBase, "*.*", System.IO.SearchOption.AllDirectories);
            foreach (string f in files)
            {
                //Check the extention of the filename first
                string sExt = Path.GetExtension(f).ToLower();
                if (sExt != ".installstate" && sExt != ".exe")
                {
                    FileAttributes attr = File.GetAttributes(f);
                    File.SetAttributes(f, attr & ~FileAttributes.ReadOnly);
                    System.IO.File.Delete(f);
                }
            }

            //This would delete the base install directory but
            //the installer will do this instead, I just need to
            //clean up everything I made other the the exe's and
            //service files
            //System.IO.Directory.Delete(sBase, true);
        }
        catch
        {
            //Error, just ignore it
        }
    }
Esempio n. 2
0
 /// <summary>
 /// Performs Cas20ServiceTicketValidator initialization.
 /// </summary>
 public override void Initialize()
 {
     if (CasAuthentication.ProxyTicketManager != null)
     {
         CustomParameters.Add("pgtUrl", HttpUtility.UrlEncode(UrlUtil.ConstructProxyCallbackUrl()));
     }
 }
Esempio n. 3
0
        public async Task When_getting_an_identity_for_staff_with_an_invalid_email_should_return_null()
        {
            //Arrange
            var mockContainer       = new Container();
            var mockStaffRepository = new Mock <IStaffRepository>();
            List <PersonIdentityModel> suppliedData = null;

            mockStaffRepository.Setup(r => r.GetStaffIdentityByEmailAsync(It.IsAny <string>(), It.IsAny <string[]>())).Returns(Task.FromResult(suppliedData));
            mockStaffRepository.Setup(r => r.GetStaffIdentityByProfileEmailAsync(It.IsAny <string>(), It.IsAny <string[]>())).Returns(Task.FromResult(suppliedData));
            mockContainer.RegisterInstance(typeof(IStaffRepository), mockStaffRepository.Object);

            var mockCustomParametersProvider = new Mock <ICustomParametersProvider>();
            var suppliedCustomParams         = new CustomParameters {
                descriptors = new Descriptors {
                    validStaffDescriptors = It.IsAny <string[]>()
                }
            };

            mockCustomParametersProvider.Setup(cp => cp.GetParameters()).Returns(suppliedCustomParams);


            var providerUnderTest = new StaffIdeintityProvider(mockContainer, mockCustomParametersProvider.Object);

            // ACT
            var actualResult = await providerUnderTest.GetIdentity("");

            //Assert
            Assert.IsNull(actualResult);
        }
Esempio n. 4
0
        public object GetDynamicParameters()
        {
            switch (Type)
            {
            case TeamTabType.Word:
            case TeamTabType.Excel:
            case TeamTabType.PowerPoint:
            case TeamTabType.PDF:
            {
                officeFileParameters = new OfficeFileParameters();
                return(officeFileParameters);
            }

            case TeamTabType.DocumentLibrary:
            case TeamTabType.WebSite:
            {
                documentLibraryParameters = new DocumentLibraryParameters();
                return(documentLibraryParameters);
            }

            case TeamTabType.Custom:
            {
                customParameters = new CustomParameters();
                return(customParameters);
            }
            }
            return(null);
        }
        /////// <summary>
        /////// Return All roles from application. All valus are formated likes this :
        /////// ApplicationID|RoleId|RoleName|Description.
        /////// To retreive any values, we must split each cell value
        /////// </summary>
        /////// <returns>Roles table</returns>
        ////public string[] GetAllRolesSplit()
        ////{
        ////    string[] roles = null;

        ////    try
        ////    {
        ////        if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
        ////            ImplementCustomConnection.Instance.Conn.Open();

        ////        using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
        ////        {
        ////            cmd.CommandText = @"SELECT a.ApplicationId,r.RoleName,r.RoleId,r.Description FROM aspnet_Roles r
        ////            INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId
        ////            WHERE a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))";

        ////            cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

        ////            IDataReader rd = cmd.ExecuteReader();

        ////            int tableIndex = 0;

        ////            while (rd.Read())
        ////            {
        ////                roles[tableIndex] = string.Format("{0}|{1}|{2}|{3}", rd["ApplicationId"].ToString(), rd["RoleId"].ToString(), rd["RoleName"].ToString(), rd["Description"].ToString());
        ////                tableIndex++;
        ////            }

        ////            rd.Dispose();
        ////        }
        ////    }
        ////    finally
        ////    {
        ////        ImplementCustomConnection.Instance.CloseConnection();
        ////    }

        ////    return roles;
        ////}

        /// <summary>
        /// Return all username for a specifique role for current application after has passed role name and username as param.
        /// </summary>
        /// <param name="roleName">Role name to match</param>
        /// <param name="usernameToMatch">Username to match</param>
        /// <returns>String table of users</returns>
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            string[] valuesUser = null;

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Role name cannot be empty.");
            }
            if (string.IsNullOrEmpty(usernameToMatch))
            {
                throw new ArgumentException("Username name cannot be empty.");
            }

            try
            {
                if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                {
                    ImplementCustomConnection.Instance.Conn.Open();
                }

                using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT (SELECT COUNT(u.UserName) AS NumRecord FROM aspnet_Roles r INNER JOIN aspnet_UsersInRoles ur ON r.RoleId=ur.RoleId INNER JOIN aspnet_Users u ON u.UserId=ur.UserId 
                    WHERE r.LoweredRoleName LIKE @LoweredRoleName AND u.LoweredUserName LIKE @LoweredUserName) AS NumRecord,u.UserName,u.UserId,r.RoleName,r.RoleId,r.Description FROM aspnet_Roles r
                    INNER JOIN aspnet_UsersInRoles ur ON r.RoleId=ur.RoleId 
                    INNER JOIN aspnet_Users u ON u.UserId=ur.UserId 
                    WHERE r.LoweredRoleName LIKE @LoweredRoleName AND u.LoweredUserName LIKE @LoweredUserName";

                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredRoleName", 256, DbType.String, roleName.ToLower()));
                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredUserName", 256, DbType.String, string.Format("%{0}%", usernameToMatch.ToLower())));

                    IDataReader rd = cmd.ExecuteReader();

                    int tableIndex = 0;

                    while (rd.Read())
                    {
                        if (tableIndex == 0)
                        {
                            // Initialise users table
                            int index = Convert.ToInt32(rd["NumRecord"].ToString());
                            valuesUser = new string[index];
                        }

                        valuesUser[tableIndex] = rd["UserName"].ToString();
                        tableIndex++;
                    }

                    rd.Dispose();
                }
            }
            finally
            {
                ImplementCustomConnection.Instance.CloseConnection();
            }

            return(valuesUser);
        }
    //Code to perform at the time of installing application
    public override void Install(System.Collections.IDictionary stateSaver)
    {
        //if (Debugger.IsAttached == false) Debugger.Launch();
        CustomParameters cParams = new CustomParameters();

        cParams.Add("InstallPath", this.Context.Parameters["targetdir"]);
        cParams.SaveState(stateSaver);
        //Continue with install process
        base.Install(stateSaver);
    }
Esempio n. 7
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var transactionNumber     = TransactionNumber.Get(context);
            var retryNumber           = RetryNumber.Get(context);
            var initRetryNumber       = InitRetryNumber.Get(context);
            var continuousRetryNumber = ContinuousRetryNumber.Get(context);
            var isQueueItem           = IsQueueItem.Get(context);
            var folders          = Folders.Get(context);
            var customParameters = CustomParameters.Get(context);
            var result           = true;

            ///////////////////////////

            // Create SystemReserved entity
            var sysRes = new SystemReserved(transactionNumber, retryNumber, initRetryNumber, continuousRetryNumber, folders, isQueueItem, "", customParameters);

            // If argument has value, check if it was correctly assigned
            if (sysRes.TransactionNumber != transactionNumber)
            {
                result = false;
            }
            if (sysRes.RetryNumber != retryNumber)
            {
                result = false;
            }
            if (sysRes.InitRetryNumber != initRetryNumber)
            {
                result = false;
            }
            if (sysRes.ContinuousRetryNumber != continuousRetryNumber)
            {
                result = false;
            }
            if (sysRes.IsQueueItem != isQueueItem)
            {
                result = false;
            }
            if (folders != null && sysRes.Folders != folders)
            {
                result = false;
            }
            if (customParameters != null && sysRes.CustomParameters != customParameters)
            {
                result = false;
            }

            ///////////////////////////

            // Outputs
            return((ctx) => {
                SystemReserved.Set(ctx, sysRes);
                Result.Set(ctx, result);
            });
        }
Esempio n. 8
0
        public virtual void SetJsonReadyCustomParameters(List <string> parameters)
        {
            if (parameters != null)
            {
                CustomParameters.Clear();

                foreach (var k in parameters)
                {
                    CustomParameters.Add(GraphParameterValue.FromJson(k, null));
                }
            }
        }
        // Return Role ID when his name has been passed as param.
        private object getRoleId(string roleName)
        {
            if (string.IsNullOrEmpty(roleName))
            {
                return(null);
            }
            else
            {
                try
                {
                    if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                    {
                        ImplementCustomConnection.Instance.Conn.Open();
                    }

                    using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                    {
                        cmd.CommandText = @"SELECT a.ApplicationId,r.RoleName,r.RoleId,r.Description FROM aspnet_Roles r
                        INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId  
                        WHERE r.LoweredRoleName=@LoweredRoleName AND a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))";

                        cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredRoleName", 256, DbType.String, roleName.ToLower()));
                        cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

                        IDataReader rd = cmd.ExecuteReader();

                        try
                        {
                            if (rd.Read())
                            {
                                object valueApp = rd["RoleId"];
                                return(valueApp);
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        finally
                        {
                            rd.Dispose();
                        }
                    }
                }
                finally
                {
                    ImplementCustomConnection.Instance.CloseConnection();
                }
            }
        }
        /// <summary>
        /// Return All roles from application.
        /// </summary>
        /// <returns>Roles table</returns>
        public override string[] GetAllRoles()
        {
            string[] roles = null;

            try
            {
                if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                {
                    ImplementCustomConnection.Instance.Conn.Open();
                }

                using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT (SELECT COUNT(r.RoleName) as NumRecord FROM aspnet_Roles r
                    INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId  
                    WHERE a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))) as NumRecord,r.RoleName FROM aspnet_Roles r
                    INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId  
                    WHERE a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))";

                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

                    IDataReader rd = cmd.ExecuteReader();

                    int tableIndex = 0;

                    while (rd.Read())
                    {
                        if (tableIndex == 0)
                        {
                            int index = Convert.ToInt32(rd["NumRecord"].ToString());
                            roles = new string[index];
                        }

                        roles[tableIndex] = rd["RoleName"].ToString();
                        tableIndex++;
                    }

                    rd.Dispose();
                }
            }
            finally
            {
                ImplementCustomConnection.Instance.CloseConnection();
            }

            return(roles);
        }
        /// <summary>
        /// Return all users from a specific role name.
        /// </summary>
        /// <param name="roleName">Role name to match</param>
        /// <returns>Username string table</returns>
        public override string[] GetUsersInRole(string roleName)
        {
            string[] valuesUser = null;

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Role name cannot be empty.");
            }

            try
            {
                if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                {
                    ImplementCustomConnection.Instance.Conn.Open();
                }

                using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT a.ApplicationId,u.UserName,u.UserId,r.RoleName,r.RoleId,r.Description FROM aspnet_Roles r
                    INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId 
                    INNER JOIN aspnet_Users u ON a.ApplicationId=u.ApplicationId 
                    INNER JOIN aspnet_UsersInRoles ur ON u.UserId=ur.UserId 
                    WHERE r.LoweredRoleName=@LoweredRoleName AND a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))";

                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredRoleName", 256, DbType.String, roleName.ToLower()));
                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

                    IDataReader rd = cmd.ExecuteReader();

                    int tableIndex = 0;

                    while (rd.Read())
                    {
                        valuesUser[tableIndex] = rd["UserName"].ToString();
                        tableIndex++;
                    }

                    rd.Dispose();
                }
            }
            finally
            {
                ImplementCustomConnection.Instance.CloseConnection();
            }

            return(valuesUser);
        }
        public static string ToBulkString(this CustomParameters parameters)
        {
            if (parameters == null)
            {
                return(null);
            }

            if (parameters.Parameters == null || parameters.Parameters.Count == 0)
            {
                return(DeleteValue);
            }

            return(string.Join("; ",
                               parameters.Parameters.Select(
                                   entry =>
                                   string.Format(CultureInfo.InvariantCulture, "{{_{0}}}={1}", entry.Key,
                                                 EscapeParameterText(entry.Value)))));
        }
Esempio n. 13
0
        private ParentAlertTypeModel featureToggleFilter(CustomParameters customParameters, ParentAlertTypeModel model)
        {
            List <AlertTypeModel> modelAlerts = new List <AlertTypeModel>();

            modelAlerts  = model.Alerts.ToList();
            model.Alerts = new List <AlertTypeModel>();

            foreach (var alert in modelAlerts)
            {
                if (alert.AlertTypeId == 1 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null).ToList()).FirstOrDefault().Count > 0 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null)).FirstOrDefault().FirstOrDefault().studentAbc.absence)
                {
                    model.Alerts.Add(modelAlerts.FirstOrDefault(x => x.AlertTypeId == 1));
                }

                if (alert.AlertTypeId == 2 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null).ToList()).FirstOrDefault().Count > 0 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null)).FirstOrDefault().FirstOrDefault().studentAbc.behavior)
                {
                    model.Alerts.Add(modelAlerts.FirstOrDefault(x => x.AlertTypeId == 2));
                }

                if (alert.AlertTypeId == 3 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null).ToList()).FirstOrDefault().Count > 0 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null)).FirstOrDefault().FirstOrDefault().studentAbc.missingAssignments)
                {
                    model.Alerts.Add(modelAlerts.FirstOrDefault(x => x.AlertTypeId == 3));
                }

                if (alert.AlertTypeId == 4 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null).ToList()).FirstOrDefault().Count > 0 &&
                    customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null)).FirstOrDefault().FirstOrDefault().studentAbc.courseAverage)
                {
                    model.Alerts.Add(modelAlerts.FirstOrDefault(x => x.AlertTypeId == 4));
                }

                if (alert.AlertTypeId == 5)
                {
                    model.Alerts.Add(modelAlerts.FirstOrDefault(x => x.AlertTypeId == 5));
                }
            }
            return(model);
        }
        /// <summary>
        /// Return True if role existm otherwise return False.
        /// </summary>
        /// <param name="roleName">Role name to match</param>
        /// <returns>Status True if found, otherwise False</returns>
        public override bool RoleExists(string roleName)
        {
            bool status = false;

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Role name cannot be empty.");
            }

            try
            {
                if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                {
                    ImplementCustomConnection.Instance.Conn.Open();
                }

                using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT a.ApplicationId,r.RoleName,r.RoleId,r.Description FROM aspnet_Roles r
                    INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId  
                    WHERE r.LoweredRoleName=@LoweredRoleName AND a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))";

                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredRoleName", 256, DbType.String, roleName.ToLower()));
                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

                    IDataReader rd = cmd.ExecuteReader();

                    if (rd.Read())
                    {
                        status = true;
                    }

                    rd.Dispose();
                }
            }
            finally
            {
                ImplementCustomConnection.Instance.CloseConnection();
            }

            return(status);
        }
        /// <summary>
        /// Indicate if the specified user is in the specified role name.
        /// </summary>
        /// <param name="username">Username to match</param>
        /// <param name="roleName">Rolename to match</param>
        /// <returns>Boolean status indicate if user is in role. True or False</returns>
        public override bool IsUserInRole(string username, string roleName)
        {
            bool status = false;

            try
            {
                if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                {
                    ImplementCustomConnection.Instance.Conn.Open();
                }

                using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT a.ApplicationId,u.UserName,u.UserId,r.RoleName,r.RoleId,r.Description FROM aspnet_Roles r
                    INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId 
                    INNER JOIN aspnet_Users u ON a.ApplicationId=u.ApplicationId 
                    INNER JOIN aspnet_UsersInRoles ur ON u.UserId=ur.UserId 
                    WHERE u.LoweredUserName=@LoweredUserName AND r.LoweredRoleName=@LoweredRoleName AND a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))";

                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredUserName", 256, DbType.String, username.ToLower()));
                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredRoleName", 256, DbType.String, roleName.ToLower()));
                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

                    IDataReader rd = cmd.ExecuteReader();

                    if (rd.Read())
                    {
                        status = true;
                    }

                    rd.Dispose();
                }
            }
            finally
            {
                ImplementCustomConnection.Instance.CloseConnection();
            }

            return(status);
        }
        /// <summary>
        /// Add new Role in Database.
        /// </summary>
        /// <param name="roleName">Role name</param>
        public override void CreateRole(string roleName)
        {
            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Role name cannot be empty.");
            }

            try
            {
                if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                {
                    ImplementCustomConnection.Instance.Conn.Open();
                }

                using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                {
                    Guid RoleIdent = Guid.NewGuid();

                    cmd.CommandText = @"INSERT INTO aspnet_Roles(ApplicationId,RoleId,RoleName,LoweredRoleName,Description)
                    VALUES((SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName)),@RoleId,@RoleName,LOWER(@RoleName),null)";

                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@RoleId", 36, DbType.Guid, RoleIdent));
                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@RoleName", 256, DbType.String, roleName));
                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

                    int record = cmd.ExecuteNonQuery();

                    if (record == 0)
                    {
                        throw new ArgumentException("Failed to create role, please try again.");
                    }
                }
            }
            finally
            {
                ImplementCustomConnection.Instance.CloseConnection();
            }
        }
Esempio n. 17
0
        public async Task When_getting_an_identity_for_staff_with_a_valid_email_should_return_object()
        {
            //Arrange
            var mockContainer       = new Container();
            var mockStaffRepository = new Mock <IStaffRepository>();
            List <PersonIdentityModel> suppliedData = new List <PersonIdentityModel>();

            suppliedData.Add(new PersonIdentityModel
            {
                Email       = "*****@*****.**",
                FirstName   = "Karen",
                LastSurname = "Jhonson",
                PersonType  = "Staff",
            });

            mockStaffRepository.Setup(r => r.GetStaffIdentityByEmailAsync(It.IsAny <string>(), It.IsAny <string[]>())).Returns(Task.FromResult(suppliedData));
            mockStaffRepository.Setup(r => r.GetStaffIdentityByProfileEmailAsync(It.IsAny <string>(), It.IsAny <string[]>())).Returns(Task.FromResult(suppliedData));
            mockContainer.RegisterInstance(typeof(IStaffRepository), mockStaffRepository.Object);

            var mockCustomParametersProvider = new Mock <ICustomParametersProvider>();
            var suppliedCustomParams         = new CustomParameters {
                descriptors = new Descriptors {
                    validStaffDescriptors = It.IsAny <string[]>()
                }
            };

            mockCustomParametersProvider.Setup(cp => cp.GetParameters()).Returns(suppliedCustomParams);


            var providerUnderTest = new StaffIdeintityProvider(mockContainer, mockCustomParametersProvider.Object);

            // ACT
            var actualResult = await providerUnderTest.GetIdentity("*****@*****.**");

            //Assert
            Assert.AreEqual(actualResult.PersonType, "Staff");
        }
        /// <summary>
        /// Delete Role when his name has been passed as param.
        /// </summary>
        /// <param name="roleName">RoleName to delete</param>
        /// <param name="throwOnPopulatedRole">State True that allow to return a exception when role has depending members</param>
        /// <returns>Status True or False for deletion</returns>
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            bool status   = false;
            Guid?RoleIdet = null;

            // Validate Rolename.
            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Role name cannot be empty.");
            }

            if (throwOnPopulatedRole)
            {
                IDbTransaction transaction = null;

                try
                {
                    // Get Role ID
                    try
                    {
                        RoleIdet = Guid.Parse(getRoleId(roleName).ToString());
                    }
                    catch { }

                    if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                    {
                        ImplementCustomConnection.Instance.Conn.Open();
                    }

                    transaction = ImplementCustomConnection.Instance.Conn.BeginTransaction(IsolationLevel.Serializable);

                    // Find Roles first
                    using (IDbCommand cmd1 = ImplementCustomConnection.Instance.Conn.CreateCommand())
                    {
                        cmd1.CommandText = @"SELECT a.ApplicationId,u.UserName,u.UserId,r.RoleName,r.RoleId,r.Description FROM aspnet_Roles r
                        INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId 
                        INNER JOIN aspnet_Users u ON a.ApplicationId=u.ApplicationId 
                        INNER JOIN aspnet_UsersInRoles ur ON u.UserId=ur.UserId 
                        WHERE r.LoweredRoleName=@LoweredRoleName AND a.ApplicationId=(SELECT a.ApplicationId FROM aspnet_Applications a WHERE a.LoweredApplicationName=LOWER(@ApplicationName))";

                        cmd1.Parameters.Add(CustomParameters.Add(cmd1, "@LoweredRoleName", 256, DbType.String, roleName.ToLower()));
                        cmd1.Parameters.Add(CustomParameters.Add(cmd1, "@ApplicationName", 256, DbType.String, _applicationName));

                        cmd1.Transaction = transaction;
                        IDataReader rd = cmd1.ExecuteReader();

                        try
                        {
                            if (rd.Read())
                            {
                                throw new ArgumentException("Failed to delete the specified role because has contains one or more members.");
                            }
                        }
                        finally
                        {
                            rd.Dispose();
                        }
                    }

                    // Delete role
                    using (IDbCommand cmd2 = ImplementCustomConnection.Instance.Conn.CreateCommand())
                    {
                        cmd2.CommandText = @"DELETE FROM aspnet_Roles WHERE RoleId=@RoleId";

                        cmd2.Parameters.Add(CustomParameters.Add(cmd2, "@RoleId", 36, DbType.Guid, RoleIdet));

                        cmd2.Transaction = transaction;
                        int record = cmd2.ExecuteNonQuery();

                        if (record == 0)
                        {
                            throw new ArgumentException("Failed to delete role into Database, please try again.");
                        }
                        else
                        {
                            status = true;
                        }

                        transaction.Commit();
                        transaction.Dispose();
                    }
                }
                catch (Exception)
                {
                    if (transaction != null)
                    {
                        transaction.Rollback();
                        transaction.Dispose();
                    }
                    throw;
                }
                finally
                {
                    ImplementCustomConnection.Instance.CloseConnection();
                }
            }
            else
            {
                // Delete Role witout chech its depending
                // Delete role
                using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                {
                    cmd.CommandText = @"DELETE FROM aspnet_Roles WHERE RoleId=@RoleId";

                    cmd.Parameters.Add(CustomParameters.Add(cmd, "@RoleId", 36, DbType.Guid, RoleIdet));

                    int record = cmd.ExecuteNonQuery();

                    if (record == 0)
                    {
                        throw new ArgumentException("Failed to delete role into Database, please try again.");
                    }
                    else
                    {
                        status = true;
                    }
                }
            }

            return(status);
        }
        /// <summary>
        /// Add many user in many role for a single application.
        /// </summary>
        /// <param name="usernames">Usernames table</param>
        /// <param name="roleNames">Rolenames table</param>
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            IDbTransaction transaction = null;

            if (usernames.Length == 0)
            {
                throw new ArgumentException("Username cannot be empty.");
            }
            if (roleNames.Length == 0)
            {
                throw new ArgumentException("Role name cannot be empty.");
            }

            try
            {
                if (ImplementCustomConnection.Instance.Conn.State == ConnectionState.Closed)
                {
                    ImplementCustomConnection.Instance.Conn.Open();
                }

                transaction = ImplementCustomConnection.Instance.Conn.BeginTransaction(IsolationLevel.Serializable);

                foreach (string user in usernames)
                {
                    foreach (string role in roleNames)
                    {
                        using (IDbCommand cmd = ImplementCustomConnection.Instance.Conn.CreateCommand())
                        {
                            cmd.CommandText = @"INSERT INTO aspnet_UsersInRoles(UserId,RoleId)
                            VALUES((SELECT u.UserId FROM aspnet_Users u INNER JOIN aspnet_Applications a ON a.ApplicationId=u.ApplicationId WHERE u.LoweredUserName=@LoweredUserName AND a.LoweredApplicationName=LOWER(@ApplicationName)),
                            ((SELECT r.RoleId FROM aspnet_Roles r INNER JOIN aspnet_Applications a ON a.ApplicationId=r.ApplicationId WHERE r.LoweredRoleName=@LoweredRoleName AND a.LoweredApplicationName=LOWER(@ApplicationName))))";

                            cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredRoleName", 256, DbType.String, role.ToLower()));
                            cmd.Parameters.Add(CustomParameters.Add(cmd, "@LoweredUserName", 256, DbType.String, user.ToLower()));
                            cmd.Parameters.Add(CustomParameters.Add(cmd, "@ApplicationName", 256, DbType.String, _applicationName));

                            cmd.Transaction = transaction;
                            int record = cmd.ExecuteNonQuery();

                            // Allow to recreate new command onject
                            cmd.Parameters.Clear();

                            if (record == 0)
                            {
                                throw new ArgumentException(string.Format("Failed to add user '{0}' in role '{1}', please try again.", user, role));
                            }
                        }
                    }
                }

                transaction.Commit();
                transaction.Dispose();
            }
            catch (Exception)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                    transaction.Dispose();
                }
                throw;
            }
            finally
            {
                ImplementCustomConnection.Instance.CloseConnection();
            }
        }