public void Setup() { BeforeSetup(); database = GameObject.AddComponent <BacktraceDatabaseMock>(); database.Configuration = null; AfterSetup(false); }
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()); }
public void Setup() { //mock file context var mockFileContext = new Mock <IBacktraceDatabaseFileContext>(); mockFileContext.Setup(n => n.GetRecords()) .Returns(new List <FileInfo>()); mockFileContext.Setup(n => n.Clear()); ////mock api var mockApi = new Mock <IBacktraceApi>(); mockApi.Setup(n => n.Send(It.IsAny <BacktraceData>())) .Returns(BacktraceResult.OnError(It.IsAny <BacktraceReport>(), new Exception("error"))); var backtraceDatabaseSettings = new BacktraceDatabaseSettings(_projectDirectory) { RetryLimit = _batchLimit, RetryBehavior = Types.RetryBehavior.NoRetry, AutoSendMode = false, DeduplicationStrategy = DeduplicationStrategy.LibraryName | DeduplicationStrategy.Classifier | DeduplicationStrategy.Message }; _backtraceDatabase = new BacktraceDatabase(backtraceDatabaseSettings) { BacktraceApi = mockApi.Object, BacktraceDatabaseFileContext = mockFileContext.Object }; _backtraceDatabase.Start(); }
/// <summary> /// Initialize new client instance with BacktraceCredentials /// </summary> /// <param name="backtraceCredentials">Backtrace credentials to access Backtrace API</param> /// <param name="attributes">Additional information about current application</param> /// <param name="databaseDirectory">Database path</param> /// <param name="reportPerMin">Number of reports sending per one minute. If value is equal to zero, there is no request sending to API. Value have to be greater than or equal to 0</param> public BacktraceBase( BacktraceCredentials backtraceCredentials, Dictionary <string, T> attributes = null, string databaseDirectory = "", uint reportPerMin = 3) { _attributes = attributes ?? new Dictionary <string, T>(); _database = new BacktraceDatabase <T>(databaseDirectory); _backtraceApi = new BacktraceApi <T>(backtraceCredentials); _reportWatcher = new ReportWatcher <T>(reportPerMin); }
/// <summary> /// Setup client behaviour - attributes, events /// </summary> private void SetupBacktraceLibrary() { //setup tls support for tested server ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | (SecurityProtocolType)0x00000300 | (SecurityProtocolType)0x00000C00; //create Backtrace library configuration var configuartion = new BacktraceClientConfiguration(credentials) { ReportPerMin = 0 }; //create Backtrace database var database = new BacktraceDatabase(databaseSettings); //setup new client backtraceClient = new BacktraceClient(configuartion, database) { UnpackAggregateExcetpion = true }; //handle all unhandled application exceptions backtraceClient.HandleApplicationException(); //Add new scoped attributes backtraceClient.Attributes["ClientAttributeNumber"] = 1; backtraceClient.Attributes["ClientAttributeString"] = "string attribute"; backtraceClient.Attributes["ClientAttributeCustomClass"] = new { Name = "Backtrace", Type = "Library" }; backtraceClient.Attributes["ComplexObject"] = new Dictionary <string, Uri>() { { "backtrace.io", new Uri("http://backtrace.io") }, { "Google url", new Uri("http://google.com") } }; //Add your own handler to client API backtraceClient.BeforeSend = (BacktraceData model) => { var data = model; data.Attributes.Add("eventAtrtibute", "EventAttributeValue"); if (data.Classifier == null || !data.Classifier.Any()) { data.Attachments.Add("path to attachment"); } return(data); }; }
public void Setup() { _lastRecord = GetRecord(); //get project path string projectPath = Path.GetTempPath(); //setup credentials var credentials = new BacktraceCredentials("https://validurl.com/", "validToken"); //mock api var serverUrl = $"{credentials.BacktraceHostUri.AbsoluteUri}post?format=json&token={credentials.Token}"; var mockHttp = new MockHttpMessageHandler(); mockHttp.When(serverUrl) .Respond("application/json", "{'object' : 'aaa'}"); var api = new BacktraceApi(credentials, 0) { HttpClient = mockHttp.ToHttpClient() }; //mock file context var mockFileContext = new Mock <IBacktraceDatabaseFileContext>(); mockFileContext.Setup(n => n.GetRecords()) .Returns(new List <FileInfo>()); mockFileContext.Setup(n => n.RemoveOrphaned(It.IsAny <IEnumerable <BacktraceDatabaseRecord> >())); //mock cache var mockCacheContext = new Mock <IBacktraceDatabaseContext>(); mockCacheContext.Setup(n => n.Add(It.IsAny <BacktraceData>(), MiniDumpType.None)) .Callback(() => { mockCacheContext.Object.Add(_lastRecord); _lastRecord = GetRecord(); }) .Returns(_lastRecord); var database = new BacktraceDatabase(new BacktraceDatabaseSettings(projectPath) { RetryBehavior = RetryBehavior.NoRetry }) { BacktraceDatabaseContext = mockCacheContext.Object, BacktraceDatabaseFileContext = mockFileContext.Object, }; //setup new client _backtraceClient = new BacktraceClient(backtraceCredentials: credentials, database: database, reportPerMin: 0) { BacktraceApi = api }; }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { Trace.WriteLine("Backtrace Universal Windows Platform Example"); Trace.WriteLine($"Used database path: {localFolder.Path}"); //Client configuration var config = new BacktraceClientConfiguration(credentials); //database instance var database = new BacktraceDatabase(localFolder.Path); //client initialization backtraceClient = new BacktraceClient(config, database); this.InitializeComponent(); this.Suspending += OnSuspending; }
/// <summary> /// Setup client behaviour - attributes, events /// </summary> private void SetupBacktraceLibrary() { //create Backtrace library configuration var configuartion = new BacktraceClientConfiguration(credentials) { ReportPerMin = 0 }; //create Backtrace database var database = new BacktraceDatabase(databaseSettings); //setup new client backtraceClient = new BacktraceClient(configuartion, database); //handle all unhandled application exceptions backtraceClient.HandleApplicationException(); //Add new scoped attributes backtraceClient.Attributes["ClientAttributeNumber"] = 1; backtraceClient.Attributes["ClientAttributeString"] = "string attribute"; backtraceClient.Attributes["ClientAttributeCustomClass"] = new { Name = "Backtrace", Type = "Library" }; backtraceClient.Attributes["ComplexObject"] = new Dictionary <string, Uri>() { { "backtrace.io", new Uri("http://backtrace.io") }, { "Google url", new Uri("http://google.com") } }; backtraceClient.BeforeSend = (BacktraceData data) => { string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); System.Diagnostics.Trace.WriteLine(json); return(data); }; //Add your own handler to client API backtraceClient.BeforeSend = (BacktraceData model) => { var data = model; data.Attributes.Add("eventAtrtibute", "EventAttributeValue"); if (data.Classifier == null || !data.Classifier.Any()) { data.Attachments.Add("path to attachment"); } return(data); }; }
protected override void OnCreate(Bundle savedInstanceState) { //setup database // we get external storage directory and special directory created for databse - Backtrace directory string directoryPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Backtrace"); var database = new BacktraceDatabase(new BacktraceDatabaseSettings(directoryPath)); //setup client configuration var credentials = new BacktraceCredentials(ApplicationSettings.Host, ApplicationSettings.Token); var clientConfiguration = new BacktraceClientConfiguration(credentials); // Initialize new BacktraceClient BacktraceClient client = new BacktraceClient(clientConfiguration, database); // Send async report to a server with custom client message var result = client.SendAsync("Hello from Xamarin").Result; base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); }
static void Main() { //create Backtrace library configuration var configuartion = new BacktraceClientConfiguration(credentials) { ReportPerMin = 0 }; //create Backtrace - var database = new BacktraceDatabase(databaseSettings); //initialize new BacktraceClient backtraceClient = new BacktraceClient(configuartion, database); //Setting application exceptions backtraceClient.HandleApplicationException(); Application.EnableVisualStyles(); Application.ThreadException += backtraceClient.HandleApplicationThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
public void Setup() { //mock file context var mockFileContext = new Mock <IBacktraceDatabaseFileContext>(); mockFileContext.Setup(n => n.GetRecords()) .Returns(new List <FileInfo>()); mockFileContext.Setup(n => n.Clear()); var backtraceDatabaseSettings = new BacktraceDatabaseSettings(_projectDirectory) { MaxRecordCount = _totalNumberOfReports, RetryBehavior = Types.RetryBehavior.NoRetry }; _backtraceDatabase = new BacktraceDatabase(backtraceDatabaseSettings) { BacktraceDatabaseFileContext = mockFileContext.Object }; //start database _backtraceDatabase.Start(); }
public virtual void Setup() { //get project path string projectPath = Path.GetTempPath(); //mock api var mockApi = new Mock <IBacktraceApi>(); mockApi.Setup(n => n.Send(It.IsAny <BacktraceData>())) .Returns(new BacktraceResult()); //mock file context var mockFileContext = new Mock <IBacktraceDatabaseFileContext>(); mockFileContext.Setup(n => n.GetRecords()) .Returns(new List <FileInfo>()); //mock cache var mockCacheContext = new Mock <IBacktraceDatabaseContext>(); mockFileContext.Setup(n => n.RemoveOrphaned(It.IsAny <IEnumerable <BacktraceDatabaseRecord> >())); mockFileContext.Setup(n => n.Clear()); var settings = new BacktraceDatabaseSettings(projectPath) { RetryBehavior = RetryBehavior.NoRetry, AutoSendMode = false, //we don't want to test timers MaxRecordCount = 100, RetryLimit = 3 }; _database = new BacktraceDatabase(settings) { BacktraceDatabaseContext = new MockBacktraceDatabaseContext(projectPath, 3, RetryOrder.Stack), BacktraceDatabaseFileContext = mockFileContext.Object, BacktraceApi = mockApi.Object }; }
public void TestDatabaseInitalizationConditions() { //initialize disabled database Assert.DoesNotThrow(() => { var database = new BacktraceDatabase(); database.Start(); }); Assert.DoesNotThrow(() => { var database = new BacktraceDatabase(new BacktraceDatabaseSettings(string.Empty)); database.Start(); }); //initialize database with invalid arguments Assert.Throws <ArgumentException>(() => new BacktraceDatabase(new BacktraceDatabaseSettings("not existing directory"))); Assert.Throws <ArgumentException>(() => new BacktraceDatabase(new BacktraceDatabaseSettings(_projectDirectory) { RetryLimit = 0 })); //initialize database with valid settings Assert.DoesNotThrow(() => new BacktraceDatabase(new BacktraceDatabaseSettings(_projectDirectory))); }
static void Main(string[] args) { //setup tls support for tested server ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | (SecurityProtocolType)0x00000300 | (SecurityProtocolType)0x00000C00; var credentials = new BacktraceCredentials(ApplicationSettings.Host, ApplicationSettings.Token); // create Backtrace library configuration var configuartion = new BacktraceClientConfiguration(credentials) { ReportPerMin = 0 }; //initialize new BacktraceClient with custom configuration section readed from file App.config //Client will be initialized with values stored in default section name "BacktraceCredentials" BacktraceClient backtraceClientWithSectionCredentials = new BacktraceClient(); //create new backtrace database settings BacktraceDatabaseSettings databaseSettings = new BacktraceDatabaseSettings(ApplicationSettings.DatabasePath); //create Backtrace database var database = new BacktraceDatabase(databaseSettings); //setup new client var backtraceClient = new BacktraceClient(credentials, databaseSettings); //Add new scoped attributes backtraceClient.Attributes["ClientAttributeNumber"] = 1; backtraceClient.Attributes["ClientAttributeString"] = "/string attribute"; backtraceClient.Attributes["ClientAttributeCustomClass"] = new { Name = "Backtrace", Type = "Library" }; //Add your own handler to client API backtraceClient.BeforeSend = (BacktraceData model) => { var data = model; data.Attributes.Add("eventAtrtibute", "EventAttributeValue"); return(data); }; //Report a new exception from current application try { try { int.Parse("abc"); } catch (Exception inner) { try { var openLog = File.Open("Not existing path", FileMode.Open); } catch { throw new FileNotFoundException("OutterException", inner); } } } catch (Exception e) { var report = new BacktraceReport( exception: e, attributes: new Dictionary <string, object>() { { "AttributeString", "string" } }, attachmentPaths: new List <string>() { @"path to file attachment", @"patch to another file attachment" } ); var response = backtraceClient.Send(report); } //Report a new message var sendResult = backtraceClient.Send("Client message"); }