public void Handle(UpdatedEvent @event)
 {
     this.Value = @event.Value;
 }
Exemple #2
0
        public void Setup()
        {
            _id           = Guid.NewGuid();
            _builder      = new Moq.Mock <IBuilder>();
            _store        = new Moq.Mock <IStoreEvents>();
            _snaps        = new Moq.Mock <IStoreSnapshots>();
            _stream       = new Moq.Mock <IEventStream>();
            _eventFactory = new Moq.Mock <IMessageCreator>();
            _resolver     = new Moq.Mock <IRouteResolver>();
            _processor    = new Moq.Mock <IProcessor>();
            _mapper       = new Moq.Mock <IMessageMapper>();

            _eventFactory.Setup(x => x.CreateInstance(Moq.It.IsAny <Action <CreatedEvent> >())).Returns <Action <CreatedEvent> >((e) => { var ev = new CreatedEvent(); e(ev); return(ev); });
            _eventFactory.Setup(x => x.CreateInstance(Moq.It.IsAny <Action <UpdatedEvent> >())).Returns <Action <UpdatedEvent> >((e) => { var ev = new UpdatedEvent(); e(ev); return(ev); });
            _eventFactory.Setup(x => x.CreateInstance(typeof(CreatedEvent))).Returns(new CreatedEvent());
            _eventFactory.Setup(x => x.CreateInstance(typeof(UpdatedEvent))).Returns(new UpdatedEvent());

            _resolver.Setup(x => x.Resolve(Moq.It.IsAny <_AggregateStub>(), typeof(CreatedEvent))).Returns <_AggregateStub, Type>((agg, type) => (@event) => (agg as _AggregateStub).Handle(@event as CreatedEvent));
            _resolver.Setup(x => x.Resolve(Moq.It.IsAny <_AggregateStub>(), typeof(UpdatedEvent))).Returns <_AggregateStub, Type>((agg, type) => (@event) => (agg as _AggregateStub).Handle(@event as UpdatedEvent));

            _snaps.Setup(x => x.GetSnapshot(Moq.It.IsAny <String>(), Moq.It.IsAny <String>()));
            _store.Setup(x => x.GetStream <_AggregateStub>(Moq.It.IsAny <String>(), Moq.It.IsAny <String>(), Moq.It.IsAny <Int32?>())).Returns(_stream.Object);
            _builder.Setup(x => x.CreateChildBuilder()).Returns(_builder.Object);
            _builder.Setup(x => x.Build <IRouteResolver>()).Returns(_resolver.Object);
            _builder.Setup(x => x.Build <IMessageCreator>()).Returns(_eventFactory.Object);
            _builder.Setup(x => x.Build <IStoreEvents>()).Returns(_store.Object);
            _builder.Setup(x => x.Build <IStoreSnapshots>()).Returns(_snaps.Object);
            _builder.Setup(x => x.Build <IProcessor>()).Returns(_processor.Object);
            _stream.Setup(x => x.StreamId).Returns(String.Format("{0}", _id));
            _stream.Setup(x => x.StreamVersion).Returns(0);
            _stream.Setup(x => x.Events).Returns(new List <IWritableEvent> {
                new _EventStub {
                    Event = new CreatedEvent {
                        Value = "Test"
                    }
                }
            });

            _uow         = new Aggregates.Internal.UnitOfWork(new DefaultRepositoryFactory(), _mapper.Object);
            _uow.Builder = _builder.Object;
        }