Commits

Douglas Mendizabal committed f991741

A few facts taken from the C++ sample.

Comments (0)

Files changed (7)

src/Setup/Model/DefaultInstallerAdapter.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Deployment.WindowsInstaller;
+
+namespace wpfsetup.Setup.Model
+{
+    /// <summary>
+    /// DefaultInstallerAdapter implements an InstallerAdapter using
+    /// DTF Installer static class.
+    /// </summary>
+    public class DefaultInstallerAdapter : IInstallerAdapter
+    {
+        public void SetInternalUI(InstallUIOptions options)
+        {
+            Installer.SetInternalUI(options);
+        }
+
+        public void SetExternalUI(ExternalUIHandler uiHandler, InstallLogModes options)
+        {
+            Installer.SetExternalUI(uiHandler, options);
+        }
+    }
+}

src/Setup/Model/IInstallerAdapter.cs

+using Microsoft.Deployment.WindowsInstaller;
+
+namespace wpfsetup.Setup.Model
+{
+    /// <summary>
+    /// Interface for the DTF Installer class. Useful for mocking.
+    /// </summary>
+    public interface IInstallerAdapter
+    {
+        void SetInternalUI(InstallUIOptions options);
+        void SetExternalUI(ExternalUIHandler uiHandler, InstallLogModes options);
+    }
+}

src/Setup/Setup.csproj

     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
-    <PlatformTarget>x86</PlatformTarget>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
     <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
     <OutputPath>bin\Debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <CodeAnalysisLogFile>bin\Debug\setup.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
     <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+    <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
+    <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+    <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
-    <PlatformTarget>x86</PlatformTarget>
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
     <OutputPath>bin\Release\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <CodeAnalysisLogFile>bin\Release\setup.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
     <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+    <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Microsoft.Deployment.WindowsInstaller, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ce35f76fcda82bad, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>C:\Program Files (x86)\Windows Installer XML v3.5\SDK\Microsoft.Deployment.WindowsInstaller.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="Model\DefaultInstallerAdapter.cs" />
     <Compile Include="RelayCommand.cs" />
+    <Compile Include="ViewModel\ExternalUIHandlerViewModel.cs" />
+    <Compile Include="Model\IInstallerAdapter.cs" />
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     <AppDesigner Include="Properties\" />
   </ItemGroup>
   <ItemGroup>
-    <Folder Include="Model\" />
     <Folder Include="Resources\" />
-    <Folder Include="ViewModel\" />
     <Folder Include="View\" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

src/Setup/ViewModel/ExternalUIHandlerViewModel.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Deployment.WindowsInstaller;
+using wpfsetup.Setup.Model;
+
+namespace wpfsetup.Setup.ViewModel
+{
+    public class ExternalUIHandlerViewModel
+    {
+        #region Fields
+
+        private IInstallerAdapter _installerAdapter;
+        private bool _firstTime;
+
+        #endregion // Fields
+
+        #region Constructor
+
+        public ExternalUIHandlerViewModel(IInstallerAdapter installerAdapter)
+        {
+            this._installerAdapter = installerAdapter;
+            this._installerAdapter.SetInternalUI(InstallUIOptions.Silent|InstallUIOptions.SourceResolutionOnly);
+            this._installerAdapter.SetExternalUI(this.BasicUIHandler, InstallLogModes.ActionData |
+                                                                      InstallLogModes.ActionStart |
+                                                                      InstallLogModes.CommonData | 
+                                                                      InstallLogModes.Error |
+                                                                      InstallLogModes.FatalExit |
+                                                                      InstallLogModes.Info |
+                                                                      InstallLogModes.Initialize |
+                                                                      InstallLogModes.OutOfDiskSpace |
+                                                                      InstallLogModes.Progress |
+                                                                      InstallLogModes.ResolveSource |
+                                                                      InstallLogModes.ShowDialog |
+                                                                      InstallLogModes.Terminate | 
+                                                                      InstallLogModes.User |
+                                                                      InstallLogModes.Warning);
+
+            this._firstTime = true;
+        }
+
+        #endregion // Constructor
+
+        public MessageResult BasicUIHandler(InstallMessage messagetype, string message, MessageButtons buttons, MessageIcon icon, MessageDefaultButton defaultbutton)
+        {
+            if (this._firstTime)
+            {
+                this._installerAdapter.SetInternalUI(InstallUIOptions.Basic);
+                this._firstTime = false;
+            }
+
+            return MessageResult.None;
+        }
+    }
+}

src/SetupTests/SetupTests.csproj

     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Microsoft.Deployment.WindowsInstaller, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ce35f76fcda82bad, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>C:\Program Files (x86)\Windows Installer XML v3.5\SDK\Microsoft.Deployment.WindowsInstaller.dll</HintPath>
+    </Reference>
     <Reference Include="Moq">
-      <HintPath>..\..\wpfsetup\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
+      <HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
     <Reference Include="xunit">
-      <HintPath>..\..\wpfsetup\packages\xunit.1.8.0.1545\lib\xunit.dll</HintPath>
+      <HintPath>..\packages\xunit.1.8.0.1545\lib\xunit.dll</HintPath>
     </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="ViewModel\ExternalUIHandlerViewModelTests.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Model\" />
-    <Folder Include="ViewModel\" />
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Setup\Setup.csproj">
+      <Project>{D7C220FE-6430-4336-BB8D-4E99EF681707}</Project>
+      <Name>Setup</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

src/SetupTests/ViewModel/ExternalUIHandlerViewModelTests.cs

+using System;
+using System.Collections.Generic;
+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, "MessageText", MessageButtons.OK,
+                                                      MessageIcon.Error, MessageDefaultButton.Button1);
+            externalUIHandlerViewModel.BasicUIHandler(InstallMessage.Error, "MessageText", 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);
+        }
+    }
+}
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
-		Debug|Mixed Platforms = Debug|Mixed Platforms
-		Debug|x86 = Debug|x86
 		Release|Any CPU = Release|Any CPU
-		Release|Mixed Platforms = Release|Mixed Platforms
-		Release|x86 = Release|x86
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Debug|Any CPU.ActiveCfg = Debug|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Debug|Mixed Platforms.Build.0 = Debug|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Debug|x86.ActiveCfg = Debug|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Debug|x86.Build.0 = Debug|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Release|Any CPU.ActiveCfg = Release|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Release|Mixed Platforms.ActiveCfg = Release|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Release|Mixed Platforms.Build.0 = Release|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Release|x86.ActiveCfg = Release|x86
-		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Release|x86.Build.0 = Release|x86
+		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D7C220FE-6430-4336-BB8D-4E99EF681707}.Release|Any CPU.Build.0 = Release|Any CPU
 		{425D8D82-49C3-4E8E-9317-013F26823033}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{425D8D82-49C3-4E8E-9317-013F26823033}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{425D8D82-49C3-4E8E-9317-013F26823033}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
-		{425D8D82-49C3-4E8E-9317-013F26823033}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
-		{425D8D82-49C3-4E8E-9317-013F26823033}.Debug|x86.ActiveCfg = Debug|Any CPU
 		{425D8D82-49C3-4E8E-9317-013F26823033}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{425D8D82-49C3-4E8E-9317-013F26823033}.Release|Any CPU.Build.0 = Release|Any CPU
-		{425D8D82-49C3-4E8E-9317-013F26823033}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
-		{425D8D82-49C3-4E8E-9317-013F26823033}.Release|Mixed Platforms.Build.0 = Release|Any CPU
-		{425D8D82-49C3-4E8E-9317-013F26823033}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE