static bool ShouldCreateNewMessage(Message previous, Message current) { return previous.ProcessName != current.ProcessName || current.LastMessage.Subtract(previous.LastMessage) > OneSecond || !previous.CanBeMerged || !current.CanBeMerged; }
private Message(Message initial, bool isDeleting) : this(initial.keys, new KeyShortcut(initial.ShortcutName)) { this.isDeleting = isDeleting; previous = initial; lastMessage = initial.lastMessage; }
public void MessagesAreAddedIntoKeysColletion() { var message = new Message(A); sut.Start(); ProvideMessage(message); keysCollection.ShouldContain(message); message.IsDeleting.ShouldBe(false); }
public void MessagesIsRemovedAfter6Seconds() { var message = new Message(A); sut.Start(); ProvideMessage(message); testScheduler.AdvanceBy(TimeSpan.FromSeconds(6).Ticks); keysCollection.ShouldNotContain(message); }
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)); }
public void MessagesAreFlaggedAsDeletingAfter5Seconds() { var message = new Message(A); sut.Start(); ProvideMessage(message); testScheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks); message.IsDeleting.ShouldBe(true); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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); }
private Message CreateNewMessage(KeyPress value) { var message = new Message { StartingTime = DateTime.Now, ProcessName = value.Process.ProcessName }; CurrentMessage = message; subject.OnNext(message); return(message); }
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)); }
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)); }
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)); }
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); }
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)); }
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)); }
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); }
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); }
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); }
public Message MergeIfNeeded(Message previousMessage, Message newMessage) { return ShouldCreateNewMessage(previousMessage, newMessage) ? newMessage : previousMessage.Merge(newMessage); }
public Message Merge(Message other) { return new Message(this, other); }
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 }
private Message(Message initial, Message appended) : this(initial.keys.Concat(appended.keys), new KeyShortcut(initial.ShortcutName)) { previous = initial; canBeMerged = true; }
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); }