Ejemplo n.º 1
0
        public void TestEventStore()
        {
            // Create table
            SQLiteEventStore eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig());

            // Insert row
            string eventString = "TestEventStore-dummy-event-string";
            string appId       = Guid.NewGuid().ToString();

            const int EVENT_COUNT = 100;

            // Add events
            for (int i = 0; i < EVENT_COUNT / 2; i++)
            {
                eventStore.PutEvent(eventString, appId);
            }
            long dbFileSizeSmall = eventStore.DatabaseSize;

            for (int i = 0; i < EVENT_COUNT / 2; i++)
            {
                eventStore.PutEvent(eventString, appId);
            }
            long dbFileSizeBigger = eventStore.DatabaseSize;

            Assert.IsTrue(dbFileSizeBigger > dbFileSizeSmall);

            Console.WriteLine("The num of events are {0}", eventStore.NumberOfEvents(appId));
            Assert.AreEqual(EVENT_COUNT, eventStore.NumberOfEvents(appId));

            // Delete EVENT_COUNT / 2 rows
            List <JsonData> allEventList       = eventStore.GetEvents(appId, EVENT_COUNT / 2);
            List <string>   deleteEventsIdList = new List <string>();

            foreach (JsonData eventData in allEventList)
            {
                deleteEventsIdList.Add(eventData["id"].ToString());
            }
            eventStore.DeleteEvent(deleteEventsIdList);

            // check row num again
            Assert.AreEqual(EVENT_COUNT / 2, eventStore.NumberOfEvents(appId));

            // insert EVENT_COUNT / 2 rows again
            for (int i = 0; i < EVENT_COUNT / 2; i++)
            {
                eventStore.PutEvent(eventString, appId);
            }
            Assert.AreEqual(EVENT_COUNT, eventStore.NumberOfEvents(appId));

            // remove all rows
            allEventList       = eventStore.GetEvents(appId, EVENT_COUNT);
            deleteEventsIdList = new List <string>();
            foreach (JsonData eventData in allEventList)
            {
                deleteEventsIdList.Add(eventData["id"].ToString());
            }
            eventStore.DeleteEvent(deleteEventsIdList);
            Assert.AreEqual(0, eventStore.NumberOfEvents(appId));
        }
Ejemplo n.º 2
0
        public void TestRecordEvent()
        {
            string appID = TestRunner.StoredSettings.AppId;
            MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1);

            // sleep a while to make sure event is stored before we delete all event record before now
            Task.Delay(TimeSpan.FromSeconds(10)).Wait();
            SQLiteEventStore eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig());
            // remove all rows submitted before
            var allEventList       = eventStore.GetEvents(appID, 10000);
            var deleteEventsIdList = new List <string>();

            foreach (JsonData eventData in allEventList)
            {
                deleteEventsIdList.Add(eventData["id"].ToString());
            }
            eventStore.DeleteEvent(deleteEventsIdList);
            Assert.AreEqual(0, eventStore.NumberOfEvents(appID));


            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
            Task.Delay(TimeSpan.FromSeconds(10)).Wait();

            // Event store should have one custom event, one monetization event
            long num = eventStore.NumberOfEvents(appID);

            Assert.AreEqual(2, eventStore.NumberOfEvents(appID));
        }