Skip to content
Merged
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
29 changes: 28 additions & 1 deletion tests/AggregateKit.Tests/AggregateRootTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public ArticlePublishedEvent(Guid articleId, DateTime publishDate)
}
}

private class TestEvent : DomainEventBase
{
}

private class TestAggregate : AggregateRoot<Guid>
{
public TestAggregate(Guid id) : base(id)
{
AddDomainEvent(new TestEvent());
}
}

private class Article : AggregateRoot<Guid>
{
public string Title { get; private set; } = string.Empty;
Expand Down Expand Up @@ -111,5 +123,20 @@ public void ClearDomainEvents_Removes_All_Events()
// Assert
Assert.Empty(article.DomainEvents);
}

[Fact]
public void DomainEvents_IsReadOnly()
{
// Arrange
var aggregate = new TestAggregate(Guid.NewGuid());

// Act
var events = aggregate.DomainEvents;
var collection = (ICollection<IDomainEvent>)events;

// Assert
Assert.Throws<NotSupportedException>(() => collection.Add(new TestEvent()));
Assert.Throws<NotSupportedException>(() => collection.Clear());
}
}
}
}