Skip to content

Commit

Permalink
Removed Autofixture (#394)
Browse files Browse the repository at this point in the history
* Removed Autofixture
* Use MongoDB 8 image
* Use ESDB 24.6 for MongoDB tests
  • Loading branch information
alexeyzimarev authored Dec 17, 2024
1 parent 24b401a commit 4bd1e88
Show file tree
Hide file tree
Showing 79 changed files with 345 additions and 328 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# name: Setup .NET
# uses: actions/setup-dotnet@v4
# with:
# dotnet-version: '8.0'
# dotnet-version: '9.0.x'
-
name: Run tests
run: dotnet test --framework net9.0
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
jobs:
event_file:
name: "Event File"
runs-on: ubuntu-latest
# runs-on: ubuntu-latest
runs-on: self-hosted
steps:
- name: Upload
uses: actions/upload-artifact@v4
Expand All @@ -17,10 +18,12 @@ jobs:
path: ${{ github.event_path }}
build-and-test:
name: "Build and test"
runs-on: ubuntu-latest
# runs-on: ubuntu-latest
runs-on: self-hosted
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
TC_CLOUD_TOKEN: ${{ secrets.TC_TOKEN }}
DOTNET_INSTALL_DIR: ${{ github.workspace }}/.dotnet
steps:
-
name: Checkout
Expand Down
20 changes: 10 additions & 10 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<MicrosoftTestHostVer>8.0.6</MicrosoftTestHostVer>
</PropertyGroup>
<PropertyGroup Label="Testcontainers version">
<TestcontainersVersion>4.0.0</TestcontainersVersion>
<TestcontainersVersion>4.1.0</TestcontainersVersion>
</PropertyGroup>
<PropertyGroup>
<NpgsqlVersion>9.0.1</NpgsqlVersion>
<TUnitVersion>0.4.74</TUnitVersion>
<TUnitVersion>0.4.105</TUnitVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
Expand Down Expand Up @@ -44,7 +44,7 @@
<PackageVersion Include="RabbitMQ.Client" Version="6.8.1" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageVersion Include="NEST" Version="7.17.5" />
<PackageVersion Include="Polly" Version="8.4.2" />
<PackageVersion Include="Polly" Version="8.5.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="StackExchange.Redis" Version="2.8.16" />
</ItemGroup>
Expand All @@ -60,29 +60,29 @@
</ItemGroup>
<ItemGroup Label="References for packable projects">
<PackageVersion Include="MinVer" Version="6.0.0" PrivateAssets="All" />
<PackageVersion Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0" PrivateAssets="All" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Label="References for test projects">
<PackageVersion Include="AutoFixture" Version="4.18.1" />
<PackageVersion Include="Bogus" Version="35.6.1" />
<PackageVersion Include="Fare" Version="2.2.1" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" PrivateAssets="All" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(MicrosoftTestHostVer)" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="$(MicrosoftTestHostVer)" />
<PackageVersion Include="RestSharp" Version="112.1.0" />
<PackageVersion Include="Hypothesist" Version="3.0.91" />
<PackageVersion Include="Hypothesist" Version="3.0.97" />
<PackageVersion Include="NodaTime" Version="3.2.0" />
<PackageVersion Include="NodaTime.Serialization.SystemTextJson" Version="1.2.0" />
<PackageVersion Include="MicroElements.AutoFixture.NodaTime" Version="1.0.0" />
<PackageVersion Include="MongoDb.Bson.NodaTime" Version="3.0.0" />
<PackageVersion Include="Verify.DiffPlex" Version="3.1.2" />
<PackageVersion Include="TUnit" Version="$(TUnitVersion)" />
<PackageVersion Include="TUnit.Core" Version="$(TUnitVersion)" />
<PackageVersion Include="TUnit.Assertions" Version="$(TUnitVersion)" />
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="1.4.1" />
<PackageVersion Include="Verify.TUnit" Version="28.1.3" />
<PackageVersion Include="NodaTime.Bogus" Version="3.0.2" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>
<ItemGroup Label="Packages for samples">
<PackageVersion Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.0.0" />
Expand All @@ -92,10 +92,10 @@
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.10.0-beta.1" />
<PackageVersion Include="OpenTelemetry.Exporter.Zipkin" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.9.0-beta.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.9.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
<ItemGroup>
<PackageReference Include="Bogus" />
<PackageReference Include="JetBrains.Annotations"/>
<PackageReference Include="MicroElements.AutoFixture.NodaTime"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection"/>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions"/>
<PackageReference Include="NodaTime.Bogus" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson"/>
<PackageReference Include="Testcontainers"/>
<PackageReference Remove="xunit.v3"/>
<PackageReference Include="TUnit.Core"/>
<PackageReference Include="TUnit.Assertions"/>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using AutoFixture;
using Bogus;
using Eventuous.Sut.App;
using NodaTime;

namespace Eventuous.Tests.Persistence.Base.Fixtures;

public static class DomainFixture {
static DomainFixture() => TypeMap.RegisterKnownEventTypes(typeof(DomainFixture).Assembly);

static Faker<Commands.ImportBooking> Faker => new Faker<Commands.ImportBooking>()
.RuleFor(x => x.BookingId, _ => Guid.NewGuid().ToString("N"))
.RuleFor(x => x.RoomId, _ => Guid.NewGuid().ToString("N"))
.RuleFor(x => x.Price, f => f.Random.Number(50, 200))
.RuleFor(x => x.CheckIn, f => f.Noda().LocalDate.Soon())
.RuleFor(x => x.CheckOut, (f, c) => c.CheckIn.PlusDays(f.Random.Number(1, 5)));

public static Commands.ImportBooking CreateImportBooking(IFixture auto) {
var from = auto.Create<LocalDate>();

return auto.Build<Commands.ImportBooking>()
.With(x => x.CheckIn, from)
.With(x => x.CheckOut, from.PlusDays(2))
.Create();
}
public static Commands.ImportBooking CreateImportBooking() => Faker.Generate();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using AutoFixture;
using static Eventuous.Sut.App.Commands;
using static Eventuous.Sut.Domain.BookingEvents;

namespace Eventuous.Tests.Persistence.Base.Fixtures;

public static class Helpers {
public static StreamName GetStreamName(this StoreFixtureBase fixture) => new(fixture.Auto.Create<string>());
public static StreamName GetStreamName() => new(Guid.NewGuid().ToString());

public static BookingImported CreateEvent(this StoreFixtureBase fixture) => ToEvent(DomainFixture.CreateImportBooking(fixture.Auto));
public static BookingImported CreateEvent() => ToEvent(DomainFixture.CreateImportBooking());

public static IEnumerable<BookingImported> CreateEvents(this StoreFixtureBase fixture, int count) {
for (var i = 0; i < count; i++) {
yield return CreateEvent(fixture);
yield return CreateEvent();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Text.RegularExpressions;
using AutoFixture;
using Bogus;
using DotNet.Testcontainers.Containers;
using Eventuous.TestHelpers;
using Eventuous.TestHelpers.TUnit.Logging;
using MicroElements.AutoFixture.NodaTime;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using TUnit.Core.Interfaces;
Expand All @@ -15,7 +13,6 @@ public interface IStartableFixture : IAsyncInitializer, IAsyncDisposable;

public abstract class StoreFixtureBase {
public IEventStore EventStore { get; protected private set; } = null!;
public IFixture Auto { get; } = new Fixture().Customize(new NodaTimeCustomization());
protected static Faker Faker { get; } = new();
protected ServiceProvider Provider { get; set; } = null!;
protected bool AutoStart { get; init; } = true;
Expand Down
28 changes: 14 additions & 14 deletions src/Core/test/Eventuous.Tests.Persistence.Base/Store/Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ protected StoreAppendTests(T fixture) {
[Test]
[Category("Store")]
public async Task ShouldAppendToNoStream() {
var evt = _fixture.CreateEvent();
var streamName = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var streamName = Helpers.GetStreamName();
var result = await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream);

await Assert.That(result.NextExpectedVersion).IsEqualTo(0);
Expand All @@ -24,12 +24,12 @@ public async Task ShouldAppendToNoStream() {
[Test]
[Category("Store")]
public async Task ShouldAppendOneByOne() {
var evt = _fixture.CreateEvent();
var stream = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var stream = Helpers.GetStreamName();

var result = await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream);

evt = _fixture.CreateEvent();
evt = Helpers.CreateEvent();

var version = new ExpectedStreamVersion(result.NextExpectedVersion);
result = await _fixture.AppendEvent(stream, evt, version);
Expand All @@ -40,25 +40,25 @@ public async Task ShouldAppendOneByOne() {
[Test]
[Category("Store")]
public async Task ShouldFailOnWrongVersionNoStream() {
var evt = _fixture.CreateEvent();
var stream = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var stream = Helpers.GetStreamName();

await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream);

evt = _fixture.CreateEvent();
evt = Helpers.CreateEvent();

await Assert.That(() => _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream)).Throws<AppendToStreamException>();
}

[Test]
[Category("Store")]
public async Task ShouldFailOnWrongVersion() {
var evt = _fixture.CreateEvent();
var stream = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var stream = Helpers.GetStreamName();

await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream);

evt = _fixture.CreateEvent();
evt = Helpers.CreateEvent();

await Assert.That(() => _fixture.AppendEvent(stream, evt, new(3))).Throws<AppendToStreamException>();
}
Expand All @@ -67,12 +67,12 @@ public async Task ShouldFailOnWrongVersion() {
[Test]
[Category("Store")]
public async Task ShouldFailOnWrongVersionWithOptimisticConcurrencyException() {
var evt = _fixture.CreateEvent();
var stream = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var stream = Helpers.GetStreamName();

await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream);

evt = _fixture.CreateEvent();
evt = Helpers.CreateEvent();

await Assert.That(() => _fixture.StoreChanges(stream, evt, new(3))).Throws<OptimisticConcurrencyException>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ protected StoreOtherOpsTests(T fixture) {
[Test]
[Category("Store")]
public async Task StreamShouldExist(CancellationToken cancellationToken) {
var evt = _fixture.CreateEvent();
var streamName = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var streamName = Helpers.GetStreamName();
await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream);

var exists = await _fixture.EventStore.StreamExists(streamName, cancellationToken);
Expand All @@ -25,7 +25,7 @@ public async Task StreamShouldExist(CancellationToken cancellationToken) {
[Test]
[Category("Store")]
public async Task StreamShouldNotExist(CancellationToken cancellationToken) {
var streamName = _fixture.GetStreamName();
var streamName = Helpers.GetStreamName();
var exists = await _fixture.EventStore.StreamExists(streamName, cancellationToken);
await Assert.That(exists).IsFalse();
}
Expand Down
16 changes: 8 additions & 8 deletions src/Core/test/Eventuous.Tests.Persistence.Base/Store/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ protected StoreReadTests(T fixture) {
[Test]
[Category("Store")]
public async Task ShouldReadOne(CancellationToken cancellationToken) {
var evt = _fixture.CreateEvent();
var streamName = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var streamName = Helpers.GetStreamName();
await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream);

var result = await _fixture.EventStore.ReadEvents(streamName, StreamReadPosition.Start, 100, cancellationToken);
Expand All @@ -30,7 +30,7 @@ public async Task ShouldReadOne(CancellationToken cancellationToken) {
[Category("Store")]
public async Task ShouldReadMany(CancellationToken cancellationToken) {
object[] events = _fixture.CreateEvents(20).ToArray();
var streamName = _fixture.GetStreamName();
var streamName = Helpers.GetStreamName();
await _fixture.AppendEvents(streamName, events, ExpectedStreamVersion.NoStream);

var result = await _fixture.EventStore.ReadEvents(streamName, StreamReadPosition.Start, 100, cancellationToken);
Expand All @@ -42,20 +42,20 @@ public async Task ShouldReadMany(CancellationToken cancellationToken) {
[Category("Store")]
public async Task ShouldReadTail(CancellationToken cancellationToken) {
object[] events = _fixture.CreateEvents(20).ToArray();
var streamName = _fixture.GetStreamName();
var streamName = Helpers.GetStreamName();
await _fixture.AppendEvents(streamName, events, ExpectedStreamVersion.NoStream);

var result = await _fixture.EventStore.ReadEvents(streamName, new(10), 100, cancellationToken);
var expected = events.Skip(10);
var actual = result.Select(x => x.Payload);
var actual = result.Select(x => x.Payload!);
await Assert.That(actual).IsEquivalentTo(expected);
}

[Test]
[Category("Store")]
public async Task ShouldReadHead(CancellationToken cancellationToken) {
object[] events = _fixture.CreateEvents(20).ToArray();
var streamName = _fixture.GetStreamName();
var streamName = Helpers.GetStreamName();
await _fixture.AppendEvents(streamName, events, ExpectedStreamVersion.NoStream);

var result = await _fixture.EventStore.ReadEvents(streamName, StreamReadPosition.Start, 10, cancellationToken);
Expand All @@ -68,8 +68,8 @@ public async Task ShouldReadHead(CancellationToken cancellationToken) {
[Test]
[Category("Store")]
public async Task ShouldReadMetadata(CancellationToken cancellationToken) {
var evt = _fixture.CreateEvent();
var streamName = _fixture.GetStreamName();
var evt = Helpers.CreateEvent();
var streamName = Helpers.GetStreamName();

await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream, new() { { "Key1", "Value1" }, { "Key2", "Value2" } });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoFixture;
using Bogus;
using DotNet.Testcontainers.Containers;
using Eventuous.TestHelpers.TUnit;
using Eventuous.Tests.Persistence.Base.Fixtures;
using JetBrains.Annotations;

Expand All @@ -11,7 +12,7 @@ protected async Task Should_load_hot_and_archive() {

var store = _storeFixture.EventStore;
var archive = new ArchiveStore(_storeFixture.EventStore);
var testEvents = _fixture.CreateMany<TestEventForTiers>(count).ToArray();
var testEvents = TestEventForTiers.CreateMany(count).ToArray();
var stream = new StreamName($"Test-{Guid.NewGuid():N}");

await store.Store(stream, ExpectedStreamVersion.NoStream, testEvents);
Expand All @@ -21,14 +22,13 @@ protected async Task Should_load_hot_and_archive() {
var combined = new TieredEventReader(store, archive);
var loaded = (await combined.ReadStream(stream, StreamReadPosition.Start)).ToArray();

var actual = loaded.Select(x => (TestEventForTiers)x.Payload!).ToArray();
await Assert.That(actual).IsEquivalentTo(testEvents);
var actual = loaded.Select(x => (TestEventForTiers)x.Payload!);
await Assert.That(actual).CollectionEquivalentTo(testEvents);

await Assert.That(loaded.Take(50).Select(x => x.FromArchive)).DoesNotContain(false);
await Assert.That(loaded.Skip(50).Select(x => x.FromArchive)).DoesNotContain(true);
}

readonly Fixture _fixture = new();
readonly StoreFixtureBase<TContainer> _storeFixture;

protected TieredStoreTestsBase(StoreFixtureBase<TContainer> storeFixture) {
Expand Down Expand Up @@ -58,4 +58,8 @@ CancellationToken cancellationToken
[UsedImplicitly]
record TestEventForTiers(string Data, int Number) {
public const string TypeName = "test-event-tiers";

static readonly Faker<TestEventForTiers> Faker = new Faker<TestEventForTiers>().CustomInstantiator(f => new(f.Commerce.Product(), f.Random.Int()));

public static IEnumerable<TestEventForTiers> CreateMany(int count) => Faker.Generate(count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hypothesist"/>
<PackageReference Remove="xunit.v3"/>
<PackageReference Include="TUnit.Core"/>
<PackageReference Include="TUnit.Assertions"/>
</ItemGroup>
Expand Down
Loading

0 comments on commit 4bd1e88

Please sign in to comment.