Skip to content
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
7 changes: 4 additions & 3 deletions .github/workflows/copilot-code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ permissions:
contents: read
pull-requests: write

jobs:
jobs:
copilot-review:
runs-on: ubuntu-latest
runs-on: ubuntu-latest
if: false
steps:
- name: GitHub Copilot review
- name: GitHub Copilot review
uses: github/copilot-actions/review@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions src/TestStack.BDDfy.Tests/FileWriterShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Shouldly;
using TestStack.BDDfy.Reporters.Writers;
using Xunit;

namespace TestStack.BDDfy.Tests
{
public sealed class FileWriterShould
{
[Theory]
[InlineData("report.txt", null)]
[InlineData("./report.txt", null)]
[InlineData("reports/report.txt", null)]
[InlineData("./reports/report.txt", null)]
[InlineData("report.txt", "TestDirectory")]
[InlineData("./reports/report.txt", "TestDirectory")]
[InlineData("./reports/report.txt", "TestDirectory/Reports")]
public void CreatePathIfItDoesNotExist(string reportName, string outputDirectory)
{
var fileWriter = new FileWriter();
outputDirectory = outputDirectory is null ? null : System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString(), $"{outputDirectory}");
fileWriter.OutputReport("Test content", reportName, outputDirectory);
var expectedPath = System.IO.Path.Combine(outputDirectory ?? string.Empty, reportName);
System.IO.File.Exists(expectedPath).ShouldBeTrue();
System.IO.File.ReadAllText(expectedPath).ShouldBe("Test content");
}
}
}
13 changes: 7 additions & 6 deletions src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using System.IO;

namespace TestStack.BDDfy.Reporters.Writers
{
public class FileWriter : IReportWriter
{
public void OutputReport(string reportData, string reportName, string outputDirectory = null)
public void OutputReport(string reportData, string reportName, string? outputDirectory = null)
{
string directory = outputDirectory ?? FileHelpers.AssemblyDirectory();
var path = Path.Combine(directory, reportName);
var filePath = Path.Combine(outputDirectory ?? FileHelpers.AssemblyDirectory(), reportName);
string directory = Path.GetDirectoryName(filePath) ?? throw new InvalidOperationException("Unable to determine directory.");

if (File.Exists(path))
File.Delete(path);
File.WriteAllText(path, reportData);
Directory.CreateDirectory(directory);

File.WriteAllText(filePath, reportData);
}
}
}
1 change: 1 addition & 0 deletions src/TestStack.BDDfy/TestStack.BDDfy.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\Scripts\*.*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
Expand Down
Loading