public void integration_test_given_filters_and_named_trackers_aggregated_results_match()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 17);
            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.KidsCount, 7);
            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 27);

            Configurator.FlushTrackers();

            var report = Container<TrackerWithCountProperties>.Where(new CustomerFilter { Gender = "M", StoreID = filter1.StoreID})
                           .Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 6 , 0)),
                                   DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)));

            Debug.Write("Report Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(44, report.Results[0].Tracker.ElderlyCount);
            Assert.AreEqual(7, report.Results[0].Tracker.KidsCount);
        }
        public void integration_test_given_filters_aggregated_results_match()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            Container<CustomerVisitTracker>.Where(filter1).IncrementBy(18);
            Configurator.FlushTrackers();

            var report = Container<CustomerVisitTracker>.Where(filter1).Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 6, 0)),DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)));

            Debug.Write("Report Count: " + report.Results.Count()
                            + " StoreId: " + filter1.StoreID);

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(1, report.Results[0].Occurrence);
            Assert.AreEqual(18, report.Results[0].Total);
        }
        public void integration_test_given_filters_and_named_trackers_with5_minute_resolution_aggregated_results_match_for_partial_filters_with_multiple_records_mulitple_resolution()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            var now = DateTime.UtcNow;

            Container<PerformanceTracker>.Where(filter1).IncrementBy(11);
            Configurator.FlushTrackers();

            var report = Container<PerformanceTracker>.Where(filter1).Report(DateTime.UtcNow.Subtract(new TimeSpan(5000, 1, 0, 0)),DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)), ReportResolution.Minute, TimeSpan.Zero);

            Debug.Write("Report Count: " + report.Results.Count()
                          + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(now.Day, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Minute, report.Resolution);

            //five minute
            report = Container<PerformanceTracker>.Where(filter1)
                        .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                                now.Add(new TimeSpan(1, 0, 0)),
                                ReportResolution.FiveMinute);

            Debug.Write("Report2 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(now.Day, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.FiveMinute, report.Resolution);

            //day
            report = Container<PerformanceTracker>.Where(filter1)
                        .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                                now.Add(new TimeSpan(1, 0, 0)),
                                ReportResolution.Day);

            Debug.Write("Report3 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(now.Day, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Day, report.Resolution);

            //month
            report = Container<PerformanceTracker>.Where(filter1)
                        .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                                now.Add(new TimeSpan(1, 0, 0)),
                                ReportResolution.Month);

            Debug.Write("Report4 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Month, report.Resolution);

            //year
            report = Container<PerformanceTracker>.Where(filter1)
                        .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                                now.Add(new TimeSpan(1, 0, 0)),
                                ReportResolution.Year);

            Debug.Write("Report5 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Year, report.Resolution);
        }
        public void integration_test_given_filters_and_named_trackers_aggregated_results_match_for_partial_filters_with_multiple_records_default()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            Container<CustomerVisitTracker>.Where(filter1).IncrementBy(16);

            Configurator.FlushTrackers();

            var report = Container<CustomerVisitTracker>.Where(new CustomerFilter { Gender = "M", }).Report(DateTime.UtcNow.Subtract(new TimeSpan(5000, 1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)), ReportResolution.Year);

            Debug.Write("Report Count: " + report.Results.Count()
                           + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results[0].Total >= 16);
            Assert.IsTrue(report.Results[0].Occurrence >= 1);
            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(ReportResolution.Year, report.Resolution);
        }
        public void integration_test_given_filters_and_named_trackers_aggregated_results_match_with_time_offset()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            var startHour = DateTime.UtcNow.Hour;
            Container<CustomerVisitTracker>.Where(filter1).IncrementBy(19);

            Configurator.FlushTrackers();

            var report = Container<CustomerVisitTracker>.Where(filter1)
                .Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 6, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)), ReportResolution.Hour);

            Debug.Write("Report Count: " + report.Results.Count()
                           + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(ReportResolution.Hour, report.Resolution);

            var endHour = DateTime.UtcNow.Hour;
            report = Container<CustomerVisitTracker>.Where(new CustomerFilter
            {
                Gender = "M",
            }).Report(DateTime.UtcNow.Subtract(new TimeSpan(((startHour != endHour)? 2:1), 6, 0)),
                      DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)), ReportResolution.Hour,
                      new TimeSpan(-7, 0, 0));

            Debug.Write("Report2 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.IsTrue(report.Results[0].Total >= 19);
            Assert.IsTrue(report.Results[0].Occurrence >= 1);
            Assert.AreEqual(ReportResolution.Hour, report.Resolution);
        }
            public void GivenAQueryWithTwoFilters_WhenBuildingTheList_AppropriateFiltersAreConverted()
            {
                var filter1 = new CustomerFilter
                {
                    Environment_ServerName = "Env1",
                    Gender = "M",
                    State = "CA",
                    StoreID = "1234"
                };

                var filter2 = new CustomerFilter
                {
                    Environment_ServerName = "Env2",
                    Gender = "F",
                    State = "CT",
                    StoreID = "4231"
                };

                var visitTrackerReportSpecification =
                    new ReportSpecification<CustomerFilter, CustomerVisitTracker>(DateTime.UtcNow, DateTime.UtcNow,
                        ReportResolution.Day, filter1, filter2);

                Assert.AreEqual(2, visitTrackerReportSpecification.FilterCombinations.Count());
                Assert.AreEqual(1, visitTrackerReportSpecification.FilterCombinations.ElementAt(0).Filters.Count());
                Assert.AreEqual(visitTrackerReportSpecification.FilterCombinations.Count(fs => fs.Filters.Contains(
                    string.Format("ENVIRONMENT_SERVERNAME::ENV1,,GENDER::M,,STATE::CA,,STOREID::1234"))),1);
            }
        public void integration_test_given_filters_and_named_trackers_aggregated_results_match_for_partial_filters_hour_resolution()
        {
            string storeId = Guid.NewGuid().ToString("D");
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = storeId
            };
            var startHour = DateTime.UtcNow.Hour;
            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 74);
            Thread.Sleep(new TimeSpan(0, 0, 5, 0));
            var endHour = DateTime.UtcNow.Hour;
            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.KidsCount, 54);
            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 24);

            Configurator.FlushTrackers();

            var report = Container<TrackerWithCountProperties>.Where(new CustomerFilter{StoreID = storeId}).Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 6, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)));

            Debug.Write("Report Count: " + report.Results.Count()
                           + " StoreId: " + filter1.StoreID);

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(startHour != endHour ? 24 : 98, report.Results[0].Tracker.ElderlyCount);
            Assert.AreEqual(54, report.Results[0].Tracker.KidsCount);
        }
            IntegrationTest_GivenFiltersAndNamedTrackersWith5MinuteResolution_AggreagetedResultsMatchForPartialFiltersWithMultipleRecordsDefaultResolution
            ()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            Configurator.Initialize(
                new Settings
                {
                    Persister = new PersistToMongo("mongodb://localhost:9001/Graphene",_fakeLogger),
                    ReportGenerator = new MongoReportGenerator("mongodb://localhost:9001/Graphene", _fakeLogger)
                }
                );

            Container<PerformanceTracker>.Where(filter1).IncrementBy(10);

            Configurator.ShutDown();

            AggregationResults<PerformanceTracker> report = Container<PerformanceTracker>.Where(new CustomerFilter
            {
                Gender = "M",
            }).Report(DateTime.UtcNow.Subtract(new TimeSpan(5000, 1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)));

            Assert.IsTrue(report.Results.Count() >= 1);
            Assert.AreEqual(DateTime.UtcNow.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(0, report.Results[0].MesurementTimeUtc.Minute);
            Assert.AreEqual(0, report.Results[0].MesurementTimeUtc.Hour);

            Assert.AreEqual(ReportResolution.Year, report.Resolution);
        }
        public void IntegrationTest_GivenFiltersAndNamedTrackers_AggreagetedResultsMatchForPartialFilters()
        {
            string storeId = Guid.NewGuid().ToString("D");
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = storeId
            };

            Configurator.Initialize(
                new Settings
                {
                    Persister = new PersistToMongo("mongodb://localhost:27017/Graphene1",_fakeLogger),
                    ReportGenerator = new MongoReportGenerator("mongodb://localhost:27017/Graphene1", _fakeLogger)
                }
                );

            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 10);
            Thread.Sleep(new TimeSpan(0, 0, 5, 0));
            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.KidsCount, 5);
            Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 2);
            
            Configurator.ShutDown();

            AggregationResults<TrackerWithCountProperties> report = Container<TrackerWithCountProperties>.Where(new CustomerFilter
            {
                StoreID = storeId
            }).Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)));

            System.Diagnostics.Debug.Write(report.Results.Count());

            Assert.IsTrue(report.Results.Count() >= 1);
            Assert.AreEqual(12, report.Results[0].Tracker.ElderlyCount);
            Assert.AreEqual(5, report.Results[0].Tracker.KidsCount);
        }
        public void IntegrationTest_GivenFilters_AggreagetedResultsMatch()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            Configurator.Initialize(
                new Settings
                {
                    Persister = new PersistToMongo("mongodb://localhost:27017/Graphene", _fakeLogger),
                    ReportGenerator = new MongoReportGenerator("mongodb://localhost:27017/Graphene", _fakeLogger)
                }
                );

            Container<CustomerVisitTracker>.Where(filter1).IncrementBy(10);

            Configurator.ShutDown();

            AggregationResults<CustomerVisitTracker> report =
                Container<CustomerVisitTracker>.Where(filter1)
                    .Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)));

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(1, report.Results[0].Occurrence);
            Assert.AreEqual(10, report.Results[0].Total);
        }
        public void GivenAQueryWithTwoFilters_WhenBuildingTheList_AppropriateFiltersAreConverted()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender = "M",
                State = "CA",
                StoreID = "1234"
            };

            var filter2 = new CustomerFilter
            {
                Environment_ServerName = "Env2",
                Gender = "F",
                State = "CT",
                StoreID = "4231"
            };

            var visitTrackerReportSpecification =
                new ReportSpecification<CustomerFilter, CustomerVisitTracker>(DateTime.Now, DateTime.UtcNow,
                    ReportResolution.Minute, filter1, filter2);

            Assert.AreEqual(2, visitTrackerReportSpecification.FilterCombinations.Count());
            Assert.AreEqual(1, visitTrackerReportSpecification.FilterCombinations.ElementAt(0).Filters.Count());
        }
        public void integration_test_given_filters_and_named_trackers_with5_minute_resolution_aggregated_results_match_for_partial_filters_with_multiple_records_mulitple_resolution()
        {
            var filter1 = new CustomerFilter
            {
                Environment_ServerName = "Env1",
                Gender  = "M",
                State   = "CA",
                StoreID = Guid.NewGuid().ToString("D")
            };

            var now = DateTime.UtcNow;

            Container <PerformanceTracker> .Where(filter1).IncrementBy(11);

            Configurator.FlushTrackers();

            var report = Container <PerformanceTracker> .Where(filter1).Report(DateTime.UtcNow.Subtract(new TimeSpan(5000, 1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0)), ReportResolution.Minute, TimeSpan.Zero);

            Debug.Write("Report Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(now.Day, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Minute, report.Resolution);

            //five minute
            report = Container <PerformanceTracker> .Where(filter1)
                     .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                             now.Add(new TimeSpan(1, 0, 0)),
                             ReportResolution.FiveMinute);

            Debug.Write("Report2 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(now.Day, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.FiveMinute, report.Resolution);

            //day
            report = Container <PerformanceTracker> .Where(filter1)
                     .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                             now.Add(new TimeSpan(1, 0, 0)),
                             ReportResolution.Day);

            Debug.Write("Report3 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(now.Day, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Day, report.Resolution);

            //month
            report = Container <PerformanceTracker> .Where(filter1)
                     .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                             now.Add(new TimeSpan(1, 0, 0)),
                             ReportResolution.Month);

            Debug.Write("Report4 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(now.Month, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Month, report.Resolution);

            //year
            report = Container <PerformanceTracker> .Where(filter1)
                     .Report(now.Subtract(new TimeSpan(5000, 1, 0, 0)),
                             now.Add(new TimeSpan(1, 0, 0)),
                             ReportResolution.Year);

            Debug.Write("Report5 Count: " + report.Results.Count()
                        + " StoreId: " + filter1.StoreID + "  ");

            Assert.IsTrue(report.Results.Any());
            Assert.AreEqual(now.Year, report.Results[0].MesurementTimeUtc.Year);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Month);
            Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Day);
            Assert.AreEqual(11, report.Results[0].Total);
            Assert.AreEqual(ReportResolution.Year, report.Resolution);
        }