コード例 #1
0
        public void Simple()
        {
            MySqlConnectionStringBuilder sb = null;

            sb = new MySqlConnectionStringBuilder();
            sb.ConnectionString = "server=localhost;uid=reggie;pwd=pass;port=1111;" +
                                  "connection timeout=23; pooling=true; min pool size=33; " +
                                  "max pool size=66;keepalive=1";
            Assert.AreEqual("localhost", sb.Server);
            Assert.AreEqual("reggie", sb.UserID);
            Assert.AreEqual("pass", sb.Password);
            Assert.AreEqual(1111, sb.Port);
            Assert.AreEqual(23, sb.ConnectionTimeout);
            Assert.IsTrue(sb.Pooling);
            Assert.AreEqual(33, sb.MinimumPoolSize);
            Assert.AreEqual(66, sb.MaximumPoolSize);
            Assert.AreEqual(sb.Keepalive, 1);

            try
            {
                sb.ConnectionString = "server=localhost;badkey=badvalue";
                Assert.Fail("This should not work");
            }
            catch (ArgumentException)
            {
            }

            sb.Clear();
            Assert.AreEqual(15, sb.ConnectionTimeout);
            Assert.AreEqual(true, sb.Pooling);
            Assert.AreEqual(3306, sb.Port);
            Assert.AreEqual(String.Empty, sb.Server);
            Assert.AreEqual(false, sb.PersistSecurityInfo);
            Assert.AreEqual(0, sb.ConnectionLifeTime);
            Assert.IsFalse(sb.ConnectionReset);
            Assert.AreEqual(0, sb.MinimumPoolSize);
            Assert.AreEqual(100, sb.MaximumPoolSize);
            Assert.AreEqual(String.Empty, sb.UserID);
            Assert.AreEqual(String.Empty, sb.Password);
            Assert.AreEqual(false, sb.UseUsageAdvisor);
            Assert.AreEqual(String.Empty, sb.CharacterSet);
            Assert.AreEqual(false, sb.UseCompression);
            Assert.AreEqual("MYSQL", sb.PipeName);
            Assert.IsFalse(sb.Logging);
            Assert.IsFalse(sb.UseOldSyntax);
            Assert.IsTrue(sb.AllowBatch);
            Assert.IsFalse(sb.ConvertZeroDateTime);
            Assert.AreEqual("MYSQL", sb.SharedMemoryName);
            Assert.AreEqual(String.Empty, sb.Database);
            Assert.AreEqual(MySqlConnectionProtocol.Sockets, sb.ConnectionProtocol);
            Assert.IsFalse(sb.AllowZeroDateTime);
            Assert.IsFalse(sb.UsePerformanceMonitor);
            Assert.AreEqual(25, sb.ProcedureCacheSize);
            Assert.AreEqual(0, sb.Keepalive);
        }
コード例 #2
0
    public void Simple()
    {
      MySqlConnectionStringBuilder sb = null;
      sb = new MySqlConnectionStringBuilder();
      sb.ConnectionString = "server=localhost;uid=reggie;pwd=pass;port=1111;" +
          "connection timeout=23; pooling=true; min pool size=33; " +
          "max pool size=66;keepalive=1";
      Assert.AreEqual("localhost", sb.Server);
      Assert.AreEqual("reggie", sb.UserID);
      Assert.AreEqual("pass", sb.Password);
      Assert.AreEqual(1111, sb.Port);
      Assert.AreEqual(23, sb.ConnectionTimeout);
      Assert.IsTrue(sb.Pooling);
      Assert.AreEqual(33, sb.MinimumPoolSize);
      Assert.AreEqual(66, sb.MaximumPoolSize);
      Assert.AreEqual(sb.Keepalive, 1);

      try
      {
        sb.ConnectionString = "server=localhost;badkey=badvalue";
        Assert.Fail("This should not work");
      }
      catch (ArgumentException)
      {
      }

      sb.Clear();
      Assert.AreEqual(15, sb.ConnectionTimeout);
      Assert.AreEqual(true, sb.Pooling);
      Assert.AreEqual(3306, sb.Port);
      Assert.AreEqual(String.Empty, sb.Server);
      Assert.AreEqual(false, sb.PersistSecurityInfo);
      Assert.AreEqual(0, sb.ConnectionLifeTime);
      Assert.IsFalse(sb.ConnectionReset);
      Assert.AreEqual(0, sb.MinimumPoolSize);
      Assert.AreEqual(100, sb.MaximumPoolSize);
      Assert.AreEqual(String.Empty, sb.UserID);
      Assert.AreEqual(String.Empty, sb.Password);
      Assert.AreEqual(false, sb.UseUsageAdvisor);
      Assert.AreEqual(String.Empty, sb.CharacterSet);
      Assert.AreEqual(false, sb.UseCompression);
      Assert.AreEqual("MYSQL", sb.PipeName);
      Assert.IsFalse(sb.Logging);
      Assert.IsFalse(sb.UseOldSyntax);
      Assert.IsTrue(sb.AllowBatch);
      Assert.IsFalse(sb.ConvertZeroDateTime);
      Assert.AreEqual("MYSQL", sb.SharedMemoryName);
      Assert.AreEqual(String.Empty, sb.Database);
      Assert.AreEqual(MySqlConnectionProtocol.Sockets, sb.ConnectionProtocol);
      Assert.IsFalse(sb.AllowZeroDateTime);
      Assert.IsFalse(sb.UsePerformanceMonitor);
      Assert.AreEqual(25, sb.ProcedureCacheSize);
      Assert.AreEqual(0, sb.Keepalive);
    }
コード例 #3
0
        public void Simple()
        {
            MySqlConnectionStringBuilder sb = null;

            sb = new MySqlConnectionStringBuilder();
            sb.ConnectionString = "server=localhost;uid=reggie;pwd=pass;port=1111;" +
                                  "connection timeout=23; pooling=true; min pool size=33; " +
                                  "max pool size=66;keepalive=1";
            Assert.AreEqual("localhost", sb.Server);
            Assert.AreEqual("reggie", sb.UserID);
            Assert.AreEqual("pass", sb.Password);
            Assert.AreEqual(1111, Convert.ToInt32(sb.Port));
            Assert.AreEqual(23, Convert.ToInt32(sb.ConnectionTimeout));
            Assert.True(sb.Pooling);
            Assert.AreEqual(33, Convert.ToInt32(sb.MinimumPoolSize));
            Assert.AreEqual(66, Convert.ToInt32(sb.MaximumPoolSize));
            Assert.AreEqual(1, Convert.ToInt32(sb.Keepalive));
            Exception ex = Assert.Throws <ArgumentException>(() => sb.ConnectionString = "server=localhost;badkey=badvalue");

#if !(NETCOREAPP3_1 || NET5_0)
            Assert.AreEqual($"Option not supported.{Environment.NewLine}Parameter name: badkey", ex.Message);
#else
            Assert.AreEqual("Option not supported. (Parameter 'badkey')", ex.Message);
#endif
            sb.Clear();
            Assert.AreEqual(15, Convert.ToInt32(sb.ConnectionTimeout));
            Assert.True(sb.Pooling);
            Assert.True(sb.Pooling);
            Assert.AreEqual(3306, Convert.ToInt32(sb.Port));
            Assert.AreEqual(String.Empty, sb.Server);
            Assert.False(sb.PersistSecurityInfo);
            Assert.AreEqual(0, Convert.ToInt32(sb.ConnectionLifeTime));
            Assert.False(sb.ConnectionReset);
            Assert.AreEqual(0, Convert.ToInt32(sb.MinimumPoolSize));
            Assert.AreEqual(100, Convert.ToInt32(sb.MaximumPoolSize));
            Assert.AreEqual(String.Empty, sb.UserID);
            Assert.AreEqual(String.Empty, sb.Password);
            Assert.False(sb.UseUsageAdvisor);
            Assert.AreEqual(String.Empty, sb.CharacterSet);
            Assert.False(sb.UseCompression);
            Assert.AreEqual("MYSQL", sb.PipeName);
            Assert.False(sb.Logging);
            Assert.True(sb.AllowBatch);
            Assert.False(sb.ConvertZeroDateTime);
            Assert.AreEqual("MYSQL", sb.SharedMemoryName);
            Assert.AreEqual(String.Empty, sb.Database);
            Assert.AreEqual(MySqlConnectionProtocol.Sockets, sb.ConnectionProtocol);
            Assert.False(sb.AllowZeroDateTime);
            Assert.False(sb.UsePerformanceMonitor);
            Assert.AreEqual(25, Convert.ToInt32(sb.ProcedureCacheSize));
            Assert.AreEqual(0, Convert.ToInt32(sb.Keepalive));
        }
        public void Simple()
        {
            MySqlConnectionStringBuilder sb = null;

            sb = new MySqlConnectionStringBuilder();
            sb.ConnectionString = "server=localhost;uid=reggie;pwd=pass;port=1111;" +
                                  "connection timeout=23; pooling=true; min pool size=33; " +
                                  "max pool size=66;keepalive=1";
            Assert.Equal("localhost", sb.Server);
            Assert.Equal("reggie", sb.UserID);
            Assert.Equal("pass", sb.Password);
            Assert.Equal(1111, Convert.ToInt32(sb.Port));
            Assert.Equal(23, Convert.ToInt32(sb.ConnectionTimeout));
            Assert.True(sb.Pooling);
            Assert.Equal(33, Convert.ToInt32(sb.MinimumPoolSize));
            Assert.Equal(66, Convert.ToInt32(sb.MaximumPoolSize));
            Assert.Equal(1, Convert.ToInt32(sb.Keepalive));
            Exception ex = Assert.Throws <ArgumentException>(() => (sb.ConnectionString = "server=localhost;badkey=badvalue"));

            Assert.Equal("Keyword not supported.\r\nParameter name: badkey", ex.Message);
            sb.Clear();
            Assert.Equal(15, Convert.ToInt32(sb.ConnectionTimeout));
            Assert.Equal(true, sb.Pooling);
            Assert.Equal(3306, Convert.ToInt32(sb.Port));
            Assert.Equal(String.Empty, sb.Server);
            Assert.Equal(false, sb.PersistSecurityInfo);
            Assert.Equal(0, Convert.ToInt32(sb.ConnectionLifeTime));
            Assert.False(sb.ConnectionReset);
            Assert.Equal(0, Convert.ToInt32(sb.MinimumPoolSize));
            Assert.Equal(100, Convert.ToInt32(sb.MaximumPoolSize));
            Assert.Equal(String.Empty, sb.UserID);
            Assert.Equal(String.Empty, sb.Password);
            Assert.Equal(false, sb.UseUsageAdvisor);
            Assert.Equal(String.Empty, sb.CharacterSet);
            Assert.Equal(false, sb.UseCompression);
            Assert.Equal("MYSQL", sb.PipeName);
            Assert.False(sb.Logging);
#pragma warning disable 618
            Assert.False(sb.UseOldSyntax);
#pragma warning restore 618
            Assert.True(sb.AllowBatch);
            Assert.False(sb.ConvertZeroDateTime);
            Assert.Equal("MYSQL", sb.SharedMemoryName);
            Assert.Equal(String.Empty, sb.Database);
            Assert.Equal(MySqlConnectionProtocol.Sockets, sb.ConnectionProtocol);
            Assert.False(sb.AllowZeroDateTime);
            Assert.False(sb.UsePerformanceMonitor);
            Assert.Equal(25, Convert.ToInt32(sb.ProcedureCacheSize));
            Assert.Equal(0, Convert.ToInt32(sb.Keepalive));
        }
コード例 #5
0
        /// <summary>
        /// Overrides the native Didspose method
        /// </summary>
        /// <param name="disposing">True or False</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // Clear all property values that maybe have been set
                    // when the class was instantiated
                    Clear();
                    connectionString.Clear();
                    connectionString = null;
                }

                // Indicate that the instance has been disposed.
                disposed = true;
            }
        }