[ConditionalFact(Helpers.IsDrawingSupported)]
public void ExtractAssociatedIcon_FilePath_Success()
{
- using (Icon icon = Icon.ExtractAssociatedIcon(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico")))
+ ExtractAssociatedIcon_FilePath_Success(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
+ }
+
+ [PlatformSpecific(TestPlatforms.Windows)] // UNC
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Fix for #34122")]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void ExtractAssociatedIcon_UNCFilePath_Success()
+ {
+ string bitmapPath = Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico");
+ string bitmapPathRoot = Path.GetPathRoot(bitmapPath);
+ string bitmapUncPath = $"\\\\{Environment.MachineName}\\{bitmapPath.Substring(0, bitmapPathRoot.IndexOf(":"))}$\\{bitmapPath.Replace(bitmapPathRoot, "")}";
+
+ // Some path could not be accessible
+ // if so we just pass the test
+ try
+ {
+ File.Open(bitmapUncPath, FileMode.Open, FileAccess.Read, FileShare.Read).Dispose();
+ }
+ catch(IOException)
+ {
+ return;
+ }
+
+ Assert.True(new Uri(bitmapUncPath).IsUnc);
+
+ ExtractAssociatedIcon_FilePath_Success(bitmapUncPath);
+ }
+
+ private void ExtractAssociatedIcon_FilePath_Success(string filePath)
+ {
+ using (Icon icon = Icon.ExtractAssociatedIcon(filePath))
{
Assert.Equal(32, icon.Width);
Assert.Equal(32, icon.Height);
AssertExtensions.Throws<ArgumentNullException, ArgumentException>("filePath", null, () => Icon.ExtractAssociatedIcon(null));
}
- [ActiveIssue(20884, TestPlatforms.AnyUnix)]
- [ConditionalTheory(Helpers.IsDrawingSupported)]
- [InlineData("", "path")]
- [InlineData("\\\\uncpath", null)]
- public void ExtractAssociatedIcon_InvalidFilePath_ThrowsArgumentException(string filePath, string paramName)
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void ExtractAssociatedIcon_InvalidFilePath_ThrowsArgumentException()
{
- AssertExtensions.Throws<ArgumentException>(paramName, null, () => Icon.ExtractAssociatedIcon(filePath));
+ AssertExtensions.Throws<ArgumentException>("path", null, () => Icon.ExtractAssociatedIcon(""));
}