Exemplo n.º 1
0
        public void OnHelpRequest_Invoke_CallsHelpRequest(EventArgs eventArgs)
        {
            var dialog = new SubCommonDialog();

            // No handler.
            dialog.OnHelpRequest(eventArgs);

            // Handler.
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(dialog, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            dialog.HelpRequest += handler;
            dialog.OnHelpRequest(eventArgs);
            Assert.Equal(1, callCount);

            // Should not call if the handler is removed.
            dialog.HelpRequest -= handler;
            dialog.OnHelpRequest(eventArgs);
            Assert.Equal(1, callCount);
        }
Exemplo n.º 2
0
 public void ShowDialog_ControlOwner_ReturnsExpected(bool runDialogResult, DialogResult expectedDialogResult)
 {
     using var dialog = new SubCommonDialog
           {
               RunDialogResult = runDialogResult
           };
     using var owner = new Control();
     Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
 }
Exemplo n.º 3
0
 public void ShowDialog_NoOwner_ReturnsExpected(bool runDialogResult, DialogResult expectedDialogResult)
 {
     using var dialog = new SubCommonDialog
           {
               RunDialogResult = runDialogResult
           };
     Assert.Equal(expectedDialogResult, dialog.ShowDialog());
     Assert.Equal(expectedDialogResult, dialog.ShowDialog(null));
 }
Exemplo n.º 4
0
        public void ShowDialog_NonControlOwnerWithHandle_ThrowsWin32Exception()
        {
            var dialog = new SubCommonDialog();
            var owner  = new Mock <IWin32Window>(MockBehavior.Strict);

            owner
            .Setup(o => o.Handle)
            .Returns((IntPtr)1);
            Assert.Throws <Win32Exception>(() => dialog.ShowDialog(owner.Object));
        }
Exemplo n.º 5
0
 public void ShowDialog_ControlOwnerWithHandle_ReturnsExpected(bool runDialogResult, DialogResult expectedDialogResult)
 {
     using var dialog = new SubCommonDialog
           {
               RunDialogResult = runDialogResult
           };
     using var owner = new Control();
     Assert.NotEqual(IntPtr.Zero, owner.Handle);
     Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
 }
Exemplo n.º 6
0
        public void ShowDialog_ControlOwnerWithVisualStyles_ReturnsExpected(bool runDialogResult, DialogResult expectedDialogResult)
        {
            Application.EnableVisualStyles();

            using var dialog = new SubCommonDialog
                  {
                      RunDialogResult = runDialogResult
                  };
            using var owner = new Control();
            Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
        }
Exemplo n.º 7
0
        public void Tag_Set_GetReturnsExpected(object value)
        {
            using var dialog = new SubCommonDialog()
                  {
                      Tag = value
                  };
            Assert.Same(value, dialog.Tag);

            // Set same.
            dialog.Tag = value;
            Assert.Same(value, dialog.Tag);
        }
Exemplo n.º 8
0
 public void Ctor_Default()
 {
     using var dialog = new SubCommonDialog();
     Assert.True(dialog.CanRaiseEvents);
     Assert.Null(dialog.Container);
     Assert.False(dialog.DesignMode);
     Assert.NotNull(dialog.Events);
     Assert.Same(dialog.Events, dialog.Events);
     Assert.Null(dialog.Container);
     Assert.Null(dialog.Site);
     Assert.Null(dialog.Tag);
 }
Exemplo n.º 9
0
        public void ShowDialog_NonControlOwner_ReturnsExpected(bool runDialogResult, DialogResult expectedDialogResult)
        {
            var dialog = new SubCommonDialog
            {
                RunDialogResult = runDialogResult
            };
            var owner = new Mock <IWin32Window>(MockBehavior.Strict);

            owner
            .Setup(o => o.Handle)
            .Returns(IntPtr.Zero);
            Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner.Object));
        }
Exemplo n.º 10
0
        public void ShowDialog_ControlOwnerWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam)
        {
            // Run this from another thread as we call Application.EnableVisualStyles.
            RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) =>
            {
                bool runDialogResult = bool.Parse(runDialogResultString);
                DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString);

                Application.EnableVisualStyles();

                using var dialog = new SubCommonDialog
                      {
                          RunDialogResult = runDialogResult
                      };
                using var owner = new Control();
                Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
            }, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose();
        }
Exemplo n.º 11
0
        public void OwnerWndProc_NonHelpMessage_DoesNotCallHelpRequest()
        {
            var       dialog = new SubCommonDialog();
            FieldInfo field  = typeof(CommonDialog).GetField("s_helpMsg", BindingFlags.NonPublic | BindingFlags.Static);

            Assert.NotNull(field);

            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(dialog, sender);
                Assert.Same(EventArgs.Empty, e);
                callCount++;
            };

            dialog.HelpRequest += handler;
            Assert.Equal(IntPtr.Zero, dialog.OwnerWndProc(IntPtr.Zero, (int)field.GetValue(null) + 1, IntPtr.Zero, IntPtr.Zero));
            Assert.Equal(0, callCount);
        }
Exemplo n.º 12
0
        public void ShowDialog_NonControlOwnerWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam)
        {
            // Run this from another thread as we call Application.EnableVisualStyles.
            RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) =>
            {
                bool runDialogResult = bool.Parse(runDialogResultString);
                DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString);

                Application.EnableVisualStyles();

                using var dialog = new SubCommonDialog
                      {
                          RunDialogResult = runDialogResult
                      };
                var owner = new Mock <IWin32Window>(MockBehavior.Strict);
                owner
                .Setup(o => o.Handle)
                .Returns(IntPtr.Zero);
                Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner.Object));
            }, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose();
        }
Exemplo n.º 13
0
        public void HookProc_Invoke_ReturnsZero(int msg)
        {
            var dialog = new SubCommonDialog();

            Assert.Equal(IntPtr.Zero, dialog.HookProc(IntPtr.Zero, msg, IntPtr.Zero, IntPtr.Zero));
        }