Skip to content

Commit

Permalink
Remove not required FileShare option
Browse files Browse the repository at this point in the history
  • Loading branch information
smadala committed Jun 27, 2018
1 parent 46df71a commit c1b0202
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/vstest.console/CommandLine/AssemblyMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal class AssemblyMetadataProvider : IAssemblyMetadataProvider

internal AssemblyMetadataProvider(IFileHelper fileHelper)
{

this.fileHelper = fileHelper;
}

Expand All @@ -36,14 +35,14 @@ public FrameworkName GetFrameWork(string filePath)
FrameworkName frameworkName = new FrameworkName(Framework.DefaultFramework.Name);
try
{
using (var assemblyStream = this.fileHelper.GetStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var assemblyStream = this.fileHelper.GetStream(filePath, FileMode.Open, FileAccess.Read))
{
frameworkName = AssemblyMetadataProvider.GetFrameworkNameFromAssemblyMetadata(assemblyStream);
}
}
catch (Exception ex)
{
EqtTrace.Warning("AssemblyMetadataProvider.GetFrameWork: failed to determine TargetFrameworkVersion: {0} for assembly: {1}", ex, filePath);
EqtTrace.Warning("AssemblyMetadataProvider.GetFrameWork: failed to determine TargetFrameworkVersion exception: {0} for assembly: {1}", ex, filePath);
}

if (EqtTrace.IsInfoEnabled)
Expand Down Expand Up @@ -172,7 +171,7 @@ public Architecture GetArchitectureForSource(string imagePath)
try
{
//get the input stream
using (Stream fs = this.fileHelper.GetStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (Stream fs = this.fileHelper.GetStream(imagePath, FileMode.Open, FileAccess.Read))
using (var reader = new BinaryReader(fs))
{
var validImage = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.TestPlatform.CoreUtilities.UnitTests.Helpers
{
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VisualStudio.TestPlatform.Utilities.Helpers;

[TestClass]
public class FileHelperTests
{
private readonly FileHelper fileHelper;
private readonly string tempFile;

public FileHelperTests()
{
this.tempFile = Path.GetTempFileName();
File.AppendAllText(this.tempFile, "Some content..");
this.fileHelper = new FileHelper();
}

[TestCleanup]
public void Cleanup()
{
File.Delete(this.tempFile);
}

[TestMethod]
public void GetStreamShouldAbleToGetTwoStreamSimultanouslyIfFileAccessIsRead()
{
using (var stream1 = this.fileHelper.GetStream(this.tempFile, FileMode.Open, FileAccess.Read))
{
using (var stream2 =
this.fileHelper.GetStream(this.tempFile, FileMode.Open, FileAccess.Read))
{
}
}
}
}
}

0 comments on commit c1b0202

Please sign in to comment.