1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// 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 WixToolsetTest.MsiE2E;
using System;
using System.IO;
using WixTestTools;
using Xunit;
using Xunit.Abstractions;
public class TouchFileTests : MsiE2ETests
{
public TouchFileTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
}
[RuntimeFact]
public void CanValidateTouchFile()
{
var touchFileTestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "touch-file-test.txt");
try
{
var touchFileTime = new DateTime(2004, 4, 5, 0, 0, 0, DateTimeKind.Utc);
File.WriteAllText(touchFileTestPath, "This file exists to test CanValidateTouchFile()");
File.SetCreationTimeUtc(touchFileTestPath, touchFileTime);
File.SetLastAccessTimeUtc(touchFileTestPath, touchFileTime);
File.SetLastWriteTimeUtc(touchFileTestPath, touchFileTime);
var product = this.CreatePackageInstaller("TouchFile");
var justBeforeInstall = DateTime.UtcNow;
product.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
var touchFile = new FileInfo(touchFileTestPath);
Assert.Equal(touchFileTime, touchFile.CreationTimeUtc);
Assert.Equal(touchFileTime, touchFile.LastAccessTimeUtc);
Assert.True(touchFile.LastWriteTimeUtc >= justBeforeInstall, $"Touch file {touchFileTestPath} last write time: {touchFile.LastWriteTimeUtc} of file should have been updated to at least: {justBeforeInstall}");
product.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
}
finally
{
File.Delete(touchFileTestPath);
}
}
}
|