标签: commondomain

CommonDomain - 如何对聚合根进行单元测试

我有一个使用Jonathan Oliver的CommonDomainEventStore的小系统.

我如何对我的聚合根进行单元测试以验证是否引发了正确的事件?

考虑遵循聚合根:

public class Subscriber : AggregateBase
{
        private Subscriber(Guid id)
        {
            this.Id = id;
        }

        private Subscriber(Guid id, string email, DateTimeOffset registeredDate)
            : this(id)
        {
            this.RaiseEvent(new NewSubscriberRegistered(this.Id, email, registeredDate));
        }

        public string Email{ get; private set; }
        public DateTimeOffset RegisteredDate { get; private set; }

        public static Subscriber Create(Guid id, string email, DateTimeOffset registeredDate)
        {
            return new Subscriber(id, email, registeredDate);
        }

        private void Apply(NewSubscriberRegistered @event)
        {
            this.Email = @event.Email;
            this.RegisteredDate = @event.RegisteredDate;
        } …
Run Code Online (Sandbox Code Playgroud)

unit-testing cqrs event-sourcing event-store commondomain

2
推荐指数
1
解决办法
1583
查看次数