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