-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial app component dependencies. * Remove ClipboardService manual startup initialization. * Improved and tested "Ctrl + V" hotkey emulation. * Simplified P/Invoke services. * Code smell fix test. * revert test
- Loading branch information
Showing
16 changed files
with
501 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Tests/Tum4ik.JustClipboardManager.UnitTests/Services/PasteServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Windows.Input; | ||
using Tum4ik.JustClipboardManager.Data.Models; | ||
using Tum4ik.JustClipboardManager.Services; | ||
using Tum4ik.JustClipboardManager.Services.PInvoke; | ||
using Tum4ik.JustClipboardManager.Services.PInvoke.ParameterModels; | ||
|
||
namespace Tum4ik.JustClipboardManager.UnitTests.Services; | ||
public class PasteServiceTests | ||
{ | ||
private readonly Mock<IClipboardService> _clipboardServiceMock = new(); | ||
private readonly Mock<IUser32DllService> _user32DllMock = new(); | ||
private readonly PasteService _testeeService; | ||
|
||
public PasteServiceTests() | ||
{ | ||
_testeeService = new(_clipboardServiceMock.Object, _user32DllMock.Object); | ||
} | ||
|
||
|
||
[Fact] | ||
internal void PasteData_DataIsEmpty_NothingToDo() | ||
{ | ||
_testeeService.PasteData(nint.Zero, new List<FormattedDataObject>()); | ||
_clipboardServiceMock.VerifyNoOtherCalls(); | ||
_user32DllMock.VerifyNoOtherCalls(); | ||
} | ||
|
||
|
||
[Fact] | ||
internal void PasteData_DataIsPresent_DataIsInsertedIntoClipboardAndCtrlVHotkeyIsEmulated() | ||
{ | ||
const nint TargetWindowPtr = 42; | ||
var data = new List<FormattedDataObject> | ||
{ | ||
new() | ||
{ | ||
Data = Array.Empty<byte>(), | ||
DataDotnetType = "int", | ||
Format = "number", | ||
FormatOrder = 0 | ||
} | ||
}; | ||
|
||
_testeeService.PasteData(TargetWindowPtr, data); | ||
|
||
_clipboardServiceMock.Verify(cs => cs.Paste(data), Times.Once); | ||
_user32DllMock.Verify(u32 => u32.SetForegroundWindow(TargetWindowPtr), Times.Once); | ||
_user32DllMock.Verify(u32 => u32.SetFocus(TargetWindowPtr), Times.Once); | ||
_user32DllMock.Verify(u32 => u32.SendInput(4, IsCtrlVInput(), InputStructSize()), Times.Once); | ||
} | ||
|
||
|
||
private static INPUT[] IsCtrlVInput() | ||
{ | ||
return Match.Create<INPUT[]>(inputs => | ||
{ | ||
var lengthCondition = inputs.Length == 4; | ||
var input0Condition = inputs[0].type == INPUTTYPE.INPUT_KEYBOARD | ||
&& inputs[0].data.ki.wVk == KeyInterop.VirtualKeyFromKey(Key.LeftCtrl) | ||
&& inputs[0].data.ki.dwFlags == default; | ||
var input1Condition = inputs[1].type == INPUTTYPE.INPUT_KEYBOARD | ||
&& inputs[1].data.ki.wVk == KeyInterop.VirtualKeyFromKey(Key.V) | ||
&& inputs[1].data.ki.dwFlags == default; | ||
var input2Condition = inputs[2].type == INPUTTYPE.INPUT_KEYBOARD | ||
&& inputs[2].data.ki.wVk == KeyInterop.VirtualKeyFromKey(Key.V) | ||
&& inputs[2].data.ki.dwFlags == KEYEVENT.KEYEVENTF_KEYUP; | ||
var input3Condition = inputs[3].type == INPUTTYPE.INPUT_KEYBOARD | ||
&& inputs[3].data.ki.wVk == KeyInterop.VirtualKeyFromKey(Key.LeftCtrl) | ||
&& inputs[3].data.ki.dwFlags == KEYEVENT.KEYEVENTF_KEYUP; | ||
return lengthCondition && input0Condition && input1Condition && input2Condition && input3Condition; | ||
}); | ||
} | ||
|
||
private static unsafe int InputStructSize() | ||
{ | ||
return Match.Create<int>(size => size == sizeof(INPUT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
Tum4ik.JustClipboardManager/Data/Repositories/ClipRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.