VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 网站开发 > ASPnet >
  • 疑是Microsoft Enterprise Library June 2005的一个小bug (续)

      昨天经过Terrylee  的指出后,又找出了Microsoft Enterprise Library June 2005的源代码,仔细的看了看。
总觉得这个是个bug。
          我又找到了src\Data\Tests这个目录下的ConnectionStringFixture.cs测试文件。经过我的测试,我确定这是一个小bug.
          这面就是经测试经过:
          原来的ConnectionStringFixture.cs文件,没有做任何修改。
          源代码如下:

using System;
using NUnit.Framework;

namespace Microsoft.Practices.EnterpriseLibrary.Data.Tests
{
    [TestFixture]
    
public class ConnectionStringFixture
    
{
        
private static readonly string userName = "User";
        
private static readonly string password = "Password";
        
private static readonly string userIdTokens = "user id=,uid=";
        
private static readonly string passwordTokens = "password=,pwd=";
        
private ConnectionString connectionString;

        [Test]
        [ExpectedException(
typeof(InvalidOperationException))]
        
public void InvalidOperationExceptionThrownWhenConnectionStringIsNull()
        
{
            
this.connectionString = new ConnectionString(null, userIdTokens, passwordTokens);
            
string password = this.connectionString.Password;
            Assert.IsTrue(password 
!= null);
        }


        [Test]
        
public void EmptyCredentialsReturnedForEmptyConnectionString()
        
{
            
this.connectionString = new ConnectionString(string.Empty, userIdTokens, passwordTokens);
            Assert.AreEqual(
0this.connectionString.UserName.Length);
            Assert.AreEqual(
0this.connectionString.Password.Length);
        }


        [Test]
        
public void CanGetCredentialsFromRealSqlDataClass()
        
{
            
string initialConnectionString = String.Format("server=localhost; database=JoeRandom; uid={0}; pwd={1}; ;", userName, password);
            
this.connectionString = new ConnectionString(initialConnectionString, userIdTokens, passwordTokens);
            Assert.AreEqual(userName, 
this.connectionString.UserName);
            Assert.AreEqual(password, 
this.connectionString.Password);
        }


        [Test]
        
public void CreateNewConnectionStringTest()
        
{
            
string initialConnectionString = String.Format("server=localhost; database=JoeRandom; uid={0}; pwd={1}; ;", userName, password);
            
this.connectionString = new ConnectionString(initialConnectionString, userIdTokens, passwordTokens).CreateNewConnectionString(initialConnectionString);
            Assert.AreEqual(userName, 
this.connectionString.UserName);
            Assert.AreEqual(password, 
this.connectionString.Password);
        }


        [Test]
        
public void CanGetCredentialsUsingAlternatePatternsForUidAndPwd()
        
{
            
string initialConnectionString = String.Format("server=localhost; database=JoeRandom; user id={0}; password={1}; ;", userName, password);
            
this.connectionString = new ConnectionString(initialConnectionString, userIdTokens, passwordTokens);
            Assert.AreEqual(userName, 
this.connectionString.UserName);
            Assert.AreEqual(password, 
this.connectionString.Password);
        }


        [Test]
        
public void CanAddCredentialsToConnectionStringThatDoesNotHaveThem()
        
{
            
string initialConnectionString = "server=localhost; database=RandomData; ; ;";
            
this.connectionString = new ConnectionString(initialConnectionString, userIdTokens, passwordTokens);
            
this.connectionString.UserName = userName;
            
this.connectionString.Password = password;
            
string actualConnectionString = String.Format("server=localhost; database=RandomData; ; ;user id={0};password={1};",
                                                          userName, password);
            Assert.AreEqual(actualConnectionString, 
this.connectionString.ToString());
        }


        [Test]
        
public void CanSetUserIdAndPasswordInConnectionStringThatAlreadyHasOne()
        
{
            
string initialConnectionString = String.Format("server=localhost; database=JoeRandom; user id={0}; password={1}; ;""Kill""Bill");
            ConnectionString newConnectionString 
= new ConnectionString(initialConnectionString, userIdTokens, passwordTokens);
            newConnectionString.UserName 
= userName;
            newConnectionString.Password 
= password;
            
string actualConnectionString = String.Format("server=localhost; database=JoeRandom; user id={0}; password={1}; ;", userName, password);
            Assert.AreEqual(actualConnectionString, newConnectionString.ToString());
        }


        
/// <summary>
        /// Test to see if ToStringNoCredentials works properly for a connection string 
        
/// without a username and password
        
/// </summary>

        [Test]
        
public void RemovingCredentialsFromConnectionStringWithoutThemIsOk()
        
{
            
string initialConnectionString = "server=localhost;database=RandomData;";
            ConnectionString newConnectionString 
= new ConnectionString(initialConnectionString, userIdTokens, passwordTokens);
            
string expectedConnectionString = "server=localhost;database=randomdata;";
            
string strippedConnectionString = newConnectionString.ToStringNoCredentials();
            Assert.AreEqual(expectedConnectionString, strippedConnectionString);
        }


        
/// <summary>
        /// Test to see that ToStringNoCredentials removes the username and password
        
/// </summary>

        [Test]
        
public void WillRemoveCredentialsFromConnectionString()
        
{
            
string initialConnectionString = "server=localhost;database=RandomData;user id=Bill;pwd=goodPassword";
            ConnectionString newConnectionString 
= new ConnectionString(initialConnectionString,
                                                                        userIdTokens, passwordTokens);
            
string expectedConnectionString = "server=localhost;database=randomdata;";
            
string strippedConnectionString = newConnectionString.ToStringNoCredentials();
            Assert.AreEqual(expectedConnectionString, strippedConnectionString);
        }


        [Test]
        
public void NullTests()
        
{
            ConnectionString connectionString 
= new ConnectionString(nullnullnull);
            Assert.AreEqual(
string.Empty, connectionString.ToStringNoCredentials());
        }

    }

}


 测试结果:
  
  测试全部通过。

  
  新的ConnectionStringFixture.cs文件,做了两处修改。其他什么也没修改。
  原来的:private static readonly string userIdTokens = "user id=,uid=";       
  修改后:private static readonly string userIdTokens = "User Id=,Uid="; //只在此处修改
         
  原来的:private static readonly string passwordTokens = "password=,pwd=";
    修改后:private static readonly string passwordTokens = "Password=,Pwd=";//只在此处修改
   
   
    测试结果:
  
      测试有些没有通过。
  
      大家可以自己做个测试。
      所以我认为,这是Microsoft Enterprise Library June 2005的一个小bug,不在是疑似。
      不对的地方请指正。

出处:https://www.cnblogs.com/chillsrc/archive/2006/03/21/354542.html


相关教程