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()); } }
public static async Task <bool> IsAppUsedXDays(this UsageRule self, LocalAnalytics analytics) { var allEvents = await analytics.GetAll(); return(allEvents.GroupByDay().Count() >= self.days); }