public void UncStickCSBReadWriteTest()
        {
            List <DriveInfo> drives = Methods.GetMLifterSticks();

            if (drives.Count < 1)
            {
                Assert.Inconclusive("No Stick plugged in! To test the stick functionality please plug in a stick!");
            }

            string LMPath = Path.Combine(drives[0].RootDirectory.ToString(), "LearningModules");
            UncConnectionStringBuilder stick = new UncConnectionStringBuilder(Path.Combine(drives[0].RootDirectory.ToString(), "LearningModules"), false, true);

            ConnectionStringHandler.CreateUncConnection("StickTest", LMPath, drives[0].RootDirectory.ToString(), "defaultConnection.mlcfg", false, true);

            // test that the file was generated with the proper placeholder
            StreamReader sreader = new StreamReader(drives[0].RootDirectory.ToString() + "defaultConnection.mlcfg");

            Assert.AreNotEqual(-1, sreader.ReadToEnd().IndexOf("MEMSTICK:\\"), "MEMSTICK identifier not found");
            sreader.Close();

            // test that reading the file translates to the proper drive letter
            ConnectionStringHandler handler    = new ConnectionStringHandler(drives[0].RootDirectory.ToString(), string.Empty);
            IConnectionString       connection = handler.ConnectionStrings.Find(c => c.Name == "StickTest");

            Assert.IsNotNull(connection, "MEMSTICK config file not generated");
            Assert.AreEqual <string>(drives[0].RootDirectory.ToString() + "defaultConnection.mlcfg", connection.ConfigFileName);

            File.Delete(Path.Combine(drives[0].RootDirectory.ToString(), "defaultConnection.mlcfg"));
        }
        public void CSGCreateUncConnectionEmptyParam3Test()
        {
            Dictionary <string, string> referenceValues;
            UncConnectionStringBuilder  csb = PrepareUncConnectionStringBuilder(out referenceValues);

            ConnectionStringHandler.CreateUncConnection(csb, "test", " ");
        }
        public void CSHConstructorTest()
        {
            Dictionary <string, string> referenceValues1, referenceValues2, referenceValues3, referenceValues4, referenceValues5, referenceValues6;

            string generalPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            string userPath    = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(generalPath);
            Directory.CreateDirectory(userPath);

            ConnectionStringHandler.CreateUncConnection(PrepareUncConnectionStringBuilder(out referenceValues1), generalPath, "unc1.mlcfg");
            ConnectionStringHandler.CreateUncConnection(PrepareUncConnectionStringBuilder(out referenceValues2), generalPath, "unc2.mlcfg");
            ConnectionStringHandler.CreatePostgreSqlConnection(PreparePostgreSqlConnectionStringBuilder(out referenceValues3), generalPath, "pg1.mlcfg");

            ConnectionStringHandler.CreateUncConnection(PrepareUncConnectionStringBuilder(out referenceValues4), userPath, "unc1.mlcfg");
            ConnectionStringHandler.CreatePostgreSqlConnection(PreparePostgreSqlConnectionStringBuilder(out referenceValues5), userPath, "pg1.mlcfg");
            ConnectionStringHandler.CreatePostgreSqlConnection(PreparePostgreSqlConnectionStringBuilder(out referenceValues6), userPath, "pg2.mlcfg");
            ConnectionStringHandler target = new ConnectionStringHandler(generalPath, userPath);

            Assert.IsTrue(target.ConnectionStrings.FindAll(c => !(c is UncConnectionStringBuilder) || !(c as UncConnectionStringBuilder).IsOnStick).Count == 2, "CSHConstructorTest - There should be 6 connection strings!");
            foreach (IConnectionString csb in target.ConnectionStrings.FindAll(c => !(c is UncConnectionStringBuilder) || !(c as UncConnectionStringBuilder).IsOnStick))
            {
                if (csb.ConnectionType == MLifter.DAL.DatabaseType.PostgreSQL)
                {
                    Assert.AreEqual <MLifter.DAL.DatabaseType>(MLifter.DAL.DatabaseType.PostgreSQL, csb.ConnectionType, "CSHPostgreSqlConnectionStringBuilderTest - ConnectionType is not correct!");
                    Assert.AreEqual <string>(referenceValues3["Name"], csb.Name, "CSHPostgreSqlConnectionStringBuilderTest - Name is not correct!");
                }
                else
                {
                    Assert.AreEqual <MLifter.DAL.DatabaseType>(MLifter.DAL.DatabaseType.Unc, csb.ConnectionType, "CSHUncConnectionStringBuilderTest - ConnectionType is not correct!");
                    Assert.AreEqual <string>(referenceValues1["Name"], csb.Name, "CSHUncConnectionStringBuilderTest - Name is not correct!");
                    Assert.AreEqual <string>(referenceValues1["ConnectionString"], csb.ConnectionString, "CSHUncConnectionStringBuilderTest - ConnectionString is not correct!");
                }
            }

            Directory.Delete(generalPath, true);
            Directory.Delete(userPath, true);
        }
예제 #4
0
        /// <summary>
        /// Creates the default config.
        /// </summary>
        /// <param name="defaultLerningModulesPath">The default lerning modules path.</param>
        /// <remarks>Documented by Dev03, 2009-05-07</remarks>
        public static void CreateDefaultConfig(string defaultLerningModulesPath)
        {
            if (Directory.Exists(defaultLerningModulesPath))
            {
                Settings.Default.DicDir = defaultLerningModulesPath;
                Settings.Default.Save();

                string configPath = Setup.UserConfigPath;

                //Get the only connection from
                IConnectionString defaultConnection = ConnectionStringHandler.GetDefaultConnectionString(configPath);
                if (defaultConnection as UncConnectionStringBuilder == null)
                {
                    ConnectionStringHandler.CreateUncConnection(Resources.DEFAULT_CONNECTION_NAME, defaultLerningModulesPath, configPath, Resources.DEFAULT_CONNECTION_FILE, true, Setup.IsPathOnStick(defaultLerningModulesPath));
                }
                else
                {
                    UncConnectionStringBuilder builder = new UncConnectionStringBuilder(defaultLerningModulesPath, true, Setup.IsPathOnStick(defaultLerningModulesPath));
                    builder.Name = defaultConnection.Name;

                    ConnectionStringHandler.CreateUncConnection(builder, Path.GetDirectoryName(defaultConnection.ConfigFileName), Path.GetFileName(defaultConnection.ConfigFileName));
                }
            }
        }
 public void CSGCreateUncConnectionNullTest()
 {
     ConnectionStringHandler.CreateUncConnection(null, "test", "test");
 }