public void GetMruDbConnectionParameterTest()
        {
            var datasources1 = new Datasources()
            {
                Provider = ProviderType.Oracle
            };

            var datasource1_1 = new Datasource()
            {
                Address = "datasource1_1"
            };
            var datasourcesList1 = new List <Datasource>();

            datasourcesList1.Add(datasource1_1);
            datasources1.Datasource = datasourcesList1;

            var datasources2 = new Datasources();

            datasources2.Provider = ProviderType.Sybase;

            var history = new MruConnections()
            {
                Datasources = new List <Datasources>()
            };

            history.Datasources.Add(datasources1);
            history.Datasources.Add(datasources2);


            DbConnectionParameter murParameter = MruDbConnectionParameterAdapter.GetMruDbConnectionParameter(history);

            Assert.AreEqual(datasources1.Provider, murParameter.Provider);
            Assert.AreEqual(datasource1_1.Address, murParameter.DatasourceAddress);
        }
        public void SetMruDbConnectionParameterTest1()
        {
            MruConnections        mruConnections = new MruConnections();
            DbConnectionParameter parameter      = new DbConnectionParameter();

            parameter.Provider          = ProviderType.MsSql;
            parameter.DatasourceAddress = "server";
            parameter.Catalog           = "catalog";
            parameter.UserId            = "test";
            parameter.Password          = "******";

            MruDbConnectionParameterAdapter.SetMruDbConnectionParameter(mruConnections, parameter);

            DbConnectionParameter mruParameter = MruDbConnectionParameterAdapter.GetMruDbConnectionParameter(mruConnections);

            Assert.AreEqual(parameter, mruParameter);
        }
        /// <summary>
        /// Update the most recently used connection store with the latest parameters used.
        /// </summary>
        /// <param name="mruConnections">The most recently used connection store.</param>
        /// <param name="mruParameter">The most recently connection parameter used.</param>
        /// <returns><c>true</c> if the store was update. <c>false</c> if the store is up to date.</returns>
        public static bool SetMruDbConnectionParameter(MruConnections mruConnections, DbConnectionParameter mruParameter)
        {
            if (mruParameter == null)
            {
                return(false);
            }

            DbConnectionParameter currentMruParameter = MruDbConnectionParameterAdapter.GetMruDbConnectionParameter(mruConnections);

            if (Object.Equals(currentMruParameter, mruParameter))
            {
                return(false);
            }

            DatasourcesList newMruDatasources = new DatasourcesList();

            if (mruParameter.Provider != ProviderType.Undefined)
            {
                Datasources newFirstDatasources = new Datasources()
                {
                    Provider = mruParameter.Provider
                };
                ProviderDataSources datasources = new ProviderDataSources(mruParameter.Provider);
                if (!String.IsNullOrEmpty(mruParameter.DatasourceAddress))
                {
                    Datasource newFirstDatasource = new Datasource()
                    {
                        Address = mruParameter.DatasourceAddress,
                        Comment = mruParameter.DatasourceComment
                    };
                    datasources.Add(newFirstDatasource);

                    AddCatalogs(newFirstDatasource, mruConnections, mruParameter);
                    AddAuthentications(newFirstDatasource, mruConnections, mruParameter);
                    AddDatasourcesFromMruList(datasources, mruConnections);
                }
                newFirstDatasources.Datasource = datasources;

                newMruDatasources.Add(newFirstDatasources);
            }

            // Add all previously used datasources
            IEnumerable <Datasources> otherDatasources = mruConnections.Datasources;

            foreach (Datasources mruDatasources in otherDatasources)
            {
                if (newMruDatasources.Count >= MaxMruEntries)
                {
                    break;
                }

                if (newMruDatasources.Contains(mruDatasources))
                {
                    continue;
                }

                newMruDatasources.Add(mruDatasources);
            }

            mruConnections.Datasources = newMruDatasources;

            return(true);
        }