示例#1
0
        public void CountsEqualSetsCorrectly()
        {
            var commandEvent = new CommandEvent {
                CommandId = "Test"
            };
            var documentEvent = new DocumentEvent {
                Action = DocumentAction.Saved
            };
            var concurrentEvent = new ConcurrentEvent
            {
                ConcurrentEventList = new List <IDEEvent>
                {
                    commandEvent,
                    documentEvent
                }
            };

            _uut.OnEvent(concurrentEvent);
            _uut.OnEvent(concurrentEvent);

            Assert.AreEqual(
                2,
                _uut.Statistic[
                    Sets.NewHashSet(
                        EventMappingUtils.GetAbstractStringOf(documentEvent),
                        EventMappingUtils.GetAbstractStringOf(commandEvent))]);
        }
示例#2
0
        public void ShouldNotIgnoreOtherWindowEvents()
        {
            _uut.AddEventAfterBreakToStatistic = false;

            var triggeredAt = DateTimeFactory.SomeWorkingHoursDateTime();

            var someEvent = new WindowEvent
            {
                TriggeredAt = triggeredAt,
                Action = WindowAction.Activate
            };
            var eventAfterBreak = new CommandEvent
            {
                TriggeredAt = triggeredAt + _uut.MinBreakTime
            };

            _uut.OnStreamStarts(new Developer());
            _uut.OnEvent(someEvent);
            _uut.OnEvent(eventAfterBreak);
            _uut.OnStreamEnds();

            var expectedStatistic = new Dictionary<string, Tuple<TimeSpan, int>>
            {
                {
                    EventMappingUtils.GetAbstractStringOf(someEvent),
                    new Tuple<TimeSpan, int>(_uut.MinBreakTime, 1)
                }
            };
            CollectionAssert.AreEquivalent(expectedStatistic, _uut.Statistic);
        }
示例#3
0
        public void ShouldAddNextEventWhenEnabled()
        {
            _uut.AddEventAfterBreakToStatistic = true;

            var triggeredAt = DateTimeFactory.SomeWorkingHoursDateTime();

            var someEvent = new TestIDEEvent
            {
                TriggeredAt = triggeredAt
            };
            var eventAfterBreak = new CommandEvent
            {
                TriggeredAt = triggeredAt + _uut.MinBreakTime
            };

            _uut.OnStreamStarts(new Developer());
            _uut.OnEvent(someEvent);
            _uut.OnEvent(eventAfterBreak);
            _uut.OnStreamEnds();

            var expectedStatistic = new Dictionary<string, Tuple<TimeSpan, int>>
            {
                {
                    String.Format(
                        "{0}{1}{2}",
                        EventMappingUtils.GetAbstractStringOf(new TestIDEEvent()),
                        AverageBreakAfterEventsCalculator.EventAfterBreakSeparator,
                        EventMappingUtils.GetAbstractStringOf(new CommandEvent())),
                    new Tuple<TimeSpan, int>(_uut.MinBreakTime, 1)
                }
            };
            CollectionAssert.AreEquivalent(expectedStatistic, _uut.Statistic);
        }
示例#4
0
 private string GenerateLastEventsString(IDEEvent lateEvent)
 {
     return(AddEventAfterBreakToStatistic
         ? String.Format(
                "{0}{1}{2}",
                GenerateStringFromCache(),
                EventAfterBreakSeparator,
                EventMappingUtils.GetAbstractStringOf(lateEvent))
         : GenerateStringFromCache());
 }
示例#5
0
        private string GenerateStringFromCache()
        {
            var cacheStringBuilder = new StringBuilder();

            _eventCache.ToList().ForEach(
                ideEvent =>
                cacheStringBuilder.Append(
                    EventMappingUtils.GetAbstractStringOf(ideEvent) + StatisticStringSeparator));

            return(cacheStringBuilder.ToString().TrimEnd(StatisticStringSeparator));
        }
示例#6
0
        public void ShouldFillStatisticAtStreamEnds()
        {
            _uut.MaxEventsBeforeBreak = 1;
            _uut.MinBreakTime = TimeSpan.Zero;

            var now = DateTime.Now;

            var listOfEvents = new List<IDEEvent>
            {
                new TestIDEEvent
                {
                    TriggeredAt = now
                },
                new CommandEvent
                {
                    TriggeredAt = now + TimeSpan.FromSeconds(2)
                },
                new TestIDEEvent
                {
                    TriggeredAt = now + TimeSpan.FromSeconds(3)
                },
                new TestIDEEvent
                {
                    TriggeredAt = now + TimeSpan.FromSeconds(4)
                },
                new CommandEvent
                {
                    TriggeredAt = now + TimeSpan.FromSeconds(10)
                },
                new TestIDEEvent
                {
                    TriggeredAt = now + TimeSpan.FromSeconds(15)
                }
            };

            var expectedStatistic = new Dictionary<string, Tuple<TimeSpan, int>>
            {
                {
                    EventMappingUtils.GetAbstractStringOf(new TestIDEEvent()),
                    new Tuple<TimeSpan, int>(TimeSpan.FromSeconds(3), 3)
                },
                {
                    EventMappingUtils.GetAbstractStringOf(new CommandEvent()),
                    new Tuple<TimeSpan, int>(TimeSpan.FromSeconds(3), 2)
                }
            };

            _uut.OnStreamStarts(new Developer());
            listOfEvents.ForEach(@event => _uut.OnEvent(@event));
            _uut.OnStreamEnds();

            CollectionAssert.AreEquivalent(expectedStatistic, _uut.Statistic);
        }
示例#7
0
        public void ShouldCombineResultsForMultipleDeveloperStreams()
        {
            _uut.MaxEventsBeforeBreak = 2;

            var triggeredAt = DateTimeFactory.SomeWorkingHoursDateTime();

            var firstEvent = new TestIDEEvent
            {
                TriggeredAt = triggeredAt
            };
            var secondEvent = new CommandEvent
            {
                TriggeredAt = triggeredAt
            };
            var lateEvent = new TestIDEEvent
            {
                TriggeredAt = triggeredAt + _uut.MinBreakTime
            };

            var listOfEvents = new List<IDEEvent>
            {
                firstEvent,
                secondEvent,
                lateEvent
            };

            _uut.OnStreamStarts(new Developer());
            listOfEvents.ForEach(@event => _uut.OnEvent(@event));
            _uut.OnStreamEnds();

            _uut.OnStreamStarts(new Developer());
            listOfEvents.ForEach(@event => _uut.OnEvent(@event));
            _uut.OnStreamEnds();


            var expectedStatistic = new Dictionary<string, Tuple<TimeSpan, int>>
            {
                {
                    String.Format(
                        "{0}{1}{2}",
                        EventMappingUtils.GetAbstractStringOf(new TestIDEEvent()),
                        AverageBreakAfterEventsCalculator.StatisticStringSeparator,
                        EventMappingUtils.GetAbstractStringOf(new CommandEvent())),
                    new Tuple<TimeSpan, int>(_uut.MinBreakTime, 2)
                }
            };
            CollectionAssert.AreEquivalent(expectedStatistic, _uut.Statistic);
        }
示例#8
0
        public string FilteredIsolatedBlocksToTxt()
        {
            var stringBuilder = new StringBuilder();

            foreach (var filteredIsolatedBlock in FilteredIsolatedBlocks)
            {
                stringBuilder.AppendLine("--- Start of filtered block ---");
                filteredIsolatedBlock.ToList()
                .ForEach(
                    eventFromBlock =>
                    stringBuilder.AppendLine(
                        "\t" + EventMappingUtils.GetAbstractStringOf(eventFromBlock)));
                stringBuilder.AppendLine("--- End of filtered block ---");
                stringBuilder.AppendLine("");
            }

            return(stringBuilder.ToString());
        }
示例#9
0
        public void HandleConcurrentEvents(ConcurrentEvent concurrentEvent)
        {
            var resultSet = Sets.NewHashSet <string>();

            foreach (var ideEvent in concurrentEvent.ConcurrentEventList)
            {
                resultSet.Add(EventMappingUtils.GetAbstractStringOf(ideEvent));
            }

            if (Statistic.ContainsKey(resultSet))
            {
                Statistic[resultSet]++;
            }
            else
            {
                if (resultSet.Count > 0)
                {
                    Statistic.Add(resultSet, 1);
                }
            }
        }
示例#10
0
        public void ShouldNotUseMoreThanMaximumEventsBeforeBreakForStatistic()
        {
            _uut.MaxEventsBeforeBreak = 1;

            var triggeredAt = DateTimeFactory.SomeWorkingHoursDateTime();

            var firstEvent = new TestIDEEvent
            {
                TriggeredAt = triggeredAt
            };
            var secondEvent = new CommandEvent
            {
                TriggeredAt = triggeredAt
            };
            var lateEvent = new TestIDEEvent
            {
                TriggeredAt = triggeredAt + _uut.MinBreakTime
            };

            var listOfEvents = new List<IDEEvent>
            {
                firstEvent,
                secondEvent,
                lateEvent
            };

            _uut.OnStreamStarts(new Developer());
            listOfEvents.ForEach(@event => _uut.OnEvent(@event));
            _uut.OnStreamEnds();

            var expectedStatistic = new Dictionary<string, Tuple<TimeSpan, int>>
            {
                {
                    EventMappingUtils.GetAbstractStringOf(new CommandEvent()),
                    new Tuple<TimeSpan, int>(_uut.MinBreakTime, 1)
                }
            };
            CollectionAssert.AreEquivalent(expectedStatistic, _uut.Statistic);
        }
示例#11
0
 public void ShouldMapToSpecialStringForTypesWithoutMapping()
 {
     Assert.AreEqual(
         "TestIDEEvent -> no mapping found",
         EventMappingUtils.GetAbstractStringOf(TestEventFactory.SomeEvent()));
 }
示例#12
0
 public void ShouldMapToAbstractStringCorrectly(IDEEvent inputEvent, string expectedString)
 {
     Assert.AreEqual(expectedString, EventMappingUtils.GetAbstractStringOf(inputEvent));
 }