public PerformanceStats(TimeSpan recordPeriod, int maxRecordCount)
 {
     this.recordPeriod = recordPeriod;
     this.maxRecordCount = maxRecordCount;
     head = new PerformanceRecord(recordPeriod);
     records.Enqueue(head);
 }
 public void TotalProcessedEventCount_AfterItemsAdded_ShouldYieldCorrectCount()
 {
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>());
     sut.EventProcessed("A");
     sut.EventProcessed("B");
     sut.EventProcessed("A");
     sut.TotalProcessedEventCount.Should().Be(3);
 }
 public void QueueStats_AfterThreeItemsAdded_ShouldYieldCorectCountsThree()
 {
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>());
     sut.EventProcessed("A");
     sut.EventProcessed("B");
     sut.EventProcessed("A");
     sut.QueueStats().Should().BeEquivalentTo(new Dictionary<string, long>{{"A",2},{"B",1}});
 }
 public void GetProcessedEventsFor_AfterItemsAdded_ShouldYieldCorrectCounts()
 {
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>());
     sut.EventProcessed("A");
     sut.EventProcessed("B");
     sut.EventProcessed("A");
     sut.GetProcessedEventsFor("A").Should().Be(2);
     sut.GetProcessedEventsFor("B").Should().Be(1);
 }
        public void TidyRecords()
        {
            while (head.EndTime < DateTime.Now)
            {
                head = new PerformanceRecord(recordPeriod, head.EndTime.AddTicks(1));
                records.Enqueue(head);

                if (records.Count > maxRecordCount)
                {
                    records.Dequeue();
                }
            }
            
        }
        public async Task RecordsAfter_ShouldReturnAllRecordsStartingAfterTheSuppliedDate()
        {
            var sut = new PerformanceStats(TimeSpan.FromMilliseconds(30), 3);

            var records = (Queue<PerformanceRecord>)sut.Records;

            records.Clear();

            var first = new PerformanceRecord(It.IsAny<TimeSpan>(), new DateTime(1, 2, 3));
            var second = new PerformanceRecord(It.IsAny<TimeSpan>(), first.StartTime.AddTicks(1));
            
            records.Enqueue(first);
            records.Enqueue(second);

            var foundRecords = sut.RecordsAfter(first.StartTime);

            foundRecords.Should().BeEquivalentTo(new[] {second});
        }
 public void EndTime_ShouldBeCalculatedCorrectlyAccordingToRecordPeriod()
 {
     var recordPeriod = TimeSpan.FromMinutes(5);
     var sut = new PerformanceRecord(recordPeriod);
     sut.EndTime.Should().BeExactly(recordPeriod).After(sut.StartTime);
 }
 public void StartTime_ShouldBeSetAccordinglyWhenSpecified()
 {
     var expected = new DateTime(1234, 5, 6);
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>(), expected);
     sut.StartTime.Should().Be(expected);
 }
 public void StartTime_ShouldBeCalculatedAccordingToCurrentTimeWhenNotSpecified()
 {
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>());
     sut.StartTime.Should().BeWithin(TimeSpan.FromMilliseconds(50)).Before(DateTime.Now);
 }
 public void GetProcessedEventsFor_ForEmptyPerformanceRecord_ShouldYieldZeroForCountForAnyString()
 {
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>());
     sut.GetProcessedEventsFor("something arbirtary").Should().Be(0);
 }
 public void TotalProcessedEventCount_ForEmptyPerformanceRecord_ShouldYieldZero()
 {
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>());
     sut.TotalProcessedEventCount.Should().Be(0);
 }
 public void QueueStats_ForEmptyPerformanceRecord_ShouldYieldAnEmptyDictionaryOfCounters()
 {
     var sut = new PerformanceRecord(It.IsAny<TimeSpan>());
     sut.QueueStats().Should().NotBeNull();
     sut.QueueStats().Should().BeEmpty();
 }