From aa6648056fd94007ffb036afdb8dced9878a15dd Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sat, 30 Jun 2018 11:25:08 +1000 Subject: [PATCH] Create output directory if it doesn't exist --- src/dotnet-ad-core/Validation/WritableFileAttribute.cs | 1 + .../Validation/WritableFileAttributeTests.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dotnet-ad-core/Validation/WritableFileAttribute.cs b/src/dotnet-ad-core/Validation/WritableFileAttribute.cs index 9a6c2d1..f460d25 100644 --- a/src/dotnet-ad-core/Validation/WritableFileAttribute.cs +++ b/src/dotnet-ad-core/Validation/WritableFileAttribute.cs @@ -20,6 +20,7 @@ protected override ValidationResult IsValid(object value, ValidationContext cont try { + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); File.WriteAllText(fullPath, "q"); return ValidationResult.Success; } diff --git a/tests/dotnet-wad-to-csv-tests/Validation/WritableFileAttributeTests.cs b/tests/dotnet-wad-to-csv-tests/Validation/WritableFileAttributeTests.cs index 8212f6f..f914cb5 100644 --- a/tests/dotnet-wad-to-csv-tests/Validation/WritableFileAttributeTests.cs +++ b/tests/dotnet-wad-to-csv-tests/Validation/WritableFileAttributeTests.cs @@ -50,11 +50,15 @@ public void GivenNonWritableFilePath_WhenGetValidationResult_ThenErrorMessage() } [Fact] - public void GivenWritableFilePath_WhenGetValidationResult_ThenNoErrorMessage() + public void GivenWritableFilePathInNewDirectory_WhenGetValidationResult_ThenNoErrorMessage() { // Arrange - var writableFilePath = Path.GetTempFileName(); + var writableFilePath = Path.Combine( + Path.GetTempPath(), + "wad-to-csv-tests", + Guid.NewGuid().ToString(), + Path.GetRandomFileName()); SetTarget(writableFilePath);