Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] System.IO.Abstractions update #21061

Merged
merged 2 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/modules/Hosts/Hosts.Tests/Hosts.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
58 changes: 9 additions & 49 deletions src/modules/Hosts/Hosts.Tests/HostsServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,13 +30,8 @@ public static void ClassInitialize(TestContext context)
[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();
Expand All @@ -47,15 +42,8 @@ public void Hosts_Exists()
[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();

Expand All @@ -76,13 +64,8 @@ 10.1.1.2 host2 host2.local # another comment
# 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));

Expand All @@ -106,13 +89,8 @@ 10.1.1.2 host2 host2.local # another comment
@"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));

Expand All @@ -137,13 +115,8 @@ 10.1.1.2 host2 host2.local # another comment
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));

Expand All @@ -162,11 +135,7 @@ 10.1.1.2 host2 host2.local # another comment
[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);
Expand Down Expand Up @@ -197,14 +166,9 @@ 10.1.1.1 host host.local # comment
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));

Expand Down Expand Up @@ -234,11 +198,7 @@ 10.1.1.2 host2 host2.local # another comment
# 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);

Expand Down
20 changes: 20 additions & 0 deletions src/modules/Hosts/Hosts.Tests/Mocks/CustomMockFileSystem.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -26,13 +27,15 @@ public class TestFileSystemWatcher : FileSystemWatcherBase

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/modules/Hosts/Hosts/Hosts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/imageresizer/tests/ImageResizerUITest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion src/modules/imageresizer/ui/ImageResizerUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,7 +32,7 @@ public void SetupMock()
{ @"c:\Test\b\", new MockDirectoryData() },
});

_queryFileSystemInfoMock = new QueryFileSystemInfo(_fileSystem.DirectoryInfo);
_queryFileSystemInfoMock = new QueryFileSystemInfo(_fileSystem.DirectoryInfo, MatchType.Simple, FileAttributes.Hidden | FileAttributes.System);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/previewpane/common/PreviewHandlerCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Loading