public void ThreadBoundCredentials() { IDbProvider dbProvider = A.Fake <IDbProvider>(); IDbConnection connection = A.Fake <IDbConnection>(); A.CallTo(() => dbProvider.CreateConnection()).Returns(connection); A.CallTo(() => dbProvider.ConnectionString).Returns(@"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False"); UserCredentialsDbProvider provider = new UserCredentialsDbProvider(); provider.TargetDbProvider = dbProvider; provider.SetCredentialsForCurrentThread("User ID=springqa", "Password=springqa"); Assert.AreEqual(connection, provider.CreateConnection()); A.CallToSet(() => connection.ConnectionString) .WhenArgumentsMatch(x => (string)x[0] == "Data Source=MARKT60\\SQL2005;Database=Spring;Trusted_Connection=False;User ID=springqa;Password=springqa") .MustHaveHappenedOnceExactly(); }
public void ThreadBoundCredentials() { IDbProvider dbProvider = (IDbProvider)mocks.CreateMock(typeof(IDbProvider)); IDbConnection connection = (IDbConnection)mocks.CreateMock(typeof(IDbConnection)); using (mocks.Ordered()) { Expect.Call(dbProvider.CreateConnection()).Return(connection); Expect.Call(dbProvider.ConnectionString).Return( @"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False"); Expect.Call(connection.ConnectionString = @"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False;User ID=springqa;Password=springqa"); } mocks.ReplayAll(); UserCredentialsDbProvider provider = new UserCredentialsDbProvider(); provider.TargetDbProvider = dbProvider; provider.SetCredentialsForCurrentThread("User ID=springqa", "Password=springqa"); Assert.AreEqual(connection, provider.CreateConnection()); mocks.VerifyAll(); }
public void ThreadBoundCredentials() { IDbProvider dbProvider = mocks.StrictMock<IDbProvider>(); IDbConnection connection = mocks.StrictMock<IDbConnection>(); using (mocks.Ordered()) { Expect.Call(dbProvider.CreateConnection()).Return(connection); Expect.Call(dbProvider.ConnectionString).Return( @"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False"); Expect.Call(connection.ConnectionString = @"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False;User ID=springqa;Password=springqa"); } mocks.ReplayAll(); UserCredentialsDbProvider provider = new UserCredentialsDbProvider(); provider.TargetDbProvider = dbProvider; provider.SetCredentialsForCurrentThread("User ID=springqa", "Password=springqa"); Assert.AreEqual(connection, provider.CreateConnection()); mocks.VerifyAll(); }