Exemple #1
0
 static bool ShouldCreateNewMessage(Message previous, Message current)
 {
     return previous.ProcessName != current.ProcessName ||
            current.LastMessage.Subtract(previous.LastMessage) > OneSecond ||
            !previous.CanBeMerged ||
            !current.CanBeMerged;
 }
Exemple #2
0
 private Message(Message initial, bool isDeleting)
     : this(initial.keys, new KeyShortcut(initial.ShortcutName))
 {
     this.isDeleting = isDeleting;
     previous = initial;
     lastMessage = initial.lastMessage;
 }
Exemple #3
0
        public void MessagesAreAddedIntoKeysColletion()
        {
            var message = new Message(A);

            sut.Start();
            ProvideMessage(message);

            keysCollection.ShouldContain(message);
            message.IsDeleting.ShouldBe(false);
        }
Exemple #4
0
        public void MessagesIsRemovedAfter6Seconds()
        {
            var message = new Message(A);

            sut.Start();
            ProvideMessage(message);
            testScheduler.AdvanceBy(TimeSpan.FromSeconds(6).Ticks);

            keysCollection.ShouldNotContain(message);
        }
Exemple #5
0
        public void message_groups_three_equal_arrow_key_presses_together()
        {
            // arrange
            var result = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" }))
                .Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" })))
                .Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" })));

            // assert
            Assert.Equal("↓ x 3 ", string.Join(string.Empty, result.Text));
        }
Exemple #6
0
        public void message_groups_three_equal_arrow_key_presses_together()
        {
            // arrange
            var result = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" }))
                         .Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" })))
                         .Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" })));

            // assert
            Assert.Equal("↓ x 3 ", string.Join(string.Empty, result.Text));
        }
Exemple #7
0
        public void MessagesAreFlaggedAsDeletingAfter5Seconds()
        {
            var message = new Message(A);

            sut.Start();
            ProvideMessage(message);
            testScheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);

            message.IsDeleting.ShouldBe(true);
        }
Exemple #8
0
        public void message_does_not_group_letter_and_backspace()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "a" }));

            // act
            var result = message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "Back" })));

            // assert
            Assert.Equal("aBack", string.Join(string.Empty, result.Text));
        }
Exemple #9
0
        public void message_groups_multiple_backspace_key_presses_together()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "Back" }));

            // act
            message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "Back" })));

            // assert
            Assert.Equal("Back x 2 ", string.Join(string.Empty, message.Text));
        }
Exemple #10
0
        public void message_does_not_group_different_arrow_key_presses_together()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Up, KeyDirection.Down, false, false, false), false, new[] { "Up" }));

            // act
            var result = message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" })));

            // assert
            Assert.Equal("↑↓", string.Join(string.Empty, result.Text));
        }
Exemple #11
0
        public void multiple_shortcuts_have_comma_inserted_between_input()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.R, KeyDirection.Down, false, true, false), false, new[] { "Control", "R" }));

            // act
            message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.T, KeyDirection.Down, false, true, false), false, new[] { "Control", "T" })));

            // assert
            Assert.Equal("Control + R, Control + T", string.Join(string.Empty, message.Text));
        }
Exemple #12
0
        public void message_groups_multiple_backspace_key_presses_together()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "Back" }));

            // act
            var result = message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "Back" })));

            // assert
            Assert.Equal("Back x 2 ", string.Join(string.Empty, result.Text));
        }
Exemple #13
0
        public void message_does_not_group_messages_from_different_processes_together()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Up, KeyDirection.Down, false, false, false), false, new[] { "Up" }));

            // act
            message.Merge(new Message(new KeyPress(fakeProcess2, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" })));

            // assert
            Assert.Equal("↑↓", string.Join(string.Empty, message.Text));
        }
Exemple #14
0
        public void message_does_not_group_letter_and_backspace()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "a" }));

            // act
            message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "Back" })));

            // assert
            Assert.Equal("aBack", string.Join(string.Empty, message.Text));
        }
Exemple #15
0
        public void message_does_not_group_different_letters()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "a" }));

            // act
            var result = message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "b" })));

            // assert
            var expected = string.Join(string.Empty, result.Text);
            Assert.Equal("ab", expected);
        }
Exemple #16
0
        private Message CreateNewMessage(KeyPress value)
        {
            var message = new Message
            {
                StartingTime = DateTime.Now,
                ProcessName  = value.Process.ProcessName
            };

            CurrentMessage = message;
            subject.OnNext(message);
            return(message);
        }
Exemple #17
0
        public void message_groups_multiple_equal_arrow_key_presses_together()
        {
            // arrange
            var message = new Message();
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" }));

            // act
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" }));

            // assert
            Assert.Equal("↓ x 2 ", string.Join(string.Empty, message.Text));
        }
Exemple #18
0
        public void message_does_not_group_letter_and_backspace()
        {
            // arrange
            var message = new Message();
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "a" }));

            // act
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "Back" }));

            // assert
            Assert.Equal("aBack", string.Join(string.Empty, message.Text));
        }
Exemple #19
0
        public void multiple_shortcuts_have_comma_inserted_between_input()
        {
            // arrange
            var message = new Message();
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.R, KeyDirection.Down, false, true, false), false, new[] { "Control", "R" }));

            // act
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.T, KeyDirection.Down, false, true, false), false, new[] { "Control", "T" }));

            // assert
            Assert.Equal("Control + R, Control + T", string.Join(string.Empty, message.Text));
        }
Exemple #20
0
        public void message_does_not_group_different_letters()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "a" }));

            // act
            var result = message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "b" })));

            // assert
            var expected = string.Join(string.Empty, result.Text);

            Assert.Equal("ab", expected);
        }
Exemple #21
0
        public void MessageTimeoutIsStartedAgainIfMessageIsUpdated()
        {
            var message = new Message(A);

            sut.Start();
            ProvideMessage(message);
            testScheduler.AdvanceBy(TimeSpan.FromSeconds(3).Ticks);
            message.Merge(new Message(A));
            testScheduler.AdvanceBy(TimeSpan.FromSeconds(3).Ticks);

            message.IsDeleting.ShouldBe(false);
            keysCollection.ShouldContain(message);
        }
Exemple #22
0
        public void message_does_not_group_different_letters()
        {
            // arrange
            var message = new Message();

            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "a" }));

            // act
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Back, KeyDirection.Down, false, false, false), false, new[] { "b" }));

            // assert
            Assert.Equal("ab", string.Join(string.Empty, message.Text));
        }
Exemple #23
0
        public void message_groups_multiple_equal_arrow_key_presses_together()
        {
            // arrange
            var message = new Message();

            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" }));

            // act
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" }));

            // assert
            Assert.Equal("↓ x 2 ", string.Join(string.Empty, message.Text));
        }
Exemple #24
0
        public void message_does_not_group_different_arrow_key_presses_together()
        {
            // arrange
            var message = new Message();

            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Up, KeyDirection.Down, false, false, false), false, new[] { "Up" }));

            // act
            message.AddKey(new KeyPress(null, new InterceptKeyEventArgs(Keys.Down, KeyDirection.Down, false, false, false), false, new[] { "Down" }));

            // assert
            Assert.Equal("↑↓", string.Join(string.Empty, message.Text));
        }
Exemple #25
0
        public void multiple_shortcuts_duplicate_shortcuts_are_grouped()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.R, KeyDirection.Down, false, true, false), false, new[] { "Control", "R" }));

            // act
            var result = message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.R, KeyDirection.Down, false, true, false), false, new[] { "Control", "R" })));

            // assert
            string actual = string.Join(string.Empty, result.Text);

            Assert.Equal("Control + R x 2 ", actual);
        }
Exemple #26
0
        public void UnsubscribesFromMessageUpdatesAfterDeleteTimeout()
        {
            var message = new Message(A);

            sut.Start();
            ProvideMessage(message);
            testScheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);
            message.IsDeleting = false;
            message.Merge(new Message(A)); // This will trigger an update of the message
            testScheduler.AdvanceBy(5);
            testScheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);

            // If we didn't unsubscribe to updates we would have triggered another inner sequence which would try to delete again.
            message.IsDeleting.ShouldBe(false);
        }
Exemple #27
0
        public void MultiMerge()
        {
            var message1 = new Message(Down);
            var message2 = message1.Merge(new Message(Down));
            var message3 = message2.Merge(new Message(Down));

            var expected        = message3;
            var messageSequence = testScheduler.CreateColdObservable(
                ReactiveTest.OnNext(0.1.Seconds(), message1),
                ReactiveTest.OnNext(0.2.Seconds(), message2),
                ReactiveTest.OnNext(0.3.Seconds(), message3)
                );

            var sut = CreateKeysController(messageSequence);

            sut.Start();
            testScheduler.AdvanceBy(1.Seconds());

            messages.Single().IsDeleting.ShouldBe(false);
            messages.Single().ShouldBe(expected);
        }
Exemple #28
0
 public Message MergeIfNeeded(Message previousMessage, Message newMessage)
 {
     return ShouldCreateNewMessage(previousMessage, newMessage)
         ? newMessage
         : previousMessage.Merge(newMessage);
 }
Exemple #29
0
        public void MultiMerge()
        {
            var message1 = new Message(Down);
            var message2 = message1.Merge(new Message(Down));
            var message3 = message2.Merge(new Message(Down));

            var expected = message3;
            var messageSequence = testScheduler.CreateColdObservable(
                ReactiveTest.OnNext(0.1.Seconds(), message1),
                ReactiveTest.OnNext(0.2.Seconds(), message2),
                ReactiveTest.OnNext(0.3.Seconds(), message3)
                );

            var sut = CreateKeysController(messageSequence);

            sut.Start();
            testScheduler.AdvanceBy(1.Seconds());

            messages.Single().IsDeleting.ShouldBe(false);
            messages.Single().ShouldBe(expected);
        }
Exemple #30
0
 public Message Merge(Message other)
 {
     return new Message(this, other);
 }
Exemple #31
0
 void ProvideMessage(Message message)
 {
     testScheduler.AdvanceBy(5);  // Need to tick to allows merge to be setup properly
     messageStream.OnNext(message);
     testScheduler.AdvanceBy(10); // Few more ticks to allow the message to be processed
 }
Exemple #32
0
 private Message(Message initial, Message appended)
     : this(initial.keys.Concat(appended.keys), new KeyShortcut(initial.ShortcutName))
 {
     previous = initial;
     canBeMerged = true;
 }
Exemple #33
0
 bool Equals(Message other)
 {
     return textCollection.SequenceEqual(other.textCollection)
         && keys.SequenceEqual(other.keys)
         && string.Equals(processName, other.processName)
         && Equals(processIcon, other.processIcon)
         && string.Equals(shortcutName, other.shortcutName)
         && canBeMerged.Equals(other.canBeMerged)
         && isShortcut.Equals(other.isShortcut)
         && isDeleting.Equals(other.isDeleting)
         && lastMessage.Equals(other.lastMessage);
 }
Exemple #34
0
        public void multiple_shortcuts_duplicate_shortcuts_are_grouped()
        {
            // arrange
            var message = new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.R, KeyDirection.Down, false, true, false), false, new[] { "Control", "R" }));

            // act
            var result = message.Merge(new Message(new KeyPress(fakeProcess, new InterceptKeyEventArgs(Keys.R, KeyDirection.Down, false, true, false), false, new[] { "Control", "R" })));

            // assert
            string actual = string.Join(string.Empty, result.Text);

            Assert.Equal("Control + R x 2 ", actual);
        }