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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Testcontainers.PostgreSql" />
Expand Down
28 changes: 14 additions & 14 deletions src/ConfigWay.PostgreSQL.Tests/Integration/PostgresApiTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Net;
using System.Net.Http.Json;
using System.Text.Json;
using FluentAssertions;
using Kododo.ConfigWay.PostgreSQL.Tests.Fixtures;
using Kododo.ConfigWay.UI;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -52,33 +51,34 @@ public async Task DisposeAsync()
public async Task GetConfiguration_Returns200()
{
var response = await PostGetConfiguration();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
public async Task GetConfiguration_ReturnsRegisteredOptions()
{
var sections = await FetchSections();

sections.Should().HaveCount(2);
sections.Select(s => s.Key).Should().BeEquivalentTo("Simple", "Nested");
Assert.Equal(2, sections.Length);
Assert.Equivalent(new[] { "Simple", "Nested" }, sections.Select(s => s.Key), strict: true);
}

[Fact]
public async Task GetConfiguration_InitialValues_AreNull()
{
var sections = await FetchSections();
sections.SelectMany(s => s.Fields).Should().AllSatisfy(f => f.Value.Should().BeNull());
Assert.All(sections.SelectMany(s => s.Fields), f => Assert.Null(f.Value));
}

[Fact]
public async Task UpdateConfiguration_ValidSettings_Returns200WithEmptyErrors()
{
var response = await PostUpdate(new[] { new { key = "Simple:Name", value = "Alice" } });

response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var errors = await response.Content.ReadFromJsonAsync<string[]>();
errors.Should().BeEmpty();
Assert.NotNull(errors);
Assert.Empty(errors);
}

[Fact]
Expand All @@ -89,7 +89,7 @@ public async Task UpdateConfiguration_AfterSave_GetReturnsUpdatedValue()
var sections = await FetchSections();
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().Be("Alice");
Assert.Equal("Alice", field.Value);
}

[Fact]
Expand All @@ -104,7 +104,7 @@ public async Task UpdateConfiguration_PersistedToPostgres_SurvivesAppRestart()
var sections = (await response.Content.ReadFromJsonAsync<SectionDto[]>())!;
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().Be("Persistent");
Assert.Equal("Persistent", field.Value);
}

[Fact]
Expand All @@ -116,7 +116,7 @@ public async Task UpdateConfiguration_MultipleUpdates_LastValueWins()
var sections = await FetchSections();
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().Be("Second");
Assert.Equal("Second", field.Value);
}

[Fact]
Expand All @@ -133,8 +133,8 @@ await PostUpdate(new[]
var sections = await FetchSections();
var fields = sections.Single(s => s.Key == "Simple").Fields;

fields.Single(f => f.Key == "Name").Value.Should().Be("Bob");
fields.Single(f => f.Key == "Value").Value.Should().Be("42");
Assert.Equal("Bob", fields.Single(f => f.Key == "Name").Value);
Assert.Equal("42", fields.Single(f => f.Key == "Value").Value);
}

[Fact]
Expand All @@ -146,7 +146,7 @@ public async Task UpdateConfiguration_NestedField_PersistedAndRetrieved()
var subSection = sections.Single(s => s.Key == "Nested").Sections.Single(s => s.Key == "Child");
var field = subSection.Fields.Single(f => f.Key == "ChildProp");

field.Value.Should().Be("deep");
Assert.Equal("deep", field.Value);
}

[Fact]
Expand All @@ -158,7 +158,7 @@ public async Task UpdateConfiguration_NullValue_ClearsField()
var sections = await FetchSections();
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().BeNull();
Assert.Null(field.Value);
}

private Task<HttpResponseMessage> PostGetConfiguration() =>
Expand Down
34 changes: 16 additions & 18 deletions src/ConfigWay.PostgreSQL.Tests/StoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Kododo.ConfigWay.Core.Model;
using Kododo.ConfigWay.PostgreSQL.Tests.Fixtures;
using Xunit;
Expand Down Expand Up @@ -27,21 +26,20 @@ public async Task InitializeAsync_CreatesSchemaAndTable()
{
await _store.SetAsync([new Setting("probe", "ok")]);
var result = await _store.GetAllAsync();
result.Should().ContainSingle(s => s.Key == "probe");
Assert.Single(result, s => s.Key == "probe");
}

[Fact]
public async Task InitializeAsync_WhenCalledTwice_IsIdempotent()
{
var act = async () => await _store.InitializeAsync();
await act.Should().NotThrowAsync();
await _store.InitializeAsync();
}

[Fact]
public async Task GetAll_WhenTableIsEmpty_ReturnsEmptyList()
{
var result = await _store.GetAllAsync();
result.Should().BeEmpty();
Assert.Empty(result);
}

[Fact]
Expand All @@ -55,8 +53,8 @@ await _store.SetAsync([

var result = await _store.GetAllAsync();

result.Should().HaveCount(3);
result.Select(s => s.Key).Should().BeEquivalentTo("Key1", "Key2", "Key3");
Assert.Equal(3, result.Count);
Assert.Equivalent(new[] { "Key1", "Key2", "Key3" }, result.Select(s => s.Key), strict: true);
}

[Fact]
Expand All @@ -66,7 +64,7 @@ public async Task GetAll_WhenValueIsNull_ReturnsSettingWithNullValue()

var result = await _store.GetAllAsync();

result.Single(s => s.Key == "NullKey").Value.Should().BeNull();
Assert.Null(result.Single(s => s.Key == "NullKey").Value);
}

[Fact]
Expand All @@ -75,7 +73,7 @@ public async Task Set_NewKey_InsertsRow()
await _store.SetAsync([new Setting("New", "value")]);

var result = await _store.GetAllAsync();
result.Should().ContainSingle(s => s.Key == "New" && s.Value == "value");
Assert.Single(result, s => s.Key == "New" && s.Value == "value");
}

[Fact]
Expand All @@ -85,8 +83,8 @@ public async Task Set_ExistingKey_UpdatesValueInPlace()
await _store.SetAsync([new Setting("Key", "NewValue")]);

var result = await _store.GetAllAsync();
result.Should().ContainSingle();
result.Single().Value.Should().Be("NewValue");
Assert.Single(result);
Assert.Equal("NewValue", result.Single().Value);
}

[Fact]
Expand All @@ -97,7 +95,7 @@ public async Task Set_ExistingKey_DoesNotDuplicateRow()
await _store.SetAsync([new Setting("Key", "C")]);

var result = await _store.GetAllAsync();
result.Should().ContainSingle(s => s.Key == "Key");
Assert.Single(result, s => s.Key == "Key");
}

[Fact]
Expand All @@ -106,7 +104,7 @@ public async Task Set_NullValue_StoredAndRetrievedAsNull()
await _store.SetAsync([new Setting("Key", null)]);

var result = await _store.GetAllAsync();
result.Single().Value.Should().BeNull();
Assert.Null(result.Single().Value);
}

[Fact]
Expand All @@ -116,7 +114,7 @@ public async Task Set_NullThenNonNull_Overwrites()
await _store.SetAsync([new Setting("Key", "value")]);

var result = await _store.GetAllAsync();
result.Single().Value.Should().Be("value");
Assert.Equal("value", result.Single().Value);
}

[Fact]
Expand All @@ -129,7 +127,7 @@ public async Task Set_MultipleSettings_AllInsertedInSingleCall()
await _store.SetAsync(settings);

var result = await _store.GetAllAsync();
result.Should().HaveCount(10);
Assert.Equal(10, result.Count);
}

[Fact]
Expand All @@ -140,10 +138,10 @@ public async Task Set_AfterPartialInsert_RollsBackAllChanges()
var brokenStore = new Store("Host=127.0.0.1;Port=9;Database=x;Username=x;Password=x");

var act = async () => await brokenStore.SetAsync([new Setting("K", "V")]);
await act.Should().ThrowAsync<Exception>();
await Assert.ThrowsAnyAsync<Exception>(act);

var result = await _store.GetAllAsync();
result.Should().ContainSingle(s => s.Key == "Existing" && s.Value == "before");
Assert.Single(result, s => s.Key == "Existing" && s.Value == "before");
}

[Fact]
Expand All @@ -155,7 +153,7 @@ public async Task Set_DataPersistedAcrossStoreInstances()
await freshStore.InitializeAsync();

var result = await freshStore.GetAllAsync();
result.Should().Contain(s => s.Key == "Persistent" && s.Value == "data");
Assert.Contains(result, s => s.Key == "Persistent" && s.Value == "data");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Testcontainers.MsSql" />
Expand Down
28 changes: 14 additions & 14 deletions src/ConfigWay.SqlServer.Tests/Integration/SqlServerApiTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Net;
using System.Net.Http.Json;
using System.Text.Json;
using FluentAssertions;
using Kododo.ConfigWay.SqlServer.Tests.Fixtures;
using Kododo.ConfigWay.UI;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -52,33 +51,34 @@ public async Task DisposeAsync()
public async Task GetConfiguration_Returns200()
{
var response = await PostGetConfiguration();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
public async Task GetConfiguration_ReturnsRegisteredOptions()
{
var sections = await FetchSections();

sections.Should().HaveCount(2);
sections.Select(s => s.Key).Should().BeEquivalentTo("Simple", "Nested");
Assert.Equal(2, sections.Length);
Assert.Equivalent(new[] { "Simple", "Nested" }, sections.Select(s => s.Key), strict: true);
}

[Fact]
public async Task GetConfiguration_InitialValues_AreNull()
{
var sections = await FetchSections();
sections.SelectMany(s => s.Fields).Should().AllSatisfy(f => f.Value.Should().BeNull());
Assert.All(sections.SelectMany(s => s.Fields), f => Assert.Null(f.Value));
}

[Fact]
public async Task UpdateConfiguration_ValidSettings_Returns200WithEmptyErrors()
{
var response = await PostUpdate(new[] { new { key = "Simple:Name", value = "Alice" } });

response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var errors = await response.Content.ReadFromJsonAsync<string[]>();
errors.Should().BeEmpty();
Assert.NotNull(errors);
Assert.Empty(errors);
}

[Fact]
Expand All @@ -89,7 +89,7 @@ public async Task UpdateConfiguration_AfterSave_GetReturnsUpdatedValue()
var sections = await FetchSections();
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().Be("Alice");
Assert.Equal("Alice", field.Value);
}

[Fact]
Expand All @@ -104,7 +104,7 @@ public async Task UpdateConfiguration_PersistedToSqlServer_SurvivesAppRestart()
var sections = (await response.Content.ReadFromJsonAsync<SectionDto[]>())!;
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().Be("Persistent");
Assert.Equal("Persistent", field.Value);
}

[Fact]
Expand All @@ -116,7 +116,7 @@ public async Task UpdateConfiguration_MultipleUpdates_LastValueWins()
var sections = await FetchSections();
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().Be("Second");
Assert.Equal("Second", field.Value);
}

[Fact]
Expand All @@ -133,8 +133,8 @@ await PostUpdate(new[]
var sections = await FetchSections();
var fields = sections.Single(s => s.Key == "Simple").Fields;

fields.Single(f => f.Key == "Name").Value.Should().Be("Bob");
fields.Single(f => f.Key == "Value").Value.Should().Be("42");
Assert.Equal("Bob", fields.Single(f => f.Key == "Name").Value);
Assert.Equal("42", fields.Single(f => f.Key == "Value").Value);
}

[Fact]
Expand All @@ -146,7 +146,7 @@ public async Task UpdateConfiguration_NestedField_PersistedAndRetrieved()
var subSection = sections.Single(s => s.Key == "Nested").Sections.Single(s => s.Key == "Child");
var field = subSection.Fields.Single(f => f.Key == "ChildProp");

field.Value.Should().Be("deep");
Assert.Equal("deep", field.Value);
}

[Fact]
Expand All @@ -158,7 +158,7 @@ public async Task UpdateConfiguration_NullValue_ClearsField()
var sections = await FetchSections();
var field = sections.Single(s => s.Key == "Simple").Fields.Single(f => f.Key == "Name");

field.Value.Should().BeNull();
Assert.Null(field.Value);
}

private Task<HttpResponseMessage> PostGetConfiguration() =>
Expand Down
Loading
Loading