public TestProductCRUDOperations()
        {
            //to be called before every unit test
            ConnectionStringBuilder builder = ConnectionStringBuilder.getInstance();

            builder.SetConnectionString(_connectionString);
        }
        public TestDALHandler()
        {
            //to be called before every unit test
            string _connectionString        = ConfigurationManager.ConnectionStrings["TestConnectionSting"].ConnectionString;
            ConnectionStringBuilder builder = ConnectionStringBuilder.getInstance();

            builder.SetConnectionString(_connectionString);
        }
Exemple #3
0
        public UcStartup()
        {
            InitializeComponent();

            try
            {
                if (Properties.Settings.Default.ChkRememberMe)
                {
                    chkRememberPass.IsChecked = true;
                    ConnectionStringBuilder.SetConnectionString(Properties.Settings.Default.ServerName, Properties.Settings.Default.Login, Security.ToInsecureString(Security.DecryptString(Properties.Settings.Default.Pass)));
                }
            }
            catch
            {
            }

            txtServerName.Text   = ConnectionStringBuilder.ServerName;
            txtLogin.Text        = ConnectionStringBuilder.UserName;
            txtPassword.Password = ConnectionStringBuilder.Password;
        }
Exemple #4
0
        private async void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            succ = false;
            btnConnect.IsEnabled = false;
            btnClose.IsEnabled   = false;


            tokenSource = new CancellationTokenSource();
            var token = tokenSource.Token;

            string serverName = txtServerName.Text;
            string login      = txtLogin.Text;
            string password   = txtPassword.Password;

            bool isChecked = chkRememberPass.IsChecked == true;

            try
            {
                ConnectionStringBuilder.SetConnectionString(txtServerName.Text, txtLogin.Text, txtPassword.Password);

                await Task.Run(new Action(() =>
                {
                    if (token.IsCancellationRequested)
                    {
                        token.ThrowIfCancellationRequested();
                    }

                    PhonebookContext db = new PhonebookContext(ConnectionStringBuilder.ConnectionString);

                    // Create database.
                    // If failed to connect to the database server, it will throw an exception.
                    db.Database.CreateIfNotExists();

                    if (token.IsCancellationRequested)
                    {
                        token.ThrowIfCancellationRequested();
                    }

                    succ = true;


                    OnConnectionCreated(this, null);
                }), token);
            }
            catch
            {
            }

            try
            {
                tokenSource.Dispose();
            }
            catch { }

            btnConnect.IsEnabled = true;
            btnCancel.IsEnabled  = true;
            btnClose.IsEnabled   = true;

            if (succ == false)
            {
                MessageBox.Show("خطا");
            }
            else
            {
                try
                {
                    if (isChecked)
                    {
                        string pass = password;
                        Properties.Settings.Default.ServerName = serverName;
                        Properties.Settings.Default.Login      = login;
                        await Task.Run(() => {
                            Properties.Settings.Default.Pass = Security.EncryptString(Security.ToSecureString(pass));
                            Properties.Settings.Default.Save();
                        });
                    }
                }
                catch
                {
                }
            }
        }
Exemple #5
0
        public void TestSetConnectionString()
        {
            ConnectionStringBuilder builder = ConnectionStringBuilder.getInstance();

            builder.SetConnectionString(_connectionString);
        }