Skip to content

Commit

Permalink
Centralize test event definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel Nobel committed Jun 7, 2023
1 parent fb04561 commit 7b83776
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/Qowaiv.DomainModel/Collections/ImmutableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public sealed class ImmutableCollection : IReadOnlyCollection<object>
/// Null, and null items are ignored.
/// </remarks>
[Pure]
public ImmutableCollection Add(object item)
public ImmutableCollection Add(object? item)
=> new(Items.Add(item));

/// <summary>Creates a new <see cref="ImmutableCollection"/> with the added items.</summary>
/// <remarks>
/// Null, and null items are ignored.
/// </remarks>
[Pure]
public ImmutableCollection AddRange(params object[] items) => Add(items);
public ImmutableCollection AddRange(params object?[]? items) => Add(items);

/// <summary>Starts a conditional addition.</summary>
[Pure]
Expand Down
4 changes: 1 addition & 3 deletions test/Qowaiv.DomainModel.UnitTests/Event_buffer_specs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using NUnit.Framework.Internal.Execution;
using Qowaiv.DomainModel;
using Qowaiv.DomainModel.UnitTests.Models;
using Qowaiv.DomainModel;

namespace Event_buffer_specs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Replays_events
public void from_buffer()
{
var id = Guid.Parse("58B82A50-B906-4178-87EC-A8C31B49368B");
var buffer = EventBuffer.Empty(id).Add(new NameUpdated { Name = "Jimi Hendrix" });
var buffer = EventBuffer.Empty(id).Add(new NameUpdated("Jimi Hendrix"));

var replayed = Aggregate.FromStorage<SimpleEventSourcedAggregate, Guid>(buffer);
replayed.Should().BeEquivalentTo(new
Expand All @@ -31,7 +31,7 @@ public void changes_for_single_event()
var updated = origin.SetName("Jimi Hendrix").Should().BeValid().Value;

updated.Name.Should().Be("Jimi Hendrix");
updated.Buffer.Uncommitted.Should().BeEquivalentTo(new[] { new NameUpdated { Name = "Jimi Hendrix" } });
updated.Buffer.Uncommitted.Should().BeEquivalentTo(new[] { new NameUpdated("Jimi Hendrix") });
}

[Test]
Expand All @@ -42,8 +42,8 @@ public void changes_for_multiple_events()

updated.Buffer.Uncommitted.Should().BeEquivalentTo(new object[]
{
new NameUpdated { Name = "Jimi Hendrix" },
new DateOfBirthUpdated { DateOfBirth = new Date(1942, 11, 27) },
new NameUpdated("Jimi Hendrix"),
new DateOfBirthUpdated(new Date(1942, 11, 27)),
});
}

Expand All @@ -69,7 +69,7 @@ public void with_origin_unchanged()
public void skips_unknown_event_types()
{
var aggregate = new TestApplyChangeAggregate();
var updated = aggregate.TestApplyChange(new NameUpdated()).Should().BeValid().Value;
var updated = aggregate.TestApplyChange(new NameUpdated("unknown")).Should().BeValid().Value;
updated.Version.Should().Be(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Models.Events;

public sealed record DateOfBirthUpdated(Date DateOfBirth);
4 changes: 4 additions & 0 deletions test/Qowaiv.DomainModel.UnitTests/Models/Events/EmptyEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Models.Events;

[EmptyTestClass]
public sealed record EmptyEvent();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Models.Events;

[EmptyTestClass]
public sealed record InvalidEvent();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Models.Events;

public sealed record NameUpdated(string Name);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Models.Events;

[EmptyTestClass]
public sealed record SimpleInitEvent();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Models.Events;

public sealed record StoredEvent(object Id, int Version, object Payload);
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Qowaiv.DomainModel.UnitTests.Models;
using Models.Events;

namespace Qowaiv.DomainModel.UnitTests.Models;

public sealed class SimpleEventSourcedAggregate : Aggregate<SimpleEventSourcedAggregate, Guid>
{
Expand All @@ -12,14 +14,12 @@ public sealed class SimpleEventSourcedAggregate : Aggregate<SimpleEventSourcedAg

public bool IsWrong { get; private set; }

public Result<SimpleEventSourcedAggregate> SetName(string name) => ApplyEvent(new NameUpdated { Name = name });
public Result<SimpleEventSourcedAggregate> SetName(string name) => ApplyEvent(new NameUpdated(name));

public Result<SimpleEventSourcedAggregate> SetPerson(string name, Date dateOfBirth)
{
return ApplyEvents(
new NameUpdated { Name = name },
new DateOfBirthUpdated { DateOfBirth = dateOfBirth });
}
public Result<SimpleEventSourcedAggregate> SetPerson(string name, Date dateOfBirth)
=> ApplyEvents(
new NameUpdated(name),
new DateOfBirthUpdated(dateOfBirth));

internal void When(NameUpdated @event)
{
Expand Down
25 changes: 0 additions & 25 deletions test/Qowaiv.DomainModel.UnitTests/Models/_events.cs

This file was deleted.

3 changes: 3 additions & 0 deletions test/Qowaiv.DomainModel.UnitTests/Properties/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
global using FluentAssertions;
global using Models.Events;
global using NUnit.Framework;
global using Qowaiv;
global using Qowaiv.DomainModel.Collections;
global using Qowaiv.DomainModel.Commands;
global using Qowaiv.DomainModel.UnitTests;
global using Qowaiv.Validation.Abstractions;
global using System;
global using System.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma warning disable CA1822 // Mark members as static, methods are used for tests and need to be instance-based

using Qowaiv.DomainModel.Reflection;
using Qowaiv.DomainModel.UnitTests;

namespace Relection.Expression_compiling_event_dispatcher_specs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ public void HasUncommittedEvents_DifferentArrayValues_DisplayedInTheMessage()

namespace TestEvents
{
[EmptyTestClass]
internal class EmptyEvent { }

[EmptyTestClass]
internal class SimpleEvent { public int Value { get; set; } }

Expand Down

0 comments on commit 7b83776

Please sign in to comment.