Example #1
0
        public async Task Should_append_events_and_publish()
        {
            var commitId = Guid.NewGuid();

            var event1 = new MyEvent();
            var event2 = new MyEvent();

            var eventData1 = new EventData();
            var eventData2 = new EventData();

            A.CallTo(() => formatter.ToEventData(A <Envelope <IEvent> > .That.Matches(e => e.Payload == event1), commitId, true))
            .Returns(eventData1);
            A.CallTo(() => formatter.ToEventData(A <Envelope <IEvent> > .That.Matches(e => e.Payload == event2), commitId, true))
            .Returns(eventData2);

            A.CallTo(() => eventStore.AppendEventsAsync(commitId, streamName, 123, A <ICollection <EventData> > .That.Matches(e => e.Count == 2)))
            .Returns(TaskHelper.Done);

            domainObject.AddEvent(event1);
            domainObject.AddEvent(event2);

            await sut.SaveAsync(domainObject, domainObject.GetUncomittedEvents(), commitId);

            A.CallTo(() => eventStore.AppendEventsAsync(commitId, streamName, 123, A <ICollection <EventData> > .That.Matches(e => e.Count == 2))).MustHaveHappened();
        }
Example #2
0
        public async Task Should_append_events_and_publish()
        {
            var commitId = Guid.NewGuid();

            var event1 = new MyEvent();
            var event2 = new MyEvent();

            var eventData1 = new EventData();
            var eventData2 = new EventData();

            eventDataFormatter.Setup(x => x.ToEventData(It.Is <Envelope <IEvent> >(e => e.Payload == event1), commitId)).Returns(eventData1);
            eventDataFormatter.Setup(x => x.ToEventData(It.Is <Envelope <IEvent> >(e => e.Payload == event2), commitId)).Returns(eventData2);

            eventStore.Setup(x => x.AppendEventsAsync(commitId, streamName, 123, It.Is <IEnumerable <EventData> >(e => e.Count() == 2)))
            .Returns(TaskHelper.Done)
            .Verifiable();

            domainObject.AddEvent(event1);
            domainObject.AddEvent(event2);

            await sut.SaveAsync(domainObject, domainObject.GetUncomittedEvents(), commitId);

            eventStore.VerifyAll();
        }