[Chore] System.IO.Abstractions update (#21061)

* System.IO.Abstractions update

* fix tests
This commit is contained in:
Davide Giacometti 2022-10-16 14:23:31 +02:00 коммит произвёл GitHub
Родитель 1c264e0899
Коммит 887da6dc1a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
22 изменённых файлов: 72 добавлений и 84 удалений

Просмотреть файл

@ -19,8 +19,8 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="12.2.3" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.IO.Abstractions.TestingHelpers;
using System.Linq;
using System.Threading.Tasks;
using Hosts.Helpers;
using Hosts.Models;
using Hosts.Settings;
using Hosts.Tests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Settings.UI.Library.Enumerations;
@ -30,13 +30,8 @@ namespace Hosts.Tests
[TestMethod]
public void Hosts_Exists()
{
var fileSystem = new MockFileSystem
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
var service = new HostsService(fileSystem, userSettings.Object, _elevationHelper.Object);
fileSystem.AddFile(service.HostsFilePath, new MockFileData(string.Empty));
var result = service.Exists();
@ -47,15 +42,8 @@ namespace Hosts.Tests
[TestMethod]
public void Hosts_Not_Exists()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
})
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
var service = new HostsService(fileSystem, userSettings.Object, _elevationHelper.Object);
var result = service.Exists();
@ -76,13 +64,8 @@ namespace Hosts.Tests
# 10.1.1.30 host30 host30.local # new entry
";
var fileSystem = new MockFileSystem
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
var service = new HostsService(fileSystem, userSettings.Object, _elevationHelper.Object);
fileSystem.AddFile(service.HostsFilePath, new MockFileData(content));
@ -106,13 +89,8 @@ namespace Hosts.Tests
@"10.1.1.2 host2 host2.local # another comment
";
var fileSystem = new MockFileSystem
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
var service = new HostsService(fileSystem, userSettings.Object, _elevationHelper.Object);
fileSystem.AddFile(service.HostsFilePath, new MockFileData(content));
@ -137,13 +115,8 @@ namespace Hosts.Tests
10.1.1.2 host2 host2.local # another comment
";
var fileSystem = new MockFileSystem
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
var service = new HostsService(fileSystem, userSettings.Object, _elevationHelper.Object);
fileSystem.AddFile(service.HostsFilePath, new MockFileData(content));
@ -162,11 +135,7 @@ namespace Hosts.Tests
[TestMethod]
public async Task Empty_Hosts()
{
var fileSystem = new MockFileSystem
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
var service = new HostsService(fileSystem, userSettings.Object, _elevationHelper.Object);
@ -197,14 +166,9 @@ namespace Hosts.Tests
10.1.1.2 host2 host2.local # another comment
";
var fileSystem = new MockFileSystem
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
userSettings.Setup(m => m.AdditionalLinesPosition).Returns(AdditionalLinesPosition.Top);
var service = new HostsService(fileSystem, userSettings.Object, _elevationHelper.Object);
fileSystem.AddFile(service.HostsFilePath, new MockFileData(content));
@ -234,11 +198,7 @@ namespace Hosts.Tests
# footer
";
var fileSystem = new MockFileSystem
{
FileSystemWatcher = new TestFileSystemWatcherFactory(),
};
var fileSystem = new CustomMockFileSystem();
var userSettings = new Mock<IUserSettings>();
userSettings.Setup(m => m.AdditionalLinesPosition).Returns(AdditionalLinesPosition.Bottom);

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
namespace Hosts.Tests.Mocks
{
public class CustomMockFileSystem : MockFileSystem
{
public override IFileSystemWatcherFactory FileSystemWatcher { get; }
public CustomMockFileSystem()
: base()
{
FileSystemWatcher = new MockFileSystemWatcherFactory();
}
}
}

Просмотреть файл

@ -2,13 +2,14 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.IO.Abstractions;
namespace Hosts.Tests
namespace Hosts.Tests.Mocks
{
public class TestFileSystemWatcher : FileSystemWatcherBase
public class MockFileSystemWatcher : FileSystemWatcherBase
{
public override bool IncludeSubdirectories { get; set; }
@ -26,13 +27,15 @@ namespace Hosts.Tests
public override ISynchronizeInvoke SynchronizingObject { get; set; }
public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType) => default(WaitForChangedResult);
public override Collection<string> Filters => throw new System.NotImplementedException();
public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) => default(WaitForChangedResult);
public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType) => default;
public TestFileSystemWatcher(string path) => Path = path;
public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) => default;
public TestFileSystemWatcher(string path, string filter)
public MockFileSystemWatcher(string path) => Path = path;
public MockFileSystemWatcher(string path, string filter)
{
Path = path;
Filter = filter;

Просмотреть файл

@ -4,16 +4,16 @@
using System.IO.Abstractions;
namespace Hosts.Tests
namespace Hosts.Tests.Mocks
{
public class TestFileSystemWatcherFactory : IFileSystemWatcherFactory
public class MockFileSystemWatcherFactory : IFileSystemWatcherFactory
{
public IFileSystemWatcher CreateNew() => new TestFileSystemWatcher(null);
public IFileSystemWatcher CreateNew() => new MockFileSystemWatcher(null);
public IFileSystemWatcher CreateNew(string path) => new TestFileSystemWatcher(path);
public IFileSystemWatcher CreateNew(string path) => new MockFileSystemWatcher(path);
public IFileSystemWatcher CreateNew(string path, string filter) => new TestFileSystemWatcher(path, filter);
public IFileSystemWatcher CreateNew(string path, string filter) => new MockFileSystemWatcher(path, filter);
public IFileSystemWatcher FromPath(string path) => new TestFileSystemWatcher(path);
public IFileSystemWatcher FromPath(string path) => new MockFileSystemWatcher(path);
}
}

Просмотреть файл

@ -37,7 +37,7 @@
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.5" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="WinUIEx" Version="1.8.0" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Просмотреть файл

@ -43,7 +43,7 @@
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
<PackageReference Include="System.ComponentModel.Composition" Version="6.0.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>

Просмотреть файл

@ -48,7 +48,7 @@
<ItemGroup>
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -54,7 +54,7 @@
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>

Просмотреть файл

@ -48,7 +48,7 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
<PackageReference Include="System.IO.Abstractions">
<Version>12.2.5</Version>
<Version>17.2.3</Version>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>

Просмотреть файл

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions.TestingHelpers;
using System.Linq;
using Microsoft.Plugin.Folder.Sources;
@ -31,7 +32,7 @@ namespace Microsoft.Plugin.Folder.UnitTests
{ @"c:\Test\b\", new MockDirectoryData() },
});
_queryFileSystemInfoMock = new QueryFileSystemInfo(_fileSystem.DirectoryInfo);
_queryFileSystemInfoMock = new QueryFileSystemInfo(_fileSystem.DirectoryInfo, MatchType.Simple, FileAttributes.Hidden | FileAttributes.System);
}
[TestMethod]

Просмотреть файл

@ -13,7 +13,7 @@
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="12.2.3" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -54,7 +54,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@ -12,23 +12,27 @@ namespace Microsoft.Plugin.Folder.Sources
public class QueryFileSystemInfo : IQueryFileSystemInfo
{
private readonly IDirectoryInfoFactory _directoryInfoFactory;
private readonly MatchType _matchType;
private readonly FileAttributes _attributesToSkip;
public QueryFileSystemInfo(IDirectoryInfoFactory directoryInfoFactory)
public QueryFileSystemInfo(IDirectoryInfoFactory directoryInfoFactory, MatchType matchType = MatchType.Win32, FileAttributes attributesToSkip = FileAttributes.Hidden)
{
_directoryInfoFactory = directoryInfoFactory;
_matchType = matchType;
_attributesToSkip = attributesToSkip;
}
public IEnumerable<DisplayFileInfo> MatchFileSystemInfo(string search, string incompleteName, bool isRecursive)
{
// search folder and add results
var directoryInfo = _directoryInfoFactory.FromDirectoryName(search);
var fileSystemInfos = directoryInfo.EnumerateFileSystemInfos(incompleteName, new EnumerationOptions()
var fileSystemInfos = directoryInfo.EnumerateFileSystemInfos(incompleteName, new EnumerationOptions
{
MatchType = MatchType.Win32,
MatchType = _matchType,
RecurseSubdirectories = isRecursive,
IgnoreInaccessible = true,
ReturnSpecialDirectories = false,
AttributesToSkip = FileAttributes.Hidden,
AttributesToSkip = _attributesToSkip,
MatchCasing = MatchCasing.PlatformDefault,
});

Просмотреть файл

@ -44,7 +44,7 @@
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="NLog.Schema" Version="5.0.4" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>
</Project>

Просмотреть файл

@ -32,7 +32,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
</ItemGroup>

Просмотреть файл

@ -41,7 +41,7 @@
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
<PackageReference Include="Markdig.Signed" Version="0.27.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -28,7 +28,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -32,7 +32,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -27,6 +27,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
</ItemGroup>
</Project>

Просмотреть файл

@ -25,7 +25,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>

Просмотреть файл

@ -28,7 +28,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="12.2.3" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
</ItemGroup>
<ItemGroup>