Exemplo n.º 1
0
        public void Can_Get_Total_Number_For_Filtered_Records()
        {
            // Setup
            _store.Initialize();
            var record1 = new LogRecord { RecordNumber = 1 };
            var record2 = new LogRecord { RecordNumber = 2 };
            var record3 = new LogRecord { RecordNumber = 3 };

            record1.Fields.Add(new LogField { FieldName = "f1", StringValue = "Pass" });
            record2.Fields.Add(new LogField { FieldName = "f1", StringValue = "Fail" });
            record3.Fields.Add(new LogField { FieldName = "f1", StringValue = "Pass" });

            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);
            _store.StoreLogRecord(record3);

            var filter = new List<LogFilter>(
                new LogFilter[] {
                    new LogFilter { FilteredFieldName = "f1", TextFilter = "Pass", FilterType = LogFilterType.Text, ExclusiveFilter = false } });

            // Act
            int count = _store.GetTotalRecordCount(filter, new Guid());

            // Verify
            Assert.AreEqual(2, count, "Total record count was incorrect");
        }
Exemplo n.º 2
0
        public Guid ParseLog(string logSource)
        {
            int currentRecordNumber = 1;
            string lineText;
            Guid sessionId = Guid.NewGuid(); // New session ID Per parse call

            // Make sure we have a valid delegate to store records with
            if (StoreRecordMethod == null)
                throw new InvalidOperationException("No method assigned for storing log records");

            // Make sure the log source is a valid file
            if (!File.Exists(logSource))
                throw new LogSourceNotAvailableException(string.Format("The log file '{0}' does not exist", logSource));

            // Open the file passed in by the log source
            var reader = File.OpenText(logSource);

            // Each line represents a separate log record, each field is delimited with a pipe
            while ((lineText = reader.ReadLine()) != null)
            {
                var record = new LogRecord { SessionId = sessionId, RecordNumber = currentRecordNumber++ };

                string[] fields = lineText.Split('|');

                for (int x = 0; x < fields.Length; x++)
                {
                    DateTime parsedDate;
                    if (!DateTime.TryParse(fields[x], out parsedDate))
                        record.Fields.Add(new LogField { StringValue = fields[x], FieldName = "Field " + x });
                    else
                        record.Fields.Add(new LogField { StringValue = fields[x], DateValue = parsedDate, FieldName = "Field " + x });
                }

                StoreRecordMethod(record);
            }

            return sessionId;
        }
Exemplo n.º 3
0
 public void StoreLogRecord(LogRecord record)
 {
     using (var session = _store.OpenSession())
     {
         session.Store(record);
         session.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public void Can_Get_Total_Number_Of_Records()
        {
            // Setup
            _store.Initialize();
            var record1 = new LogRecord();
            var record2 = new LogRecord();
            var record3 = new LogRecord();
            var record4 = new LogRecord();
            var record5 = new LogRecord();
            var record6 = new LogRecord();

            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);
            _store.StoreLogRecord(record3);
            _store.StoreLogRecord(record4);
            _store.StoreLogRecord(record5);
            _store.StoreLogRecord(record6);

            // Act
            int count = _store.GetTotalRecordCount(null, new Guid());

            // Verify
            Assert.AreEqual(6, count, "Total count was incorrect");
        }
Exemplo n.º 5
0
        public void Store_Retrieves_Records_In_Specified_Page()
        {
            // Setup
            _store.Initialize();
            var record1 = new LogRecord { RecordNumber = 1 };
            var record2 = new LogRecord { RecordNumber = 2 };
            var record3 = new LogRecord { RecordNumber = 3 };
            var record4 = new LogRecord { RecordNumber = 4 };
            var record5 = new LogRecord { RecordNumber = 5 };
            var record6 = new LogRecord { RecordNumber = 6 };

            // Act
            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);
            _store.StoreLogRecord(record3);
            _store.StoreLogRecord(record4);
            _store.StoreLogRecord(record5);
            _store.StoreLogRecord(record6);
            IList<LogRecord> result = _store.GetFilteredRecords(null, new Guid(), 2, 2);

            // Verify
            Assert.AreEqual(2, result.Count, "Result contained an incorrect number of elements");
            Assert.AreEqual(record3.RecordNumber, result[0].RecordNumber, "First result was incorrect");
            Assert.AreEqual(record4.RecordNumber, result[1].RecordNumber, "Second result was incorrect");
        }
Exemplo n.º 6
0
        public void Store_Only_Retrieves_Log_Records_With_Passed_In_Session_Id()
        {
            // Setup
            _store.Initialize();
            Guid session1 = Guid.NewGuid(), session2 = Guid.NewGuid();

            var record1 = new LogRecord { SessionId = session1, RecordNumber = 1 };
            var record2 = new LogRecord { SessionId = session2, RecordNumber = 2 };
            var record3 = new LogRecord { SessionId = session1, RecordNumber = 3 };

            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);
            _store.StoreLogRecord(record3);

            // Act
            IList<LogRecord> result = _store.GetFilteredRecords(null, session1, 2, 1);

            // Verify
            Assert.IsNotNull(result, "Null list was returned");
            Assert.AreEqual(2, result.Count, "List returned an incorrect number of log records");
            Assert.IsTrue(result.Any(x => x.RecordNumber == record1.RecordNumber), "List did not contain record1");
            Assert.IsTrue(result.Any(x => x.RecordNumber == record3.RecordNumber), "List did not contain record3");
        }
Exemplo n.º 7
0
        public void Store_Can_Filter_Records_By_Inclusive_Text()
        {
            // Setup
            _store.Initialize();
            var record1 = new LogRecord { RecordNumber = 1 };
            var record2 = new LogRecord { RecordNumber = 2 };

            record1.Fields.Add(new LogField { FieldName = "f1", StringValue = "Pass" });
            record1.Fields.Add(new LogField { FieldName = "f2", StringValue = "Fail" });
            record2.Fields.Add(new LogField { FieldName = "f1", StringValue = "Fail" });
            record2.Fields.Add(new LogField { FieldName = "f2", StringValue = "Pass" });

            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);

            var filter = new List<LogFilter>(
                new LogFilter[] {
                    new LogFilter { FilteredFieldName = "f2", TextFilter = "Pass", FilterType = LogFilterType.Text, ExclusiveFilter = false } });

            // Act
            var result = _store.GetFilteredRecords(filter, new Guid(), 2, 1);

            // Verify
            Assert.AreEqual(1, result.Count, "Incorrect number of records returned");
            Assert.AreEqual(record2.RecordNumber, result[0].RecordNumber, "Incorrect record returned");
        }
Exemplo n.º 8
0
        public void Store_Can_Filter_Records_By_Inclusive_Date_Range()
        {
            // Setup
            _store.Initialize();
            var record1 = new LogRecord { RecordNumber = 1 };
            var record2 = new LogRecord { RecordNumber = 2 };

            record1.Fields.Add(new LogField { FieldName = "f1", DateValue = new DateTime(2011, 1, 1) });
            record1.Fields.Add(new LogField { FieldName = "f2", DateValue = new DateTime(2011, 3, 1) });
            record2.Fields.Add(new LogField { FieldName = "f1", DateValue = new DateTime(2011, 3, 1) });
            record2.Fields.Add(new LogField { FieldName = "f2", DateValue = new DateTime(2011, 1, 1) });

            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);

            var filter = new List<LogFilter>(
                new LogFilter[]
                {
                    new LogFilter
                    {
                        FilteredFieldName = "f2",
                        StartDate = new DateTime(2010, 12, 1),
                        EndDate = new DateTime(2011, 2, 1),
                        FilterType = LogFilterType.Date,
                        ExclusiveFilter = false
                    }
                }
            );

            // Act
            var result = _store.GetFilteredRecords(filter, new Guid(), 2, 1);

            // Verify
            Assert.AreEqual(1, result.Count, "Incorrect number of records returned");
            Assert.AreEqual(record2.RecordNumber, result[0].RecordNumber, "Incorrect record returned");
        }
Exemplo n.º 9
0
        public void Can_Store_And_Retrieve_Log_Records()
        {
            // Setup
            var record1 = new LogRecord { RecordNumber = 1 };
            var record2 = new LogRecord { RecordNumber = 2 };
            _store.Initialize();

            // Act
            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);
            IList<LogRecord> result = _store.GetFilteredRecords(null, new Guid(), 2, 1);

            // Verify
            Assert.IsNotNull(result, "Store returned a null result");
            Assert.AreEqual(2, result.Count, "Store returned an incorrect number of records");
            Assert.AreEqual(record1.RecordNumber, result[0].RecordNumber, "First record returned by the store was incorrect");
            Assert.AreEqual(record2.RecordNumber, result[1].RecordNumber, "Second record returned by the store was incorect");
        }
Exemplo n.º 10
0
        public void Can_Get_Total_Number_Of_Records_For_Session()
        {
            // Setup
            _store.Initialize();
            Guid session1 = Guid.NewGuid(), session2 = Guid.NewGuid();
            var record1 = new LogRecord { SessionId = session1 };
            var record2 = new LogRecord { SessionId = session2 };
            var record3 = new LogRecord { SessionId = session2 };

            _store.StoreLogRecord(record1);
            _store.StoreLogRecord(record2);
            _store.StoreLogRecord(record3);

            // Act
            int s1Count = _store.GetTotalRecordCount(null, session1);
            int s2Count = _store.GetTotalRecordCount(null, session2);

            // Verify
            Assert.AreEqual(1, s1Count, "Total count for session 1 was incorrect");
            Assert.AreEqual(2, s2Count, "Total count for session 2 was incorrect");
        }