private async Task TestAppFlowWithStore(int eventCount, AppFlowToStore appFlow) { Assert.Empty(await appFlow.store.GetAllKeys()); var t1 = Log.MethodEntered($"Track {eventCount} events via appFlow.TrackEvent"); for (int i = 0; i < eventCount; i++) { appFlow.TrackEvent(EventConsts.catMethod, "action " + i); } Log.MethodDone(t1); var t2 = Log.MethodEntered("GetAll events in store"); var events = await appFlow.store.GetAll(); Assert.Equal(eventCount, events.Count()); Log.MethodDone(t2); var t3 = Log.MethodEntered("GetAll again but for specific category"); var filtered = events.Filter(x => x.cat == EventConsts.catMethod); Assert.Equal(filtered, events); Assert.Empty(events.Filter(x => x.cat == EventConsts.catUi)); Log.MethodDone(t3); }
public async Task TestLocalAnalytics() { int eventCount = 10000; // Create a LocalAnalytics instance that uses only memory stores for testing: LocalAnalytics localAnalytics = new LocalAnalytics(new InMemoryKeyValueStore()); localAnalytics.createStoreFor = (_) => new InMemoryKeyValueStore().GetTypeAdapter <AppFlowEvent>(); // Pass this local analytics system to the app flow impl. as the target store: AppFlowToStore appFlow = new AppFlowToStore(localAnalytics); await TestAppFlowWithStore(eventCount, appFlow); // Run the tests // Get the store that contains only the events of a specific category: var catMethodStore = localAnalytics.GetStoreForCategory(EventConsts.catMethod); { // Check that all events so far are of the method category: var all = await localAnalytics.GetAll(); var allForCat = await catMethodStore.GetAll(); Assert.Equal(all.Count(), allForCat.Count()); } { // Add an event of a different category and check that the numbers again: appFlow.TrackEvent(EventConsts.catUi, "Some UI event"); var all = await localAnalytics.GetAll(); var allForCat = await catMethodStore.GetAll(); Assert.Equal(all.Count(), allForCat.Count() + 1); var catUiStore = localAnalytics.GetStoreForCategory(EventConsts.catUi); Assert.Single(await catUiStore.GetAll()); } }