Add WixBuildTools.TestSupport with common testing functionality
This commit is contained in:
Родитель
9a829ccb7b
Коммит
2c711ea621
|
@ -1,13 +1,13 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.3
|
||||
VisualStudioVersion = 15.0.27130.2003
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{00E50075-E896-42D1-AC30-2D2E7D129FB9}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.XsdGen", "src\WixBuildTools.XsdGen\WixBuildTools.XsdGen.csproj", "{E89E52C9-A4A1-4174-A1B1-3B72975E6ED6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.MsgGen", "src\WixBuildTools.MsgGen\WixBuildTools.MsgGen.csproj", "{DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixBuildTools.TestSupport", "src\WixBuildTools.TestSupport\WixBuildTools.TestSupport.csproj", "{6C57EF2C-979A-4106-A9E5-FE342810619A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -42,14 +42,22 @@ Global
|
|||
{DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x64.Build.0 = Release|Any CPU
|
||||
{DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DB6EF6F3-51B1-4214-9A14-D501C23F6FA4}.Release|x86.Build.0 = Release|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x64.Build.0 = Release|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{6C57EF2C-979A-4106-A9E5-FE342810619A}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{E89E52C9-A4A1-4174-A1B1-3B72975E6ED6} = {00E50075-E896-42D1-AC30-2D2E7D129FB9}
|
||||
{DB6EF6F3-51B1-4214-9A14-D501C23F6FA4} = {00E50075-E896-42D1-AC30-2D2E7D129FB9}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {83E9E075-B440-471A-9C37-9D84BA0AE3E0}
|
||||
EndGlobalSection
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<add key="wixtoolset-dtf" value="https://ci.appveyor.com/nuget/wixtoolset-dtf" />
|
||||
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -0,0 +1,113 @@
|
|||
// 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.
|
||||
|
||||
namespace WixBuildTools.TestSupport
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using WixToolset.Dtf.WindowsInstaller;
|
||||
|
||||
public class Builder
|
||||
{
|
||||
public Builder(string sourceFolder, Type extensionType = null, string[] bindPaths = null)
|
||||
{
|
||||
this.SourceFolder = sourceFolder;
|
||||
this.ExtensionType = extensionType;
|
||||
this.BindPaths = bindPaths;
|
||||
}
|
||||
|
||||
public string[] BindPaths { get; }
|
||||
|
||||
public Type ExtensionType { get; }
|
||||
|
||||
public string SourceFolder { get; }
|
||||
|
||||
public string[] BuildAndQuery(Action<string[]> buildFunc, params string[] tables)
|
||||
{
|
||||
var sourceFiles = Directory.GetFiles(this.SourceFolder, "*.wxs");
|
||||
var wxlFiles = Directory.GetFiles(this.SourceFolder, "*.wxl");
|
||||
|
||||
using (var fs = new DisposableFileSystem())
|
||||
{
|
||||
var intermediateFolder = fs.GetFolder();
|
||||
var outputPath = Path.Combine(intermediateFolder, @"bin\test.msi");
|
||||
|
||||
var args = new List<string>
|
||||
{
|
||||
"build",
|
||||
"-o", outputPath,
|
||||
"-intermediateFolder", intermediateFolder,
|
||||
};
|
||||
|
||||
if (this.ExtensionType != null)
|
||||
{
|
||||
args.Add("-ext");
|
||||
args.Add(Path.GetFullPath(new Uri(this.ExtensionType.Assembly.CodeBase).LocalPath));
|
||||
}
|
||||
|
||||
args.AddRange(sourceFiles);
|
||||
|
||||
foreach (var wxlFile in wxlFiles)
|
||||
{
|
||||
args.Add("-loc");
|
||||
args.Add(wxlFile);
|
||||
}
|
||||
|
||||
foreach (var bindPath in this.BindPaths)
|
||||
{
|
||||
args.Add("-bindpath");
|
||||
args.Add(bindPath);
|
||||
}
|
||||
|
||||
buildFunc(args.ToArray());
|
||||
|
||||
return this.Query(outputPath, tables);
|
||||
}
|
||||
}
|
||||
|
||||
private string[] Query(string path, string[] tables)
|
||||
{
|
||||
var results = new List<string>();
|
||||
|
||||
if (tables?.Length > 0)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
using (var db = new Database(path))
|
||||
{
|
||||
foreach (var table in tables)
|
||||
{
|
||||
using (var view = db.OpenView($"SELECT * FROM `{table}`"))
|
||||
{
|
||||
view.Execute();
|
||||
|
||||
Record record;
|
||||
while ((record = view.Fetch()) != null)
|
||||
{
|
||||
sb.Clear();
|
||||
sb.AppendFormat("{0}:", table);
|
||||
|
||||
using (record)
|
||||
{
|
||||
for (var i = 0; i < record.FieldCount; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
sb.Append("\t");
|
||||
}
|
||||
|
||||
sb.Append(record[i + 1]?.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
results.Add(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
// 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.
|
||||
|
||||
namespace WixBuildTools.TestSupport
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public class DisposableFileSystem : IDisposable
|
||||
{
|
||||
protected bool Disposed { get; private set; }
|
||||
|
||||
private List<string> CleanupPaths { get; } = new List<string>();
|
||||
|
||||
protected string GetFile(bool create = false)
|
||||
{
|
||||
var path = Path.GetTempFileName();
|
||||
|
||||
if (!create)
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
this.CleanupPaths.Add(path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public string GetFolder(bool create = false)
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
|
||||
if (create)
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
this.CleanupPaths.Add(path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
#region // IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (this.Disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
foreach (var path in this.CleanupPaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Best effort delete, so ignore any failures.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.Disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// 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.
|
||||
|
||||
namespace WixBuildTools.TestSupport
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public class Pushd : IDisposable
|
||||
{
|
||||
protected bool Disposed { get; private set; }
|
||||
|
||||
public Pushd(string path)
|
||||
{
|
||||
this.PreviousDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
Directory.SetCurrentDirectory(path);
|
||||
}
|
||||
|
||||
public string PreviousDirectory { get; }
|
||||
|
||||
#region // IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (this.Disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
Directory.SetCurrentDirectory(this.PreviousDirectory);
|
||||
}
|
||||
|
||||
this.Disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// 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.
|
||||
|
||||
namespace WixBuildTools.TestSupport
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public class TestData
|
||||
{
|
||||
public static string Get(params string[] paths)
|
||||
{
|
||||
var localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetCallingAssembly().CodeBase).LocalPath);
|
||||
return Path.Combine(localPath, Path.Combine(paths));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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. -->
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="WixToolset.Dtf.Resources" Version="4.0.*" />
|
||||
<PackageReference Include="WixToolset.Dtf.WindowsInstaller" Version="4.0.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Nerdbank.GitVersioning" Version="2.0.41" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Загрузка…
Ссылка в новой задаче