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

Added exception handling while creating "TestResults" folder #2450

Merged
merged 8 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.DataCollector
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

/// <summary>
Expand Down Expand Up @@ -117,11 +118,21 @@ public void Initialize(SessionId id, string outputDirectory, IMessageSink messag
this.SessionOutputDirectory = Path.Combine(absolutePath, id.Id.ToString());
}

// Create the output directory if it doesn't exist.
if (!Directory.Exists(this.SessionOutputDirectory))
try
{
// Create the output directory if it doesn't exist.
if (!Directory.Exists(this.SessionOutputDirectory))
{
Directory.CreateDirectory(this.SessionOutputDirectory);
}
}
catch (UnauthorizedAccessException accessException)
{
Directory.CreateDirectory(this.SessionOutputDirectory);
string accessDeniedMessage = string.Format(CultureInfo.CurrentCulture, Resources.Resources.AccessDenied, accessException.Message);
Sanan07 marked this conversation as resolved.
Show resolved Hide resolved
ConsoleOutput.Instance.Error(false, accessDeniedMessage);
throw;
}

}

/// <inheritdoc/>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AccessDenied" xml:space="preserve">
Sanan07 marked this conversation as resolved.
Show resolved Hide resolved
<value>{0} Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</value>
Sanan07 marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="CancellationRequested" xml:space="preserve">
<value>Cancelling the operation as requested.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Nepovedlo se načíst rozšíření ze souboru {0}. Další informace získáte pomocí parametru /diag.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
Sanan07 marked this conversation as resolved.
Show resolved Hide resolved
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Fehler beim Laden von Erweiterungen aus der Datei "{0}". Verwenden Sie "/diag", um weitere Informationen zu erhalten.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">No se pudieron cargar las extensiones del archivo "{0}". Use /diag para obtener más información.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Le chargement des extensions à partir du fichier '{0}' a échoué. Pour plus d'informations, utilisez /diag.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Non è stato possibile caricare le estensioni dal file '{0}'. Per altre informazioni, usare /diag.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">ファイル '{0}' から拡張機能を読み込めませんでした。詳細な情報を得るには、/diag をご使用ください。</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">'{0}' 파일에서 확장을 로드하지 못했습니다. 자세한 내용을 보려면 /diag를 사용하세요.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Nie można załadować rozszerzeń z pliku „{0}”. Aby uzyskać więcej informacji, użyj opcji /diag.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Falha ao carregar as extensões do arquivo '{0}'. Use /diag para obter mais informações.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Не удалось загрузить расширения из файла "{0}". Для получения дополнительных сведений используйте /diag.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">Uzantılar '{0}' dosyasından yüklenemedi. Daha fazla bilgi için lütfen /diag kullanın.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">未能从文件 "{0}" 加载扩展。有关详细信息,请使用 /diag。</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<target state="translated">無法從檔案 '{0}' 載入延伸模組。如需詳細資訊,請使用 /diag。</target>
<note></note>
</trans-unit>
<trans-unit id="AccessDenied">
<source>{0}. Access denied while trying to create "TestResults" folder in mentioned location. You are getting this exception because you are running vstest.console.exe from a folder which requires having write access. To solve the issue : please run vstest.console.exe from a folder where you have write privileges to that folder. For more information, please look at the error message :</source>
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.DataCollector.UnitTests
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Security.AccessControl;
Sanan07 marked this conversation as resolved.
Show resolved Hide resolved


Sanan07 marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.VisualStudio.TestPlatform.Common.DataCollector.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
Expand Down Expand Up @@ -72,7 +74,7 @@ public void InitializeShouldSetCorrectGuidAndOutputPath()

Assert.AreEqual(Path.Combine(TempDirectoryPath, this.sessionId.Id.ToString()), this.attachmentManager.SessionOutputDirectory);
}

Sanan07 marked this conversation as resolved.
Show resolved Hide resolved
[TestMethod]
public void AddAttachmentShouldNotAddNewFileTransferIfSessionIsNotConfigured()
{
Expand Down