-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b421d2
commit b7c8b3d
Showing
24 changed files
with
212 additions
and
63 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Threading.Tasks; | ||
using TextCopy; | ||
using VerifyXunit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
public class ClipboardServiceTests : | ||
VerifyBase | ||
{ | ||
[Fact] | ||
public async Task Simple() | ||
{ | ||
VerifyInner("Foo"); | ||
VerifyInner("🅢"); | ||
await VerifyInnerAsync("Foo"); | ||
await VerifyInnerAsync("🅢"); | ||
} | ||
|
||
static void VerifyInner(string expected) | ||
{ | ||
ClipboardService.SetText(expected); | ||
|
||
var actual = ClipboardService.GetText(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
static async Task VerifyInnerAsync(string expected) | ||
{ | ||
await ClipboardService.SetTextAsync(expected); | ||
|
||
var actual = await ClipboardService.GetTextAsync(); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
public ClipboardServiceTests(ITestOutputHelper output) : | ||
base(output) | ||
{ | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using Xunit; | ||
|
||
[assembly: CollectionBehavior(DisableTestParallelization = true)] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,44 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace TextCopy | ||
{ | ||
/// <summary> | ||
/// Provides methods to place text on and retrieve text from the system Clipboard. | ||
/// </summary> | ||
public static partial class Clipboard | ||
public class Clipboard : | ||
IClipboard | ||
{ | ||
static Func<CancellationToken, Task<string?>> getAsyncFunc = CreateAsyncGet(); | ||
static Func<string?> getFunc = CreateGet(); | ||
|
||
/// <summary> | ||
/// Retrieves text data from the Clipboard. | ||
/// </summary> | ||
public static Task<string?> GetTextAsync(CancellationToken cancellation = default) | ||
public virtual Task<string?> GetTextAsync(CancellationToken cancellation = default) | ||
{ | ||
return getAsyncFunc(cancellation); | ||
return ClipboardService.GetTextAsync(cancellation); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves text data from the Clipboard. | ||
/// </summary> | ||
public static string? GetText() | ||
public virtual string? GetText() | ||
{ | ||
return getFunc(); | ||
return ClipboardService.GetText(); | ||
} | ||
|
||
static Func<string, CancellationToken, Task> setAsyncAction = CreateAsyncSet(); | ||
static Action<string> setAction = CreateSet(); | ||
|
||
/// <summary> | ||
/// Clears the Clipboard and then adds text data to it. | ||
/// </summary> | ||
public static Task SetTextAsync(string text, CancellationToken cancellation = default) | ||
public virtual Task SetTextAsync(string text, CancellationToken cancellation = default) | ||
{ | ||
Guard.AgainstNull(text, nameof(text)); | ||
return setAsyncAction(text, cancellation); | ||
return ClipboardService.SetTextAsync(text, cancellation); | ||
} | ||
|
||
/// <summary> | ||
/// Clears the Clipboard and then adds text data to it. | ||
/// </summary> | ||
public static void SetText(string text) | ||
public virtual void SetText(string text) | ||
{ | ||
Guard.AgainstNull(text, nameof(text)); | ||
setAction(text); | ||
ClipboardService.SetText(text); | ||
} | ||
} | ||
} |
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,52 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace TextCopy | ||
{ | ||
/// <summary> | ||
/// Provides methods to place text on and retrieve text from the system Clipboard. | ||
/// </summary> | ||
public static partial class ClipboardService | ||
{ | ||
static Func<CancellationToken, Task<string?>> getAsyncFunc = CreateAsyncGet(); | ||
static Func<string?> getFunc = CreateGet(); | ||
|
||
/// <summary> | ||
/// Retrieves text data from the Clipboard. | ||
/// </summary> | ||
public static Task<string?> GetTextAsync(CancellationToken cancellation = default) | ||
{ | ||
return getAsyncFunc(cancellation); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves text data from the Clipboard. | ||
/// </summary> | ||
public static string? GetText() | ||
{ | ||
return getFunc(); | ||
} | ||
|
||
static Func<string, CancellationToken, Task> setAsyncAction = CreateAsyncSet(); | ||
static Action<string> setAction = CreateSet(); | ||
|
||
/// <summary> | ||
/// Clears the Clipboard and then adds text data to it. | ||
/// </summary> | ||
public static Task SetTextAsync(string text, CancellationToken cancellation = default) | ||
{ | ||
Guard.AgainstNull(text, nameof(text)); | ||
return setAsyncAction(text, cancellation); | ||
} | ||
|
||
/// <summary> | ||
/// Clears the Clipboard and then adds text data to it. | ||
/// </summary> | ||
public static void SetText(string text) | ||
{ | ||
Guard.AgainstNull(text, nameof(text)); | ||
setAction(text); | ||
} | ||
} | ||
} |
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.