public void TestRecordEvent() { // Need to make sure that background runner does not attempt to deliver events during // test (and consequently delete them from local storage). Restart Background runner // and sleep until after it checks for events to send. BackgroundRunner.AbortBackgroundThread(); System.Reflection.FieldInfo fieldInfo = typeof(MobileAnalyticsManager).GetField("_backgroundRunner", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); BackgroundRunner backgroundRunner = fieldInfo.GetValue(null) as BackgroundRunner; backgroundRunner.StartWork(); Thread.Sleep(1000); string appID = Guid.NewGuid().ToString(); MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, TestRunner.Credentials, RegionEndpoint.USEast1); SQLiteEventStore eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig()); try { CustomEvent customEvent = new CustomEvent("TestRecordEvent"); customEvent.AddAttribute("LevelName", "Level5"); customEvent.AddAttribute("Successful", "True"); customEvent.AddMetric("Score", 12345); customEvent.AddMetric("TimeInLevel", 64); manager.RecordEvent(customEvent); MonetizationEvent monetizationEvent = new MonetizationEvent(); monetizationEvent.Quantity = 10.0; monetizationEvent.ItemPrice = 2.00; monetizationEvent.ProductId = "ProductId123"; monetizationEvent.ItemPriceFormatted = "$2.00"; monetizationEvent.Store = "Amazon"; monetizationEvent.TransactionId = "TransactionId123"; monetizationEvent.Currency = "USD"; manager.RecordEvent(monetizationEvent); } catch (Exception e) { Console.WriteLine("Catch exception: " + e.ToString()); Assert.Fail(); } // sleep a while to make sure event is stored Thread.Sleep(TimeSpan.FromSeconds(1)); // Event store should have one custom event, one monetization event and one session start event. Assert.AreEqual(3, eventStore.NumberOfEvents(appID)); eventStore.Dispose(); }
public void Cleanup() { BackgroundRunner.AbortBackgroundThread(); }