Exemplo n.º 1
0
        public OrmRepositoryFixture()
        {
            using (var context = new TestOrmRepository(Mock.Of <IEventBus>()))
            {
                if (context.Database.Exists())
                {
                    context.Database.Delete();
                }

                context.Database.Create();
            }
        }
Exemplo n.º 2
0
        public void WhenSavingEntity_ThenCanRetrieveIt()
        {
            var id = Guid.NewGuid();

            using (var context = new TestOrmRepository(Mock.Of <IEventBus>()))
            {
                var aggregate = new OrmTestAggregate(id);
                context.Save(aggregate);
            }

            using (var context = new TestOrmRepository(Mock.Of <IEventBus>()))
            {
                var aggregate = context.Find <OrmTestAggregate>(id);

                Assert.NotNull(aggregate);
            }
        }
Exemplo n.º 3
0
        public void WhenEntityExposesEvent_ThenRepositoryPublishesIt()
        {
            var bus    = new Mock <IEventBus>();
            var events = new List <IEvent>();

            bus.Setup(x => x.Publish(It.IsAny <IEnumerable <IEvent> >()))
            .Callback <IEnumerable <IEvent> >(x => events.AddRange(x));

            var @event = new TestEvent();

            using (var context = new TestOrmRepository(bus.Object))
            {
                var aggregate = new OrmTestAggregate(Guid.NewGuid());
                aggregate.AddEvent(@event);
                context.Save(aggregate);
            }

            Assert.Equal(1, events.Count);
            Assert.True(events.Contains(@event));
        }
Exemplo n.º 4
0
        public void WhenSavingEntityTwice_ThenCanReloadIt()
        {
            var id = Guid.NewGuid();

            using (var context = new TestOrmRepository(Mock.Of <IEventBus>()))
            {
                var aggregate = new OrmTestAggregate(id);
                context.Save(aggregate);
            }

            using (var context = new TestOrmRepository(Mock.Of <IEventBus>()))
            {
                var aggregate = context.Find <OrmTestAggregate>(id);
                aggregate.Title = "CQRS Journey";

                context.Save(aggregate);

                context.Entry(aggregate).Reload();

                Assert.Equal("CQRS Journey", aggregate.Title);
            }
        }