Exemple #1
0
        public void Test_Convert_Dispose()
        {
            // モック
            var resourceUnicodeMock = new Mock <IDisposable>();
            var resourceAnsiMock    = new Mock <IDisposable>();
            var dataMock            = new TestDataObject();

            dataMock.Setup_GetDataPresent("UniformResourceLocatorW", () => true);
            dataMock.Setup_GetDataPresent("UniformResourceLocator", () => true);
            dataMock.Setup_GetData("UniformResourceLocatorW", () => resourceUnicodeMock.Object);
            dataMock.Setup_GetData("UniformResourceLocator", () => resourceAnsiMock.Object);

            // テスト用のイベントパラメータ生成
            var args = TestActivator.CreateDragEventArgs(dataMock.Object);

            // 変換テスト
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = false;
            target.Convert(args, null, null, null)
            .Should().BeNull();

            resourceUnicodeMock.Verify(m => m.Dispose(), Times.Once());
            resourceAnsiMock.Verify(m => m.Dispose(), Times.Once());
        }
Exemple #2
0
        public void Test_Convert_ToString_PriorityUnicode()
        {
            // ドロップテストデータ
            var urlUnicode = "https://www.google.com/unicode";
            var urlAnsi    = "https://www.google.com/ansi";

            // モック
            var dataMock = new TestDataObject();

            dataMock.Setup_GetDataPresent("UniformResourceLocatorW", () => true);
            dataMock.Setup_GetDataPresent("UniformResourceLocator", () => true);
            dataMock.Setup_GetData("UniformResourceLocatorW", () => new MemoryStream(Encoding.Unicode.GetBytes(urlUnicode)));
            dataMock.Setup_GetData("UniformResourceLocator", () => new MemoryStream(Encoding.ASCII.GetBytes(urlAnsi)));

            // テスト用のイベントパラメータ生成
            var args = TestActivator.CreateDragEventArgs(dataMock.Object);

            // 変換テスト
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = false;
            target.Convert(args, null, null, null)
            .Should().BeOfType <string>()
            .Which
            .Should().Be(urlUnicode);
        }
Exemple #3
0
        public void Test_Convert_ToUri_FromAnsi()
        {
            // ドロップテストデータ
            var url = "https://www.google.com";

            // モック
            var dataMock = new TestDataObject();

            dataMock.Setup_GetDataPresent("UniformResourceLocator", () => true);
            dataMock.Setup_GetData("UniformResourceLocator", () => new MemoryStream(Encoding.ASCII.GetBytes(url)));

            // テスト用のイベントパラメータ生成
            var args = TestActivator.CreateDragEventArgs(dataMock.Object);

            // テストデータを期待値の型に変換しておく
            var expects = new Uri(url);

            // 変換テスト
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = true;
            target.Convert(args, null, null, null)
            .Should().BeOfType <Uri>()
            .Which
            .Should().Be(expects);
        }
Exemple #4
0
        public void Test_Construct()
        {
            var target = new DragEventArgsToUrlConverter();

            target.AcceptFormats.Should().Contain("UniformResourceLocatorW", "UniformResourceLocator");
            target.ConvertToUri.Should().Be(false);
        }
Exemple #5
0
        public void Test_Convert_ToString_Fallback2()
        {
            // ドロップテストデータ
            var url = "https://www.google.com";

            // モック
            var resourceMock = new Mock <IDisposable>();

            resourceMock.Setup(m => m.Dispose()).Throws(new Exception());
            var dataMock = new TestDataObject();

            dataMock.Setup_GetDataPresent("UniformResourceLocatorW", () => true);
            dataMock.Setup_GetDataPresent("UniformResourceLocator", () => true);
            dataMock.Setup_GetData("UniformResourceLocatorW", () => resourceMock.Object);
            dataMock.Setup_GetData("UniformResourceLocator", () => new MemoryStream(Encoding.ASCII.GetBytes(url)));

            // テスト用のイベントパラメータ生成
            var args = TestActivator.CreateDragEventArgs(dataMock.Object);

            // 変換テスト
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = false;
            target.Convert(args, null, null, null)
            .Should().BeOfType <string>()
            .Which
            .Should().Be(url);
        }
Exemple #6
0
        public void Test_ConvertBack_NotSupport()
        {
            // ドロップテストデータ
            var url = "https://www.google.com";

            // 変換テスト (変換元データ型が期待と異なる)
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = false;
            target.ConvertBack(url, null, null, null)
            .Should().Be(DependencyProperty.UnsetValue);
        }
Exemple #7
0
        public void Test_Convert_NotUrlDrop2()
        {
            // モック
            var dataMock = new TestDataObject();

            dataMock.Setup_GetDataPresent("UniformResourceLocatorW", () => true);
            dataMock.Setup_GetData("UniformResourceLocatorW", () => null);

            // テスト用のイベントパラメータ生成
            var args = TestActivator.CreateDragEventArgs(dataMock.Object);

            // 変換テスト
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = false;
            target.Convert(args, null, null, null)
            .Should().BeNull();
        }
Exemple #8
0
        public void Test_Convert_ToUri_NotConvert()
        {
            // ドロップテストデータ
            var url = "::::::::::::";

            // モック
            var dataMock = new TestDataObject();

            dataMock.Setup_GetDataPresent("UniformResourceLocatorW", () => true);
            dataMock.Setup_GetData("UniformResourceLocatorW", () => new MemoryStream(Encoding.Unicode.GetBytes(url)));

            // テスト用のイベントパラメータ生成
            var args = TestActivator.CreateDragEventArgs(dataMock.Object);

            // 変換テスト
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = true;
            target.Convert(args, null, null, null)
            .Should().BeNull();
        }
Exemple #9
0
        public void Test_Convert_ByTargetType_NotUri()
        {
            // ドロップテストデータ
            var url = "https://www.google.com";

            // モック
            var dataMock = new TestDataObject();

            dataMock.Setup_GetDataPresent("UniformResourceLocatorW", () => true);
            dataMock.Setup_GetData("UniformResourceLocatorW", () => new MemoryStream(Encoding.Unicode.GetBytes(url)));

            // テスト用のイベントパラメータ生成
            var args = TestActivator.CreateDragEventArgs(dataMock.Object);

            // 変換テスト
            var target = new DragEventArgsToUrlConverter();

            target.ConvertToUri = false;
            target.Convert(args, typeof(int), null, null)
            .Should().BeOfType <string>()
            .Which
            .Should().Be(url);
        }