Пример #1
0
        public async Task TestClipboardStore_MemoryStream()
        {
            const string testString = "Dapplo.Windows.Tests.ClipboardTests";
            var          testStream = new MemoryStream();
            var          bytes      = Encoding.Unicode.GetBytes(testString + "\0");

            Assert.Equal(testString, Encoding.Unicode.GetString(bytes).TrimEnd('\0'));
            testStream.Write(bytes, 0, bytes.Length);

            Assert.Equal(testString, Encoding.Unicode.GetString(testStream.GetBuffer(), 0, (int)testStream.Length).TrimEnd('\0'));

            MemoryStream resultStream;

            using (ClipboardNative.Lock())
            {
                ClipboardNative.Clear();
                ClipboardNative.SetAsStream("CF_UNICODETEXT", testStream);
            }
            await Task.Delay(1000);

            using (ClipboardNative.Lock())
            {
                resultStream = ClipboardNative.GetAsStream("CF_UNICODETEXT");
            }
            Assert.Equal(testString, Encoding.Unicode.GetString(resultStream.GetBuffer(), 0, (int)resultStream.Length).TrimEnd('\0'));
        }