public void ExtractUserInfoTestFormat() { var initialUserInfo = new TestUserInfo("os\ab", "cd.ef", true); var processedUserInfo = SqlUtility.ExtractUserInfo(SqlUtility.UserContextInfoText(initialUserInfo)); Assert.AreEqual( initialUserInfo.UserName + "|" + initialUserInfo.Workstation, processedUserInfo.UserName + "|" + processedUserInfo.Workstation); }
public void SendUserInfoInSqlContext_WriteWithUser() { var testUser = new TestUserInfo { IsUserRecognized = true, UserName = "******", Workstation = "HAL9000" }; var sqlExecuter = new OracleSqlExecuter(SqlUtility.ConnectionString, new ConsoleLogProvider(), testUser); string table = GetRandomTableName(); var result = new List<string>(); sqlExecuter.ExecuteSql(new [] { @"CREATE TABLE " + table + " AS SELECT SYS_CONTEXT('USERENV','CLIENT_INFO') ClientInfo FROM DUAL" }); sqlExecuter.ExecuteReader(@"SELECT * FROM " + table, reader => result.Add(reader[0].ToString())); var clientInfo = result.Single(); TestUtility.AssertContains(clientInfo, testUser.UserName, "CLIENT_INFO should contain username."); TestUtility.AssertContains(clientInfo, testUser.Workstation, "CLIENT_INFO should contain client workstation."); Assert.AreEqual(SqlUtility.UserContextInfoText(testUser), clientInfo); }
public void SendUserInfoInSqlContext_NoUser() { var testUser = new TestUserInfo(null, null, false); var sqlExecuter = new MsSqlExecuter(SqlUtility.ConnectionString, new ConsoleLogProvider(), testUser); var result = new List<object>(); sqlExecuter.ExecuteReader("SELECT context_info()", reader => result.Add(reader[0])); Console.WriteLine(result.Single()); Assert.AreEqual(typeof(DBNull), result.Single().GetType()); }
public void SendUserInfoInSqlContext_WriteWithUser() { var testUser = new TestUserInfo("Bob", "HAL9000"); var sqlExecuter = new MsSqlExecuter(SqlUtility.ConnectionString, new ConsoleLogProvider(), testUser); string table = GetRandomTableName(); var result = new List<string>(); sqlExecuter.ExecuteSql(new [] { @"SELECT Context = (CONVERT([varchar](128),left(context_info(),isnull(nullif(charindex(0x00,context_info())-(1),(-1)),(128))),(0))) INTO " + table}); sqlExecuter.ExecuteReader( @"SELECT * FROM " + table, reader => result.Add(reader[0].ToString())); Console.WriteLine(result.Single()); Assert.IsTrue(result.Single().Contains(testUser.UserName), "context_info should contain username."); Assert.IsTrue(result.Single().Contains(testUser.Workstation), "context_info should contain client workstation."); }
public void SendUserInfoInSqlContext_ReadWithUser() { var testUser = new TestUserInfo("Bob", "HAL9000"); var sqlExecuter = NewSqlExecuter(testUser); var result = new List<string>(); sqlExecuter.ExecuteReader( @"SELECT (CONVERT([varchar](128),left(context_info(),isnull(nullif(charindex(0x00,context_info())-(1),(-1)),(128))),(0)))", reader => result.Add(reader[0].ToString())); Console.WriteLine(result.Single()); Assert.IsTrue(result.Single().Contains(testUser.UserName), "context_info should contain username."); Assert.IsTrue(result.Single().Contains(testUser.Workstation), "context_info should contain client workstation."); }