public async Task HandleWithEventsShouldCallAppendAsync() { //Arrange var mockEventStoreRepository = new Mock <IEventStoreRepository <AggregateRoot <Guid> > >(); mockEventStoreRepository.Setup(e => e.AppendAsync(It.IsAny <EventStore>())) .Returns(Task.FromResult(true)) .Verifiable(); var mockEventSerializer = new Mock <IEventSerializer>(); var @event = new SpeechCreatedEvent(It.IsAny <Guid>(), It.IsAny <Title>(), It.IsAny <UrlValue>(), It.IsAny <Description>(), It.IsAny <SpeechType>()); long version = 0; //Act var sut = new EventSourcingHandler <AggregateRoot <Guid> >(mockEventStoreRepository.Object, mockEventSerializer.Object); await sut.Handle(@event, version); //Assert mockEventStoreRepository.Verify(m => m.AppendAsync(It.IsAny <EventStore>()), Times.Once, "AppendAsync must be called only once"); }
public async Task HandleWithEventsShouldCallCommitAsync() { //Arrange Mock <IUnitOfWork> moqUnitOfWork = new Mock <IUnitOfWork>(); moqUnitOfWork.Setup(m => m.Commit()).Verifiable(); var mockEventStoreRepository = new Mock <IEventStoreRepository>(); mockEventStoreRepository.Setup(e => e.AppendAsync(It.IsAny <EventStore>())) .Returns(Task.FromResult(true)) .Verifiable(); var mockEventSerializer = new Mock <IEventSerializer>(); var @event = new SpeechCreatedEvent(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SpeechTypeEnum>()); long version = 0; var moqSignalRPublisher = new Mock <ISignalRPublisher>(); moqSignalRPublisher.Setup(p => p.SubscribeAsync(It.IsAny <string>())).Returns(Task.CompletedTask); moqSignalRPublisher.Setup(p => p.PublishAsync(It.IsAny <string>(), It.IsAny <EventStore>())).Returns(Task.CompletedTask); //Act var sut = new EventSourcingHandler(moqUnitOfWork.Object, mockEventStoreRepository.Object, mockEventSerializer.Object, moqSignalRPublisher.Object); await sut.Handle(@event, version); //Assert // Verify that SaveChanges is called moqUnitOfWork.Verify(m => m.Commit(), Times.Once, "Commit must be called only once"); }
public void Apply(SpeechCreatedEvent ev) { Id = ev.AggregateId; _title = ev.Title; _url = ev.Url; _description = ev.Description; _type = ev.Type.Value; }
public void Apply(SpeechCreatedEvent ev) { Id = ev.AggregateId; Title = ev.Title; Url = ev.Url; Description = ev.Description; Type = ev.Type; }
public void ShouldApplySpeechCreatedEvent() { //Arrange var speechProjection = Invoker.CreateInstanceOfProjection <SpeechProjection>(); var speechCreatedEvent = new SpeechCreatedEvent(Guid.NewGuid(), "my title", "http://test.com", "my desc", new SpeechTypeEnum(1, "conferences")); //Act speechProjection.Apply(speechCreatedEvent); //Assert Assert.Equal(speechCreatedEvent.AggregateId, speechProjection.Id); Assert.Equal(speechCreatedEvent.Title, speechProjection.Title); Assert.Equal(speechCreatedEvent.Description, speechProjection.Description); Assert.Equal(speechCreatedEvent.Url, speechProjection.Url); Assert.Equal(speechCreatedEvent.Type, speechProjection.Type); Assert.Equal(0, speechProjection.Version); }
public void ApplyEventShouldPopulateAggregatePropertiesWithEventProperties() { //Arrange long expectedVersion = -1; var evt = new SpeechCreatedEvent(Guid.NewGuid(), new Title("SpeechCreatedEvent Title "), new UrlValue("http://url-evt.com"), new Description("SpeechCreatedEvent description must be very long as a description than people can understand without efforts"), SpeechType.Conferences); var aggregate = CreateNewAggregate <SpeechAggregate.Speech>(); //Act aggregate.ApplyEvent(evt, expectedVersion); //Assert Assert.Equal(evt.AggregateId, aggregate.Id); Assert.Equal(evt.Title, aggregate.Title); Assert.Equal(evt.Url, aggregate.Url); Assert.Equal(evt.Description, aggregate.Description); Assert.Equal(evt.Type, aggregate.Type); Assert.IsAssignableFrom <IDomainEvent>(evt); }
public void ApplyEventShouldPopulateAggregatePropertiesWithEventProperties() { //Arrange long expectedVersion = -1; var speechType = new LogCorner.EduSync.Speech.Domain.SpeechType("Conferences"); var evt = new SpeechCreatedEvent(Guid.NewGuid(), "SpeechCreatedEvent Title ", "http://url-evt.com", "SpeechCreatedEvent description must be very long as a description than people can understand without efforts", new Command.SharedKernel.Events.SpeechTypeEnum(speechType.IntValue, speechType.StringValue)); var aggregate = CreateNewAggregate <SpeechAggregate.Speech>(); //Act aggregate.ApplyEvent(evt, expectedVersion); //Assert Assert.Equal(evt.AggregateId, aggregate.Id); Assert.Equal(evt.Title, aggregate.Title.Value); Assert.Equal(evt.Url, aggregate.Url.Value); Assert.Equal(evt.Description, aggregate.Description.Value); Assert.Equal(evt.Type.Name, aggregate.Type.Value.ToString()); Assert.IsAssignableFrom <IDomainEvent>(evt); }