feat: implement read and write methods for json file storage provider
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
[*.cs]
|
||||
|
||||
dotnet_diagnostic.CA1707.severity = none
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net11.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
<Using Include="AwesomeAssertions" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\StevanFreeborn.Extensions.Configuration.Secure\StevanFreeborn.Extensions.Configuration.Secure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
using StevanFreeborn.Extensions.Configuration.Secure.Storage;
|
||||
|
||||
namespace StevanFreeborn.Extensions.Configuration.Secure.Tests.Unit.Storage;
|
||||
|
||||
public class JsonFileStorageProviderTests
|
||||
{
|
||||
private readonly string _tmpDirectory;
|
||||
private readonly JsonStorageOptions _options;
|
||||
private readonly JsonFileStorageProvider _sut;
|
||||
|
||||
public JsonFileStorageProviderTests()
|
||||
{
|
||||
_tmpDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(_tmpDirectory);
|
||||
|
||||
_options = new()
|
||||
{
|
||||
FileName = "testsettings.json"
|
||||
};
|
||||
|
||||
_sut = new(_options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithNullOptions_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var act = static () => new JsonFileStorageProvider(null!);
|
||||
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WriteAsync_And_ReadAsync_WhenCalled_ItShouldBeAbleToPersistAndRetrieveValues()
|
||||
{
|
||||
var configKey = "Key";
|
||||
var configValue = "Value";
|
||||
|
||||
await _sut.WriteAsync(configKey, configValue);
|
||||
var result = await _sut.ReadAsync(configKey);
|
||||
|
||||
result.Should().Be(configValue);
|
||||
File.Exists(_options.FullPath).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using StevanFreeborn.Extensions.Configuration.Secure.Storage;
|
||||
|
||||
namespace StevanFreeborn.Extensions.Configuration.Secure.Tests.Unit.Storage;
|
||||
|
||||
public class JsonStorageOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Path_WhenCalledWithFileNameSet_ItShouldReturnExpectedPath()
|
||||
{
|
||||
var fileName = "appsettings.json";
|
||||
var expectedPath = Path.Combine(AppContext.BaseDirectory, fileName);
|
||||
|
||||
var opts = new JsonStorageOptions()
|
||||
{
|
||||
FileName = fileName,
|
||||
};
|
||||
|
||||
opts.FullPath.Should().Be(expectedPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Path_WhenCalledWithFileNameAndDirectoryPathSet_ItShouldReturnExpectedPath()
|
||||
{
|
||||
var fileName = "appsettings.json";
|
||||
var directoryPath = @"C:\Path\To\Some\Directory";
|
||||
var expectedPath = Path.Combine(directoryPath, fileName);
|
||||
|
||||
var opts = new JsonStorageOptions()
|
||||
{
|
||||
FileName = fileName,
|
||||
DirectoryPath = directoryPath,
|
||||
};
|
||||
|
||||
opts.FullPath.Should().Be(expectedPath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user