Skip to content

Commit

Permalink
split out file store tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dazfuller committed Oct 18, 2024
1 parent 56cee49 commit 8823edf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
50 changes: 50 additions & 0 deletions DotPrompt.Tests/FilePromptStoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace DotPrompt.Tests;

public class FilePromptStoreTests
{
[Fact]
public void FilePromptStore_WithNoParameters_CreatesInstanceUsingDefaultPath()
{
var promptStore = new FilePromptStore();

Assert.Equal("prompts", promptStore.PromptDirectory.Name);
}

[Fact]
public void FilePromptStore_WithValidPath_CreatesInstance()
{
var promptStore = new FilePromptStore("manager-prompts");

Assert.Equal("manager-prompts", promptStore.PromptDirectory.Name);
}

[Fact]
public void FilePromptStore_WithInvalidPathSpecified_ThrowsException()
{
var act = () => new FilePromptStore("does-not-exist");

var exception = Assert.Throws<ArgumentException>(act);
Assert.Contains("The specified path does not exist", exception.Message);
}

[Fact]
public void Load_WithVaryingCaseNames_RetrievesPromptsFromDirectory()
{
var promptStore = new FilePromptStore();

var promptFiles = promptStore.Load().ToList();

Assert.Contains("basic", promptFiles.Select(p => p.Name));
Assert.Contains("example-with-name", promptFiles.Select(p => p.Name));
}

[Fact]
public void Load_WhenCalledOnDirectoryWithSubDirectories_RetrievesAllPromptFiles()
{
var promptStore = new FilePromptStore("manager-prompts");

var promptFiles = promptStore.Load().ToList();

Assert.Equal(2, promptFiles.Count);
}
}
9 changes: 0 additions & 9 deletions DotPrompt.Tests/PromptManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,4 @@ public void GetPromptFile_WhenRequestedWithInvalidName_ThrowsException()
var exception = Assert.Throws<DotPromptException>(act);
Assert.Equal("No prompt file with that name has been loaded", exception.Message);
}

[Fact]
public void FilePromptStore_WithInvalidPathSpecified_ThrowsException()
{
var act = () => new FilePromptStore("does-not-exist");

var exception = Assert.Throws<ArgumentException>(act);
Assert.Contains("The specified path does not exist", exception.Message);
}
}
File renamed without changes.
4 changes: 4 additions & 0 deletions DotPrompt/DotPrompt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@
<ItemGroup>
<None Include="Docs\README.md" Pack="true" PackagePath=""/>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="DotPrompt.Tests" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions DotPrompt/FilePromptStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FilePromptStore : IPromptStore
/// <summary>
/// Holds the location selected by the client to manage prompt files from
/// </summary>
private readonly DirectoryInfo _promptDirectory;
internal readonly DirectoryInfo PromptDirectory;

/// <summary>
/// Creates a new instance of the <see cref="FilePromptStore"/> using the default location
Expand All @@ -30,9 +30,9 @@ public FilePromptStore() : this(DefaultPath) { }
/// <exception cref="ArgumentException">Thrown if the specified location does not exist</exception>
public FilePromptStore(string path)
{
_promptDirectory = new DirectoryInfo(path);
PromptDirectory = new DirectoryInfo(path);

if (!_promptDirectory.Exists)
if (!PromptDirectory.Exists)
{
throw new ArgumentException("The specified path does not exist", nameof(path));
}
Expand All @@ -53,7 +53,7 @@ public IEnumerable<PromptFile> Load()
IgnoreInaccessible = true
};

foreach (var file in _promptDirectory.EnumerateFiles("*.prompt", options))
foreach (var file in PromptDirectory.EnumerateFiles("*.prompt", options))
{
var promptFile = PromptFile.FromFile(file.FullName);
yield return promptFile;
Expand Down

0 comments on commit 8823edf

Please sign in to comment.