public void SqlServerEventStore_Save_And_Find_Should_Retrieve_EnumEvent_Without_Throwing_When_NullableConfirm_Is_Not_Null()
        {
            var enumEvent = new EnumEvent(EnumEvent.TestEnum.Yes, nullableConfirm: EnumEvent.TestEnum.No);

            var eventId = enumEvent.Id;

            var eventStore = new SqlServerEventStore(Config.ConnectionString, this.EventDispatcher);

            eventStore.Save(enumEvent);

            System.Threading.Thread.Sleep(1000);

            var events = eventStore.Find <EnumEvent>(e => e.Id == eventId).ToArray();

            Assert.NotNull(events);
            Assert.Single(events);

            var @event = events[0];

            Assert.Equal(enumEvent.Id, @event.Id);
            Assert.Equal(enumEvent.TimelineId, @event.TimelineId);
            Assert.Equal(enumEvent.TimeStamp.ToLongDateString(), @event.TimeStamp.ToLongDateString());
            Assert.Equal(enumEvent.RequiredConfirm, @event.RequiredConfirm);
            Assert.Equal(enumEvent.NullableConfirm, @event.NullableConfirm);
            Assert.NotNull(@event.NullableConfirm);
        }
        public void SqlServerEventStore_RetrieveEvents_PlainEvent_Should_Work()
        {
            var eventStore = new SqlServerEventStore(this.Settings, this.EventDispatcher);

            var aggId = Guid.NewGuid();

            var events = new[]
            {
                new PlainEvent(aggId, PlainEvent.TestEnum.Nope),
                new PlainEvent(aggId, null),
                new PlainEvent(Guid.NewGuid(), null),
                new PlainEvent(aggId, PlainEvent.TestEnum.Ok),
            };

            var eventsCount = events.Count(e => e.MyAggId == aggId);

            foreach (var @event in events)
            {
                eventStore.Save(@event);
            }

            var eventMapping = new EventMapping {
                AggregateIdPropertyName = nameof(PlainEvent.MyAggId), EventType = typeof(PlainEvent)
            };

            var eventDescriptors = new[] { eventMapping };

            var savedEvents = eventStore.RetrieveEvents(aggId, DateTime.Now, eventDescriptors, timelineId: null);

            Assert.NotNull(savedEvents);
            Assert.NotEmpty(savedEvents);
            Assert.True(savedEvents.All(e => e is PlainEvent));

            Assert.Equal(eventsCount, savedEvents.Count());
        }
        public void LoadEventsTest()
        {
            var aggregateRootId = Guid.NewGuid();
            var employee        = new Employee(aggregateRootId);

            var event1 = new NameChangedEvent("daxnet");
            var event2 = new TitleChangedEvent("title");
            var event3 = new RegisteredEvent();

            event1.AttachTo(employee);
            event2.AttachTo(employee);
            event3.AttachTo(employee);

            var storeConfig       = new AdoNetEventStoreConfiguration(SQLServerFixture.ConnectionString, new GuidKeyGenerator());
            var payloadSerializer = new ObjectJsonSerializer();
            var store             = new SqlServerEventStore(storeConfig, payloadSerializer);

            store.Save(new List <DomainEvent>
            {
                event1,
                event2,
                event3
            });

            var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId);

            Assert.Equal(3, events.Count());
        }
Пример #4
0
        public void Connecting_to_SqlClient_does_not_throw_exception()
        {
            var store = new SqlServerEventStore("SqlClientConnection", _logger);
            var user  = new User();

            user.Register();
            user.ChangePassword("password");
            Assert.DoesNotThrow(
                () => store.Save <User>(user.Id.ToString(), EntityVersion.New, user.GetUncommittedEvents()));
        }
Пример #5
0
        public void Connecting_to_non_SqlClient_throws_exception()
        {
            var store = new SqlServerEventStore("NonSqlClientConnection", _logger);
            var user  = new User();

            user.Register();
            user.ChangePassword("password");
            Assert.Throws <InvalidOperationException>(
                () => store.Save <User>(user.Id.ToString(), EntityVersion.New, user.GetUncommittedEvents()));
        }
        public void Connecting_to_undefined_database_name_throws_exception()
        {
            var store = new SqlServerEventStore("InvalidConnnectionName", _logger);
            var user  = new User();

            user.Register();
            user.ChangePassword("password");
            Assert.Throws <InvalidOperationException>(
                () => store.Save <User>(user.Id.ToString(), EventStreamVersion.NoStream, user.GetUncommittedEvents()));
        }
        public void SqlServerEventStore_Save_PlainEvent_Should_Work()
        {
            var eventStore = new SqlServerEventStore(this.Settings, this.EventDispatcher);

            var guid = Guid.NewGuid();

            var plainEvent = new PlainEvent(guid, PlainEvent.TestEnum.Nope);

            var exception = Record.Exception(() => eventStore.Save(plainEvent));

            Assert.Null(exception);
        }
        public void SqlServerEventStore_Save_ComplexEvent_Should_Work()
        {
            var eventStore = new SqlServerEventStore(this.Settings, this.EventDispatcher);

            var stringList = new List <string> {
                "Hello", "Memento"
            };

            var myProp = new ComplexEvent.InternalProp(stringList);

            var complexEvent = new ComplexEvent(Guid.NewGuid(), Environment.TickCount, "PROV@", myProp, byte.MaxValue);

            var exception = Record.Exception(() => eventStore.Save(complexEvent));

            Assert.Null(exception);
        }
        public void SqlServerEventStore_Find_PlainEvent_Should_Retrieve_Previously_Saved_Event()
        {
            var myAggId = Guid.NewGuid();

            var plainEvent = new PlainEvent(myAggId, null);

            var eventStore = new SqlServerEventStore(this.Settings, this.EventDispatcher);

            eventStore.Save(plainEvent);

            var events = eventStore.Find <PlainEvent>(e => e.MyAggId == myAggId).ToArray();

            Assert.NotNull(events);
            Assert.Single(events);

            var @event = events[0];

            Assert.Equal(myAggId, @event.MyAggId);
            Assert.Equal(plainEvent.Id, @event.Id);
            Assert.Equal(plainEvent.TimeStamp.ToLongDateString(), @event.TimeStamp.ToLongDateString());
            Assert.Null(@event.TimelineId);
        }
        public void SqlServerEventStore_RetrieveEvents_ComplexEvent_Should_Work()
        {
            var eventStore = new SqlServerEventStore(this.Settings, this.EventDispatcher);

            var complexId = Guid.NewGuid();

            var events = new[]
            {
                new ComplexEvent(complexId, Environment.TickCount, "PROV@", new ComplexEvent.InternalProp(new List <string> {
                    "Hello", "Memento"
                }), byte.MaxValue),
                new ComplexEvent(complexId, 10000, "test titolo", new ComplexEvent.InternalProp(new List <string>()), byte.MinValue),
                new ComplexEvent(Guid.NewGuid(), 8787878, null, null, 0),
                new ComplexEvent(complexId, 12345, string.Empty, new ComplexEvent.InternalProp(new List <string> {
                    "test"
                }), 128),
            };

            var eventsCount = events.Count(e => e.ComplexId == complexId);

            foreach (var @event in events)
            {
                eventStore.Save(@event);
            }

            var eventMapping = new EventMapping {
                AggregateIdPropertyName = nameof(ComplexEvent.ComplexId), EventType = typeof(ComplexEvent)
            };

            var eventDescriptors = new[] { eventMapping };

            var savedEvents = eventStore.RetrieveEvents(complexId, DateTime.Now, eventDescriptors, timelineId: null);

            Assert.NotNull(savedEvents);
            Assert.NotEmpty(savedEvents);
            Assert.True(savedEvents.All(e => e is ComplexEvent));

            Assert.Equal(eventsCount, savedEvents.Count());
        }