public void LogWithMultipleCategories() { FormattedDatabaseTraceListener listener = new FormattedDatabaseTraceListener(new SqlDatabase(connectionString), "WriteLog", "AddCategory", new TextFormatter("TEST{newline}TEST")); // need to go through the source to get a TraceEventCache TraceSource source = new TraceSource("notfromconfig", SourceLevels.All); source.Listeners.Add(listener); LogEntry logEntry = new LogEntry(); logEntry.Message = "message"; logEntry.Categories.Add("FormattedCategory"); logEntry.Categories.Add("DictionaryCategory"); logEntry.EventId = 123; logEntry.Priority = 11; logEntry.Severity = TraceEventType.Error; logEntry.Title = "title"; source.TraceData(TraceEventType.Error, 0, logEntry); DatabaseProviderFactory factory = new DatabaseProviderFactory(ConfigurationSourceFactory.Create()); Data.Database db = factory.CreateDefault(); DbCommand command = db.GetSqlStringCommand("SELECT Count(*) FROM Category"); int categoryCount = Convert.ToInt32(db.ExecuteScalar(command)); Assert.AreEqual(2, categoryCount); }
int GetNumberOfLogMessage(string databaseName) { DatabaseProviderFactory factory = new DatabaseProviderFactory(); Data.Database db = ((databaseName == null) || (databaseName.Length == 0)) ? factory.CreateDefault() : factory.Create(databaseName); DbCommand command = db.GetSqlStringCommand("SELECT COUNT(*) FROM Log"); int numMessages = Convert.ToInt32(db.ExecuteScalar(command)); return(numMessages); }
string GetLastLogMessage(string databaseName) { DatabaseProviderFactory factory = new DatabaseProviderFactory(); Data.Database db = ((databaseName == null) || (databaseName.Length == 0)) ? factory.CreateDefault() : factory.Create(databaseName); DbCommand command = db.GetSqlStringCommand("SELECT TOP 1 FormattedMessage FROM Log ORDER BY TimeStamp DESC"); string messageContents = Convert.ToString(db.ExecuteScalar(command)); return(messageContents); }
/// <summary> /// Get the password for a user. /// </summary> /// <param name="userName">User name</param> /// <returns>Password.</returns> public byte[] GetPassword(string userName) { ValidateParam("userName", userName); DBCommandWrapper cmd = this.securityDb.GetStoredProcCommandWrapper( SPGetPassword); cmd.AddInParameter("Name", DbType.String, userName); byte[] password = (byte[])securityDb.ExecuteScalar(cmd); return(password); }
public void ItemRemovedFromCacheCompletelyIfAddFails() { cache.Add("foo", new SerializableClass()); try { cache.Add("foo", new NonSerializableClass()); Assert.Fail("should have thrown exception in Cache.Add"); } catch (Exception) { Assert.IsFalse(cache.Contains("foo")); string isItInDatabaseQuery = "select count(*) from CacheData"; Data.Database db = DatabaseFactory.CreateDatabase("CachingDatabase"); DBCommandWrapper wrapper = db.GetSqlStringCommandWrapper(isItInDatabaseQuery); int count = (int)db.ExecuteScalar(wrapper); Assert.AreEqual(0, count); } }