예제 #1
0
    public void PgDbManagerCreatedWithNullSuperuserUsesDefaultSuperuser()
    {
      var manager = new PgDbManager { Description = new PgDbDescription { ConnectionInfo = GlobalTest.Manager1.Description.ConnectionInfo } };

      Assert.NotNull(manager.Description.Superuser);
      Assert.AreEqual("postgres", ((PgSuperuser)manager.Description.Superuser).DatabaseName);
      Assert.AreEqual("postgres", manager.Description.Superuser.UserName);
      Assert.AreEqual("postgres", manager.Description.Superuser.Password);
    }
예제 #2
0
    public void PgDbManagerCreatedWithSuperuserUsesSuperuser()
    {
      var manager = new PgDbManager
      {
        Description = new PgDbDescription
        {
          ConnectionInfo = GlobalTest.Manager1.Description.ConnectionInfo,
          Superuser = new PgSuperuser { DatabaseName = "sudb", UserName = "******", Password = "******" }
        }
      };

      Assert.NotNull(manager.Description.Superuser);
      Assert.AreEqual("sudb", ((PgSuperuser)manager.Description.Superuser).DatabaseName);
      Assert.AreEqual("suid", manager.Description.Superuser.UserName);
      Assert.AreEqual("supw", manager.Description.Superuser.Password);
    }
    public void DestroyDropsRole()
    {
      var manager = new PgDbManager { Description = new PgDbDescription { ConnectionInfo = GlobalTest.Manager1.Description.ConnectionInfo } };

      manager.Create();
      manager.Destroy();

      using (var conn = manager.CreateDatabaseConnection())
      {
        conn.Open();

        using (var cmd = conn.CreateCommand())
        {
          cmd.CommandText = string.Format("SELECT COUNT(*) FROM pg_catalog.pg_user WHERE usename='{0}'", manager.Description.ConnectionInfo.UserName);
          Assert.AreEqual(0, Convert.ToInt64(cmd.ExecuteScalar()));
        }
      }
    }
예제 #4
0
    public void CreateContentConnectionStringUsesSuperuserParameters()
    {
      var manager = new PgDbManager
      {
        Description = new PgDbDescription
        {
          ConnectionInfo = GlobalTest.Manager1.Description.ConnectionInfo,
          Superuser = new PgSuperuser { DatabaseName = "sudb", UserName = "******", Password = "******" }
        }
      };
                    
      using (var conn = manager.CreateContentConnection())
      {
        var result = new DbConnectionStringBuilder { ConnectionString = conn.ConnectionString };

        Assert.AreEqual(manager.Description.ConnectionInfo.DatabaseName, result[PgDbConnectionInfo.DatabaseNameKey]);
        Assert.AreEqual("suid", result[PgDbConnectionInfo.UserNameKey]);
        Assert.AreEqual("supw", result[PgDbConnectionInfo.PasswordKey]);
      }
    }
    public void DestroyDoesNotDropRoleThatIsStillInUse()
    {
      var manager2 = new PgDbManager { Description = new PgDbDescription { ConnectionInfo = GlobalTest.Manager2.Description.ConnectionInfo } };
      manager2.Create();

      // Create a new manager for connection 1's database with connection 2's user
      var csBuilderT = new DbConnectionStringBuilder { ConnectionString = GlobalTest.Manager1.Description.ConnectionInfo.ConnectionString };
      csBuilderT[PgDbConnectionInfo.UserNameKey] = GlobalTest.Manager2.Description.ConnectionInfo.UserName;
      csBuilderT[PgDbConnectionInfo.PasswordKey] = GlobalTest.Manager2.Description.ConnectionInfo.Password;

      var managerT = new PgDbManager
                     {
                       Description = new PgDbDescription
                                     {
                                       ConnectionInfo = new DbConnectionInfo
                                                        {
                                                          ConnectionString = csBuilderT.ConnectionString,
                                                          Provider = GlobalTest.Manager1.Description.ConnectionInfo.Provider
                                                        }
                                     }
                     };

      managerT.Create();
      managerT.Destroy();

      // connection 2's user should not have been deleted because it is still in use by connection 2's database

      using (var conn = managerT.CreateDatabaseConnection())
      {
        conn.Open();

        using (var cmd = conn.CreateCommand())
        {
          cmd.CommandText = string.Format("SELECT COUNT(*) FROM pg_catalog.pg_user WHERE usename='{0}'", csBuilderT[PgDbConnectionInfo.UserNameKey]);
          Assert.AreEqual(1, Convert.ToInt64(cmd.ExecuteScalar()));
        }
      }
    }
예제 #6
0
    private void InvalidParameterTests(Action<PgDbManager> action)
    {
      var manager = new PgDbManager();
      var result = Assert.Throws<ArgumentException>(() => action.Invoke(manager));
      Assert.AreEqual("Description", result.ParamName);
      Console.WriteLine(result.Message);
      
      manager = new PgDbManager { Description = new PgDbDescription() };
      result = Assert.Throws<ArgumentException>(() => action.Invoke(manager));
      Assert.AreEqual("Description.ConnectionInfo", result.ParamName);
      Console.WriteLine(result.Message);

      manager = new PgDbManager { Description = new PgDbDescription { ConnectionInfo = new DbConnectionInfo() } };
      result = Assert.Throws<ArgumentException>(() => action.Invoke(manager));
      Assert.AreEqual("Description.ConnectionInfo.ConnectionString", result.ParamName);
      Console.WriteLine(result.Message);
    }