Ejemplo n.º 1
0
 public AuditQueryableSqlite(string connectionString)
 {
     _source = new SeriLogSQLiteSource
     {
         ConnectionString = connectionString
     };
 }
Ejemplo n.º 2
0
        public void SeriLogSQLite_DataSource_Constructor_Success()
        {
            //---------------------------------Arrange-----------------------------
            var testDBPath    = @"C:\ProgramData\Warewolf\Audits\AuditTestDB.db";
            var testTableName = "Logs";

            var loggerSource = new SeriLogSQLiteSource
            {
                ConnectionString = testDBPath,
                TableName        = testTableName
            };

            //---------------------------------Assert------------------------------
            Assert.AreEqual(testTableName, loggerSource.TableName);
            Assert.AreEqual(testDBPath, loggerSource.ConnectionString);
        }
Ejemplo n.º 3
0
        public void SeriLogPublisher_NewPublisher_Reading_LogData_From_SQLite_Success()
        {
            //-------------------------Arrange------------------------------
            var testDBPath = @"C:\ProgramData\Warewolf\Audits\AuditTestDB.db";

            if (File.Exists(testDBPath))
            {
                File.Delete(testDBPath);
            }

            var testTableName = "Logs";
            var logger        = new LoggerConfiguration().WriteTo.SQLite(testDBPath, testTableName).CreateLogger();

            var mockSeriLogConfig = new Mock <ISeriLogConfig>();

            mockSeriLogConfig.SetupGet(o => o.Logger).Returns(logger);

            var loggerSource = new SeriLogSQLiteSource
            {
                ConnectionString = testDBPath,
                TableName        = testTableName
            };

            using (var loggerConnection = loggerSource.NewConnection(mockSeriLogConfig.Object))
            {
                var loggerPublisher = loggerConnection.NewPublisher();

                var error = new { ServerName = "testServer", Error = "testError" };
                var fatal = new { ServerName = "testServer", Error = "testFatalError" };

                var expectedTestErrorMsgTemplate = GlobalConstants.WarewolfLogsTemplate;
                var expectedTestFatalMsg         = "test infomation {testFatalKey}";
                var testErrorMsg = $"Error From: {@error.ServerName} : {error.Error} ";

                //-------------------------Act----------------------------------

                loggerPublisher.Info(GlobalConstants.WarewolfLogsTemplate, "test message");
                loggerPublisher.Error(expectedTestErrorMsgTemplate, testErrorMsg);
                loggerPublisher.Fatal(expectedTestFatalMsg, @fatal);
            }

            //-------------------------Assert------------------------------------
            var dataFromDb = new TestSqliteDatabase(loggerSource.ConnectionString, loggerSource.TableName);
            var dataList   = dataFromDb.GetPublishedData().ToList();

            var o1 = JObject.Parse(dataList[0].Properties);

            Assert.IsNotNull(dataList[0].Timestamp);
            Assert.AreEqual(null, dataList[0].Exception);
            Assert.AreEqual(LogEventLevel.Information, dataList[0].Level);
            Assert.AreEqual(expected: "test message", actual: o1["Data"].ToString());

            var o2 = JObject.Parse(dataList[1].Properties);

            Assert.IsNotNull(dataList[1].Timestamp);
            Assert.AreEqual(null, dataList[1].Exception);
            Assert.AreEqual(LogEventLevel.Error, dataList[1].Level);
            Assert.AreEqual(expected: "Error From: testServer : testError ", actual: o2["Data"].ToString());

            var o3 = JObject.Parse(dataList[2].Properties);

            Assert.IsNotNull(dataList[2].Timestamp);
            Assert.AreEqual(null, dataList[2].Exception);
            Assert.AreEqual(LogEventLevel.Fatal, dataList[2].Level);
            Assert.AreEqual(expected: "{ ServerName = testServer, Error = testFatalError }", o3["testFatalKey"].ToString());
        }