示例#1
0
        public void TestUninitializedDatabase()
        {
            var mockFileContext = new Mock <IBacktraceDatabaseFileContext>();

            mockFileContext.Setup(n => n.Clear());
            var database = new BacktraceDatabase(new BacktraceDatabaseSettings(_projectDirectory))
            {
                BacktraceDatabaseFileContext = mockFileContext.Object
            };
            var report = (new Exception("test excetpion")).ToBacktraceReport();

            Assert.DoesNotThrow(() => database.Add(null, null));
            Assert.AreEqual(null, database.Add(report, new Dictionary <string, object>()));
            Assert.DoesNotThrow(() => database.Clear());
            Assert.DoesNotThrow(() => database.Count());

            //mock deleting
            var mockRecord = new Mock <BacktraceDatabaseRecord>();

            mockRecord.Setup(n => n.Delete());
            Assert.DoesNotThrow(() => database.Delete(mockRecord.Object));
            Assert.DoesNotThrow(() => database.Delete(null));

            //test flush methods
            Assert.Throws <ArgumentException>(() => database.Flush());
            Assert.ThrowsAsync <ArgumentException>(() => database.FlushAsync());

            //mock api
            database.SetApi(new BacktraceApi(new BacktraceCredentials("https://www.backtrace.io", "123123")));
            Assert.DoesNotThrow(() => database.Flush());
            Assert.DoesNotThrowAsync(() => database.FlushAsync());
        }
示例#2
0
        public void TestDatabaseRecordLimitConditions()
        {
            var backtraceReport = (new Exception("custom exception")).ToBacktraceReport();

            _backtraceDatabase.Clear();
            for (int i = 0; i < _totalNumberOfReports; i++)
            {
                var record = _backtraceDatabase.Add(backtraceReport, new Dictionary <string, object>(), Types.MiniDumpType.None);
                record.Dispose();
            }
            Assert.AreEqual(_totalNumberOfReports, _backtraceDatabase.Count());
        }
示例#3
0
        public void TestCounter_AfterAddMethod_ShouldReturnValidNumberOfRecords(int numberOfDeduplications)
        {
            _backtraceDatabase.Clear();
            var backtraceReport = (new Exception("custom exception")).ToBacktraceReport();

            for (int i = 0; i < numberOfDeduplications; i++)
            {
                _backtraceDatabase.Add(backtraceReport, null);
            }
            Assert.AreEqual(numberOfDeduplications, _backtraceDatabase.Count());
            var record = _backtraceDatabase.Get().FirstOrDefault();

            Assert.AreEqual(record.Count, numberOfDeduplications);
        }