public void Setup()
        {
            var copyPair = SortedCommandPair.NewSortedPair(
                "Copy",
                "{5EFC7975-14BC-11CF-9B2B-00AA00573819}:15:Edit.Copy");
            var cutPair   = SortedCommandPair.NewSortedPair("Cut", "{5EFC7975-14BC-11CF-9B2B-00AA00573819}:16:Edit.Cut");
            var pastePair = SortedCommandPair.NewSortedPair(
                "Paste",
                "{5EFC7975-14BC-11CF-9B2B-00AA00573819}:26:Edit.Paste");
            var leftPair = SortedCommandPair.NewSortedPair("Left", "TextControl.Left");

            _saveAllPair = SortedCommandPair.NewSortedPair(
                "Save All",
                "{5EFC7975-14BC-11CF-9B2B-00AA00573819}:224:File.SaveAll");
            _reSharperToVsPair = SortedCommandPair.NewSortedPair(
                "TextControl.Delete",
                "{5EFC7975-14BC-11CF-9B2B-00AA00573819}:17:Edit.Delete");

            var testResourceProvider = new TestResourceProvider
            {
                Mappings =
                    new List <SortedCommandPair>
                {
                    copyPair,
                    cutPair,
                    pastePair,
                    leftPair,
                    _saveAllPair,
                    _reSharperToVsPair
                }
            };

            _uut = new MapEquivalentCommandsProcessor(testResourceProvider);
        }
        public void ShouldAddMappingForTwoConcurrentCommandEvents()
        {
            var eventTime = DateTimeFactory.SomeWorkingHoursDateTime();

            var commandEvent1 = new CommandEvent
            {
                CommandId   = "Edit.Copy",
                TriggeredAt = eventTime
            };
            var commandEvent2 = new CommandEvent
            {
                CommandId   = "Copy",
                TriggeredBy = EventTrigger.Click,
                TriggeredAt = eventTime + ConcurrentEventHeuristic.EventTimeDifference
            };

            _uut.OnStreamStarts(TestFactory.SomeDeveloper());
            _uut.OnEvent(commandEvent1);
            _uut.OnEvent(commandEvent2);
            _uut.OnStreamEnds();

            var expectedPair = SortedCommandPair.NewSortedPair(commandEvent1.CommandId, commandEvent2.CommandId);

            CollectionAssert.Contains(
                _uut.Statistic,
                new KeyValuePair <SortedCommandPair, int>(expectedPair, 1));
        }
        public void DoesNotSwapIfSecondIsGreaterThanFirst()
        {
            var sortedCommandPair = SortedCommandPair.NewSortedPair(SmallerCommand, GreaterCommand);

            Assert.AreEqual(SmallerCommand, sortedCommandPair.Item1);
            Assert.AreEqual(GreaterCommand, sortedCommandPair.Item2);
        }
        public void DoesNotSwapIfBothAreEqual()
        {
            const string anotherSmallerCommand = "New Item...";
            var          sortedCommandPair     = SortedCommandPair.NewSortedPair(SmallerCommand, anotherSmallerCommand);

            Assert.AreEqual(SmallerCommand, sortedCommandPair.Item1);
            Assert.AreEqual(anotherSmallerCommand, sortedCommandPair.Item2);
        }
        public void AddsFrequentPairToExport()
        {
            var frequencyThreshold = _uut.FrequencyThreshold;

            _uut.OnStreamStarts(TestFactory.SomeDeveloper());
            _uut.Statistic.Add(SortedCommandPair.NewSortedPair("Copy", "Edit.Copy"), frequencyThreshold);
            _uut.OnStreamEnds();

            StringAssert.Contains(string.Format("Copy,Edit.Copy,{0}", frequencyThreshold), _uut.StatisticAsCsv());
        }
        public void ShouldSortAlphabeticallyForEqualCommandTypes(string command1, string command2, bool shouldSwap)
        {
            var sortedCommandPair = SortedCommandPair.NewSortedPair(command1, command2);

            var expectedItem1 = shouldSwap ? command2 : command1;
            var expectedItem2 = shouldSwap ? command1 : command2;

            Assert.AreEqual(expectedItem1, sortedCommandPair.Item1);
            Assert.AreEqual(expectedItem2, sortedCommandPair.Item2);
        }
        public void RemovesInfrequentPairToExport()
        {
            var frequencyThreshold = _uut.FrequencyThreshold;

            _uut.OnStreamStarts(TestFactory.SomeDeveloper());
            _uut.Statistic.Add(SortedCommandPair.NewSortedPair("Left", "Textcontrol.Left"), frequencyThreshold - 1);
            _uut.OnStreamEnds();

            StringAssert.DoesNotContain(
                string.Format("Left,Textcontrol.Left,{0}", frequencyThreshold - 1),
                _uut.StatisticAsCsv());
        }
        private void AddEquivalentCommandsToUnknownTriggerMappings(string command1, string command2)
        {
            var keyPair = SortedCommandPair.NewSortedPair(command1, command2);

            if (UnknownTriggerMappings.ContainsKey(keyPair))
            {
                UnknownTriggerMappings[keyPair]++;
            }
            else
            {
                UnknownTriggerMappings.Add(keyPair, 1);
            }
        }
        private void AddEquivalentCommandsToStatistic(string command1, string command2)
        {
            var keyPair = SortedCommandPair.NewSortedPair(command1, command2);

            if (_currentDeveloperStatistic.ContainsKey(keyPair))
            {
                _currentDeveloperStatistic[keyPair]++;
            }
            else
            {
                _currentDeveloperStatistic.Add(keyPair, 1);
            }
        }
        public void ShouldAddUnknownTriggerMappingsToSeparateStatistic()
        {
            var eventTime = DateTimeFactory.SomeWorkingHoursDateTime();

            var commandEvent1 = new CommandEvent
            {
                CommandId   = "Test1",
                TriggeredAt = eventTime
            };
            var commandEvent2 = new CommandEvent
            {
                CommandId   = "Test2",
                TriggeredAt = eventTime + ConcurrentEventHeuristic.EventTimeDifference
            };
            var commandEvent3 = new CommandEvent
            {
                CommandId   = commandEvent1.CommandId,
                TriggeredAt = eventTime + ConcurrentEventHeuristic.EventTimeDifference +
                              TimeSpan.FromSeconds(1)
            };
            var commandEvent4 = new CommandEvent
            {
                CommandId   = commandEvent2.CommandId,
                TriggeredAt = eventTime + ConcurrentEventHeuristic.EventTimeDifference +
                              TimeSpan.FromSeconds(1) +
                              ConcurrentEventHeuristic.EventTimeDifference
            };

            _uut.OnStreamStarts(TestFactory.SomeDeveloper());
            _uut.OnEvent(commandEvent1);
            _uut.OnEvent(commandEvent2);

            _uut.OnEvent(commandEvent3);
            _uut.OnEvent(commandEvent4);

            var expectedPair = SortedCommandPair.NewSortedPair(commandEvent1.CommandId, commandEvent2.CommandId);

            CollectionAssert.AreEquivalent(
                new Dictionary <SortedCommandPair, int>
            {
                { expectedPair, 2 }
            },
                _uut.UnknownTriggerMappings);

            CollectionAssert.IsEmpty(_uut.Statistic);
        }