aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-12-28 09:20:11 -0800
committerRob Mensching <rob@firegiant.com>2017-12-28 09:20:11 -0800
commit2c711ea621c03e415dc9ad9e9f103e09372b8c50 (patch)
tree415b00719d8f016e6edbd867947510d753224040
parent9a829ccb7b8cbc3432356f5b8deba081d64e3cb5 (diff)
downloadwix-2c711ea621c03e415dc9ad9e9f103e09372b8c50.tar.gz
wix-2c711ea621c03e415dc9ad9e9f103e09372b8c50.tar.bz2
wix-2c711ea621c03e415dc9ad9e9f103e09372b8c50.zip
Add WixBuildTools.TestSupport with common testing functionality
-rw-r--r--WixBuildTools.sln22
-rw-r--r--nuget.config1
-rw-r--r--src/WixBuildTools.TestSupport/Builder.cs113
-rw-r--r--src/WixBuildTools.TestSupport/DisposableFileSystem.cs86
-rw-r--r--src/WixBuildTools.TestSupport/Pushd.cs46
-rw-r--r--src/WixBuildTools.TestSupport/TestData.cs16
-rw-r--r--src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj21
7 files changed, 298 insertions, 7 deletions
diff --git a/WixBuildTools.sln b/WixBuildTools.sln
index d7f21621..b46c4ed1 100644
--- a/WixBuildTools.sln
+++ b/WixBuildTools.sln
@@ -1,13 +1,13 @@
1Microsoft Visual Studio Solution File, Format Version 12.00 1Microsoft Visual Studio Solution File, Format Version 12.00
2# Visual Studio 15 2# Visual Studio 15
3VisualStudioVersion = 15.0.26730.3 3VisualStudioVersion = 15.0.27130.2003
4MinimumVisualStudioVersion = 15.0.26124.0 4MinimumVisualStudioVersion = 15.0.26124.0
5Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{00E50075-E896-42D1-AC30-2D2E7D129FB9}"
6EndProject
7Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.XsdGen", "src\WixBuildTools.XsdGen\WixBuildTools.XsdGen.csproj", "{E89E52C9-A4A1-4174-A1B1-3B72975E6ED6}" 5Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.XsdGen", "src\WixBuildTools.XsdGen\WixBuildTools.XsdGen.csproj", "{E89E52C9-A4A1-4174-A1B1-3B72975E6ED6}"
8EndProject 6EndProject
9Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.MsgGen", "src\WixBuildTools.MsgGen\WixBuildTools.MsgGen.csproj", "{DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}" 7Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.MsgGen", "src\WixBuildTools.MsgGen\WixBuildTools.MsgGen.csproj", "{DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}"
10EndProject 8EndProject
9Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.TestSupport", "src\WixBuildTools.TestSupport\WixBuildTools.TestSupport.csproj", "{6C57EF2C-979A-4106-A9E5-FE342810619A}"
10EndProject
11Global 11Global
12 GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 GlobalSection(SolutionConfigurationPlatforms) = preSolution
13 Debug|Any CPU = Debug|Any CPU 13 Debug|Any CPU = Debug|Any CPU
@@ -42,14 +42,22 @@ Global
42 {DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x64.Build.0 = Release|Any CPU 42 {DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x64.Build.0 = Release|Any CPU
43 {DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x86.ActiveCfg = Release|Any CPU 43 {DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x86.ActiveCfg = Release|Any CPU
44 {DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x86.Build.0 = Release|Any CPU 44 {DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x86.Build.0 = Release|Any CPU
45 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|Any CPU.Build.0 = Debug|Any CPU
47 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x64.ActiveCfg = Debug|Any CPU
48 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x64.Build.0 = Debug|Any CPU
49 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x86.ActiveCfg = Debug|Any CPU
50 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x86.Build.0 = Debug|Any CPU
51 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|Any CPU.ActiveCfg = Release|Any CPU
52 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|Any CPU.Build.0 = Release|Any CPU
53 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x64.ActiveCfg = Release|Any CPU
54 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x64.Build.0 = Release|Any CPU
55 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x86.ActiveCfg = Release|Any CPU
56 {6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x86.Build.0 = Release|Any CPU
45 EndGlobalSection 57 EndGlobalSection
46 GlobalSection(SolutionProperties) = preSolution 58 GlobalSection(SolutionProperties) = preSolution
47 HideSolutionNode = FALSE 59 HideSolutionNode = FALSE
48 EndGlobalSection 60 EndGlobalSection
49 GlobalSection(NestedProjects) = preSolution
50 {E89E52C9-A4A1-4174-A1B1-3B72975E6ED6} = {00E50075-E896-42D1-AC30-2D2E7D129FB9}
51 {DB6EF6F3-51B1-4214-9A14-D501C23F6FA4} = {00E50075-E896-42D1-AC30-2D2E7D129FB9}
52 EndGlobalSection
53 GlobalSection(ExtensibilityGlobals) = postSolution 61 GlobalSection(ExtensibilityGlobals) = postSolution
54 SolutionGuid = {83E9E075-B440-471A-9C37-9D84BA0AE3E0} 62 SolutionGuid = {83E9E075-B440-471A-9C37-9D84BA0AE3E0}
55 EndGlobalSection 63 EndGlobalSection
diff --git a/nuget.config b/nuget.config
index 6e1ad9b5..fcbac27a 100644
--- a/nuget.config
+++ b/nuget.config
@@ -2,6 +2,7 @@
2<configuration> 2<configuration>
3 <packageSources> 3 <packageSources>
4 <clear /> 4 <clear />
5 <add key="wixtoolset-dtf" value="https://ci.appveyor.com/nuget/wixtoolset-dtf" />
5 <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> 6 <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
6 </packageSources> 7 </packageSources>
7</configuration> \ No newline at end of file 8</configuration> \ No newline at end of file
diff --git a/src/WixBuildTools.TestSupport/Builder.cs b/src/WixBuildTools.TestSupport/Builder.cs
new file mode 100644
index 00000000..62439ff7
--- /dev/null
+++ b/src/WixBuildTools.TestSupport/Builder.cs
@@ -0,0 +1,113 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport
4{
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 using System.Text;
9 using WixToolset.Dtf.WindowsInstaller;
10
11 public class Builder
12 {
13 public Builder(string sourceFolder, Type extensionType = null, string[] bindPaths = null)
14 {
15 this.SourceFolder = sourceFolder;
16 this.ExtensionType = extensionType;
17 this.BindPaths = bindPaths;
18 }
19
20 public string[] BindPaths { get; }
21
22 public Type ExtensionType { get; }
23
24 public string SourceFolder { get; }
25
26 public string[] BuildAndQuery(Action<string[]> buildFunc, params string[] tables)
27 {
28 var sourceFiles = Directory.GetFiles(this.SourceFolder, "*.wxs");
29 var wxlFiles = Directory.GetFiles(this.SourceFolder, "*.wxl");
30
31 using (var fs = new DisposableFileSystem())
32 {
33 var intermediateFolder = fs.GetFolder();
34 var outputPath = Path.Combine(intermediateFolder, @"bin\test.msi");
35
36 var args = new List<string>
37 {
38 "build",
39 "-o", outputPath,
40 "-intermediateFolder", intermediateFolder,
41 };
42
43 if (this.ExtensionType != null)
44 {
45 args.Add("-ext");
46 args.Add(Path.GetFullPath(new Uri(this.ExtensionType.Assembly.CodeBase).LocalPath));
47 }
48
49 args.AddRange(sourceFiles);
50
51 foreach (var wxlFile in wxlFiles)
52 {
53 args.Add("-loc");
54 args.Add(wxlFile);
55 }
56
57 foreach (var bindPath in this.BindPaths)
58 {
59 args.Add("-bindpath");
60 args.Add(bindPath);
61 }
62
63 buildFunc(args.ToArray());
64
65 return this.Query(outputPath, tables);
66 }
67 }
68
69 private string[] Query(string path, string[] tables)
70 {
71 var results = new List<string>();
72
73 if (tables?.Length > 0)
74 {
75 var sb = new StringBuilder();
76 using (var db = new Database(path))
77 {
78 foreach (var table in tables)
79 {
80 using (var view = db.OpenView($"SELECT * FROM `{table}`"))
81 {
82 view.Execute();
83
84 Record record;
85 while ((record = view.Fetch()) != null)
86 {
87 sb.Clear();
88 sb.AppendFormat("{0}:", table);
89
90 using (record)
91 {
92 for (var i = 0; i < record.FieldCount; ++i)
93 {
94 if (i > 0)
95 {
96 sb.Append("\t");
97 }
98
99 sb.Append(record[i + 1]?.ToString());
100 }
101 }
102
103 results.Add(sb.ToString());
104 }
105 }
106 }
107 }
108 }
109
110 return results.ToArray();
111 }
112 }
113}
diff --git a/src/WixBuildTools.TestSupport/DisposableFileSystem.cs b/src/WixBuildTools.TestSupport/DisposableFileSystem.cs
new file mode 100644
index 00000000..28440f90
--- /dev/null
+++ b/src/WixBuildTools.TestSupport/DisposableFileSystem.cs
@@ -0,0 +1,86 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport
4{
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8
9 public class DisposableFileSystem : IDisposable
10 {
11 protected bool Disposed { get; private set; }
12
13 private List<string> CleanupPaths { get; } = new List<string>();
14
15 protected string GetFile(bool create = false)
16 {
17 var path = Path.GetTempFileName();
18
19 if (!create)
20 {
21 File.Delete(path);
22 }
23
24 this.CleanupPaths.Add(path);
25
26 return path;
27 }
28
29 public string GetFolder(bool create = false)
30 {
31 var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
32
33 if (create)
34 {
35 Directory.CreateDirectory(path);
36 }
37
38 this.CleanupPaths.Add(path);
39
40 return path;
41 }
42
43
44 #region // IDisposable
45
46 public void Dispose()
47 {
48 this.Dispose(true);
49 GC.SuppressFinalize(this);
50 }
51
52 protected virtual void Dispose(bool disposing)
53 {
54 if (this.Disposed)
55 {
56 return;
57 }
58
59 if (disposing)
60 {
61 foreach (var path in this.CleanupPaths)
62 {
63 try
64 {
65 if (File.Exists(path))
66 {
67 File.Delete(path);
68 }
69 else if (Directory.Exists(path))
70 {
71 Directory.Delete(path, true);
72 }
73 }
74 catch
75 {
76 // Best effort delete, so ignore any failures.
77 }
78 }
79 }
80
81 this.Disposed = true;
82 }
83
84 #endregion
85 }
86}
diff --git a/src/WixBuildTools.TestSupport/Pushd.cs b/src/WixBuildTools.TestSupport/Pushd.cs
new file mode 100644
index 00000000..d0545215
--- /dev/null
+++ b/src/WixBuildTools.TestSupport/Pushd.cs
@@ -0,0 +1,46 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport
4{
5 using System;
6 using System.IO;
7
8 public class Pushd : IDisposable
9 {
10 protected bool Disposed { get; private set; }
11
12 public Pushd(string path)
13 {
14 this.PreviousDirectory = Directory.GetCurrentDirectory();
15
16 Directory.SetCurrentDirectory(path);
17 }
18
19 public string PreviousDirectory { get; }
20
21 #region // IDisposable
22
23 public void Dispose()
24 {
25 this.Dispose(true);
26 GC.SuppressFinalize(this);
27 }
28
29 protected virtual void Dispose(bool disposing)
30 {
31 if (this.Disposed)
32 {
33 return;
34 }
35
36 if (disposing)
37 {
38 Directory.SetCurrentDirectory(this.PreviousDirectory);
39 }
40
41 this.Disposed = true;
42 }
43
44 #endregion
45 }
46}
diff --git a/src/WixBuildTools.TestSupport/TestData.cs b/src/WixBuildTools.TestSupport/TestData.cs
new file mode 100644
index 00000000..fde9db54
--- /dev/null
+++ b/src/WixBuildTools.TestSupport/TestData.cs
@@ -0,0 +1,16 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport
4{
5 using System;
6 using System.IO;
7
8 public class TestData
9 {
10 public static string Get(params string[] paths)
11 {
12 var localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetCallingAssembly().CodeBase).LocalPath);
13 return Path.Combine(localPath, Path.Combine(paths));
14 }
15 }
16}
diff --git a/src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj b/src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj
new file mode 100644
index 00000000..e43a7753
--- /dev/null
+++ b/src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj
@@ -0,0 +1,21 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
4<Project Sdk="Microsoft.NET.Sdk">
5 <PropertyGroup>
6 <TargetFramework>netstandard2.0</TargetFramework>
7 </PropertyGroup>
8
9 <PropertyGroup>
10 <NoWarn>NU1701</NoWarn>
11 </PropertyGroup>
12
13 <ItemGroup>
14 <PackageReference Include="WixToolset.Dtf.Resources" Version="4.0.*" />
15 <PackageReference Include="WixToolset.Dtf.WindowsInstaller" Version="4.0.*" />
16 </ItemGroup>
17
18 <ItemGroup>
19 <PackageReference Include="Nerdbank.GitVersioning" Version="2.0.41" PrivateAssets="all" />
20 </ItemGroup>
21</Project>