wpfsetup / src / SetupTests / ViewModel / ExternalUIHandlerViewModelTests.cs

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
using Moq;
using wpfsetup.Setup.Model;
using wpfsetup.Setup.ViewModel;
using Xunit;

namespace wpfsetup.Tests.ViewModel
{
    public class ExternalUIHandlerViewModelTests
    {
        [Fact]
        public void Installer_InternalUI_is_set_to_None_SourcesOnly()
        {
            var mockInstallerAdapter = new Mock<IInstallerAdapter>();
            var externalUIHandlerViewModel = new ExternalUIHandlerViewModel(mockInstallerAdapter.Object);
            mockInstallerAdapter.Verify(m => m.SetInternalUI(InstallUIOptions.Silent | InstallUIOptions.SourceResolutionOnly), Times.AtLeastOnce());
        }

        [Fact]
        public void Installer_ExternalUI_InstallUIOptions_are_set()
        {
            var mockInstallerAdapter = new Mock<IInstallerAdapter>();
            var externalUIHandlerViewModel = new ExternalUIHandlerViewModel(mockInstallerAdapter.Object);
            mockInstallerAdapter.Verify(
                m =>
                m.SetExternalUI(It.IsAny<ExternalUIHandler>(),
                                InstallLogModes.Progress |
                                InstallLogModes.FatalExit |
                                InstallLogModes.Error |
                                InstallLogModes.Warning |
                                InstallLogModes.User |
                                InstallLogModes.Info |
                                InstallLogModes.ResolveSource |
                                InstallLogModes.OutOfDiskSpace |
                                InstallLogModes.ActionStart |
                                InstallLogModes.ActionData |
                                InstallLogModes.CommonData |
                                InstallLogModes.Initialize |
                                InstallLogModes.Terminate |
                                InstallLogModes.ShowDialog));
        }

        [Fact]
        public void BasicUIHandler_matches_ExternalUIHandler_signature()
        {
            var mockInstallerAdapter = new Mock<IInstallerAdapter>();
            var externalUIHandlerViewModel = new ExternalUIHandlerViewModel(mockInstallerAdapter.Object);
            ExternalUIHandler externalUIHandler = externalUIHandlerViewModel.BasicUIHandler;
            Assert.Equal(externalUIHandler, externalUIHandlerViewModel.BasicUIHandler);
        }

        [Fact]
        public void BasicUIHandler_sets_IntenalUI_to_Basic_only_once()
        {
            var mockInstallerAdapter = new Mock<IInstallerAdapter>();
            var externalUIHandlerViewModel = new ExternalUIHandlerViewModel(mockInstallerAdapter.Object);
            externalUIHandlerViewModel.BasicUIHandler(InstallMessage.Error, "", MessageButtons.OK,
                                                      MessageIcon.Error, MessageDefaultButton.Button1);
            externalUIHandlerViewModel.BasicUIHandler(InstallMessage.Error, "", MessageButtons.OK,
                                                      MessageIcon.Error, MessageDefaultButton.Button1);
            mockInstallerAdapter.Verify(m => m.SetInternalUI(InstallUIOptions.Basic), Times.Exactly(1));
        }

        [Fact]
        public void BasicUIHandler_returns_MessageResultNone_if_the_message_is_empty()
        {
            var mockInstallerAdapter = new Mock<IInstallerAdapter>();
            var externalUIHandlerViewModel = new ExternalUIHandlerViewModel(mockInstallerAdapter.Object);
            var message = "";
            var returnedMessageResult = externalUIHandlerViewModel.BasicUIHandler(InstallMessage.Error, message,
                                                                                  MessageButtons.OK, MessageIcon.Error,
                                                                                  MessageDefaultButton.Button1);
            Assert.Equal(MessageResult.None, returnedMessageResult);
        }

        [Fact (Skip = "Actually shows the window, so we want to skip this for automated testing.")]
        public void BasicUIHandler_shows_User32MessageBox()
        {
            var ia = new Mock<IInstallerAdapter>();
            var vm = new ExternalUIHandlerViewModel(ia.Object);
            var message = "Error message text here.";
            var returnedMessageResult = vm.BasicUIHandler(InstallMessage.FatalExit,
                                                          message,
                                                          MessageButtons.RetryCancel,
                                                          MessageIcon.Information,
                                                          MessageDefaultButton.Button3);
            switch (returnedMessageResult)
            {
                case MessageResult.Error:
                    Debug.WriteLine("Error");
                    break;
                case MessageResult.None:
                    Debug.WriteLine("None");
                    break;
                case MessageResult.OK:
                    Debug.WriteLine("OK");
                    break;
                case MessageResult.Cancel:
                    Debug.WriteLine("Cancel");
                    break;
                case MessageResult.Abort:
                    Debug.WriteLine("Abort");
                    break;
                case MessageResult.Retry:
                    Debug.WriteLine("Retry");
                    break;
                case MessageResult.Ignore:
                    Debug.WriteLine("Ignore");
                    break;
                case MessageResult.Yes:
                    Debug.WriteLine("Yes");
                    break;
                case MessageResult.No:
                    Debug.WriteLine("No");
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.