public async Task QueueClearedAfterWrite() { var domainObject = new DefaultDomainObject(); domainObject.AddEvent(new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar"))); var store = new Mock <IEventStore>(MockBehavior.Strict); store.Setup(s => s.WriteEvents(It.IsAny <IList <DomainEvent> >())) .ReturnsAsync(42); await domainObject.WriteRecordedEvents(store.Object); Assert.Empty(domainObject.GetCapturedDomainEvents()); }
public async Task IncrementVersionAfterWrite() { var domainObject = new DefaultDomainObject(); domainObject.AddEvent(new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar"))); var store = new Mock <IEventStore>(MockBehavior.Strict); store.Setup(s => s.WriteEvents(It.IsAny <IList <DomainEvent> >())) .ReturnsAsync(42); await domainObject.WriteRecordedEvents(store.Object); Assert.Equal(42, domainObject.CurrentVersion); Assert.Equal(42, domainObject.MetaVersion); }
public void ReturnValidationErrors() { var validator = new Mock <ICommandValidator>(MockBehavior.Strict); validator.Setup(v => v.ValidateDomainEvent(It.IsAny <EnvironmentCreated>())) .Returns(() => Result.Error("Something went wrong", ErrorCode.Undefined)); var domainObject = new DefaultDomainObject(); var domainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar")); domainObject.AddEvent(domainEvent); var result = domainObject.Validate(new List <ICommandValidator> { validator.Object }); Assert.NotEmpty(result[domainEvent]); }
public void ValidatesCapturedEvents() { var validator = new Mock <ICommandValidator>(MockBehavior.Strict); validator.Setup(v => v.ValidateDomainEvent(It.IsAny <EnvironmentCreated>())) .Returns(Result.Success) .Verifiable(); var domainObject = new DefaultDomainObject(); domainObject.AddEvent(new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar"))); domainObject.Validate(new List <ICommandValidator> { validator.Object }); validator.Verify(); }