public virtual async Task LoadAllEventsAsyncFindsEventsAfterLargeGaps()
        {
            // Arrange
            var ids = Enumerable.Range(0, 10)
                      .Select(i => ThingyId.New)
                      .ToArray();

            foreach (var id in ids)
            {
                var command = new ThingyPingCommand(id, PingId.New);
                await CommandBus.PublishAsync(command).ConfigureAwait(false);
            }

            foreach (var id in ids.Skip(1).Take(5))
            {
                await EventPersistence.DeleteEventsAsync(id, CancellationToken.None)
                .ConfigureAwait(false);
            }

            // Act
            var result = await EventStore
                         .LoadAllEventsAsync(GlobalPosition.Start, 5, CancellationToken.None)
                         .ConfigureAwait(false);

            // Assert
            result.DomainEvents.Should().HaveCount(5);
        }
Esempio n. 2
0
        public ActionResult UpdateEvent()
        {
            List <Events> events = EventPersistence.GetAllEvents();

            ViewData["events"] = events;
            return(View(new Events()));
        }
Esempio n. 3
0
        public ActionResult CommentAdd(Events textin)
        {
            string t      = textin.Comment.Replace("<", "&lt");
            string t1     = t.Replace(">", "&gt");
            string t2     = t1.Replace("(", "&#40");
            string t3     = t2.Replace(")", "&#41");
            string t4     = t3.Replace("&", "&#38");
            string tfinal = t4.Replace("|", "&#124");

            Comment com = new Comment();

            com.EventId   = textin.EventId;
            com.Text      = tfinal;
            com.EventName = EventPersistence.getEventD(textin.EventId).EventName;
            bool result = EventPersistence.AddComment(com);

            if (result)
            {
                ViewBag.message = "Commited";
            }
            else
            {
                ViewBag.message = "Couldnt commited";
            }

            return(RedirectToAction("ListEvents", "Event"));
        }
Esempio n. 4
0
        public ActionResult FindComment()
        {
            List <Comment> comments = EventPersistence.GetAllComments();

            ViewData["Comments"] = comments;
            return(View(new Comment()));
        }
Esempio n. 5
0
 public DefaultEventStore(EventPersistence persistence,
                          DomainEventBus domainEventBus,
                          DomainEventSerializer serializer)
 {
     _persistence    = persistence;
     _domainEventBus = domainEventBus;
     _serializer     = serializer;
 }
Esempio n. 6
0
 /*
  * Transaction: Update an event in the database
  * Returns true if the event exists in the database and
  * it was successfully changed.
  */
 public static bool ChangeEvent(Events changeEvent)
 {
     if (EventPersistence.getEvent(changeEvent) == null)
     {
         return(false);
     }
     return(EventPersistence.UpdateEvent(changeEvent));
 }
Esempio n. 7
0
 /*
  * Transaction: Delete an event from the database
  * Returns true if the event exists in the database and
  * it was successfully deleted.
  */
 public static bool DeleteEvent(Events delEvent)
 {
     if (EventPersistence.getEvent(delEvent) == null)
     {
         return(false);
     }
     return(EventPersistence.DeleteEvent(delEvent));
 }
Esempio n. 8
0
        public static Comment[] GetAllComments()
        {
            List <Comment> comments = EventPersistence.GetAllComments();

            if (comments != null)
            {
                return(EventPersistence.GetAllComments().ToArray());
            }
            else
            {
                return(new Comment[0]);
            }
        }
Esempio n. 9
0
        /*
         * This method takes all events to list to array
         */
        public static Events[] GetAllEvents()
        {
            List <Events> events = EventPersistence.GetAllEvents();

            if (events != null)
            {
                return(EventPersistence.GetAllEvents().ToArray());
            }
            else
            {
                return(new Events[0]);
            }
        }
Esempio n. 10
0
        public static bool AddNewEvent(Events newEvent)
        {
            bool eventChecker = EventPersistence.CheckEventname(newEvent);

            Events oldEvent = EventPersistence.getEvent(newEvent);

            if (eventChecker == true)
            {
                return(EventPersistence.AddEvent(newEvent));
            }

            return(false);
        }
Esempio n. 11
0
        public async Task EventStore_get_version_returns_default_for_unknown_id()
        {
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(new XunitLoggerProvider(_testOutputHelper));

            var publisher   = new SimpleEventPublisher();
            var persistence = new EventPersistence();
            var eventStore  = new EventStore(persistence, publisher, loggerFactory.CreateLogger <EventStore>());

            var version = await eventStore.GetVersion(Guid.NewGuid().ToString(), default);

            Assert.Equal(AggregateRoot.InitialVersion, version);
        }
Esempio n. 12
0
        public ActionResult FindComment(decimal a)
        {
            Comment result = EventPersistence.FindComment(a);

            List <Comment> list = EventPersistence.GetAllComments();


            if (result != null)
            {
                TempData["Comment"] = list;
                return(View("ListEvents"));
            }
            return(View("ListEvents"));
        }
Esempio n. 13
0
        public async Task EventStore_get_events_returns_empty_enumerable_for_unknown_id()
        {
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(new XunitLoggerProvider(_testOutputHelper));

            var publisher   = new SimpleEventPublisher();
            var persistence = new EventPersistence();
            var eventStore  = new EventStore(persistence, publisher, loggerFactory.CreateLogger <EventStore>());

            var retrievedEvents = await eventStore.GetEventStream("invalid_aggragate_id", 0);

            Assert.False(retrievedEvents.Events.Any());
        }
Esempio n. 14
0
        public ActionResult SearchEvent(Events value)
        {
            List <Events> events = EventPersistence.GetAllEvents();

            if (events != null)
            {
                ViewData["events"] = events;
                return(View(events.Contains(value)));
            }
            else
            {
                return(View("Home", "Index"));
            }
        }
Esempio n. 15
0
        public async Task EventStore_get_version_returns_correct_value()
        {
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(new XunitLoggerProvider(_testOutputHelper));

            var aggregateId = Guid.NewGuid().ToString();
            var eventStream = new EventStream(aggregateId, 1, new[] { new Event1(), new Event1() });

            var persistence = new EventPersistence(new[] { eventStream });
            var eventStore  = new EventStore(persistence, new SimpleEventPublisher(), loggerFactory.CreateLogger <EventStore>());
            var version     = await eventStore.GetVersion(aggregateId, default);

            eventStore.Dispose();
            Assert.Equal(2, version);
        }
Esempio n. 16
0
        public async Task EventStore_get_events_returns_saved_and_higher_state_events_only()
        {
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(new XunitLoggerProvider(_testOutputHelper));

            var aggregateId = Guid.NewGuid().ToString();
            var eventStream = new EventStream(aggregateId, 1, new[] { new Event1(), new Event1() });

            var persistence = new EventPersistence(new[] { eventStream });
            var eventStore  = new EventStore(persistence, new SimpleEventPublisher(), loggerFactory.CreateLogger <EventStore>());

            var retrievedEvents = await eventStore.GetEventStream(aggregateId, default);

            Assert.True(retrievedEvents.Events.Any());
            Assert.Equal(eventStream.Events.Count(), retrievedEvents.Events.Count());
        }
Esempio n. 17
0
        public async Task EventStore_save_and_publish_handles_all_events()
        {
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(new XunitLoggerProvider(_testOutputHelper));

            var publisher   = new SimpleEventPublisher();
            var persistence = new EventPersistence();
            var eventStore  = new EventStore(persistence, publisher, loggerFactory.CreateLogger <EventStore>());

            var aggregateId = Guid.NewGuid().ToString();
            var eventStream = new EventStream(aggregateId, 0, new[] { new Event1(), new Event1() });

            await eventStore.SaveAndPublish(eventStream, 0, () => { }, default);

            eventStore.Dispose();

            Assert.Equal(eventStream.Events.Count(), publisher.PublishedEvents.Count);
            Assert.Equal(eventStream.Events.Count(), persistence.GetPersistedEvents(aggregateId).Events.Count());
        }
Esempio n. 18
0
        /*
         * Handle a request for a listing of events.
         */
        public ActionResult ListEvents()
        {
            List <Events>  events   = EventPersistence.GetAllEvents();
            List <Comment> comments = EventPersistence.GetAllComments();

            if (events != null && comments != null)
            {
                ViewData["eventList"] = events;
                ViewData["Comments"]  = comments;
                return(View(events));
            }
            if (events != null)
            {
                ViewData["eventList"] = events;
                return(View(events));
            }
            else
            {
                return(View("Home", "Index"));
            }
        }
Esempio n. 19
0
        public ActionResult UpdateEvent(Events newEvent)
        {
            if (newEvent == null)
            {
                ViewBag.message = "Error: Invalid Request - please try again";
                return(View(new Events()));
            }

            if (newEvent.EventId.ToString().Length == 0)
            {
                ViewBag.message = "Error: An Id is required";
                return(View(newEvent));
            }


            bool result = EventManager.ChangeEvent(newEvent);

            if (result)
            {
                ViewBag.message = "Event Updated";
            }
            else
            {
                ViewBag.message = "That event could not be Updated";
            }
            List <Events> events = EventPersistence.GetAllEvents();

            if (events == null)
            {
                ViewBag.message = "There is not event for listing.";
                return(View("Home", "Index"));
            }
            else
            {
                ViewData["eventList"] = events;
                return(View("ChangeEvent", new Events()));
            }
        }
Esempio n. 20
0
 public DefaultEventStore(EventPersistence persistence, DomainEventBus domainEventBus)
     : this(persistence, domainEventBus, new JsonDomainEventSerializer())
 {
 }