Ejemplo n.º 1
0
        public void ESProcessException()
        {
            string expected = "ok";
            string actual   = string.Empty;

            EventSourcingExceptionProcessor.Process(() =>
            {
                actual = "ok";
            });

            Assert.AreEqual(expected, actual, "Expected string different than actual.");
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Save event source object using <see cref="RaraAvis.nCubed.EventSourcing.Core.Mementos.IMemento"/> if available.
 /// </summary>
 /// <param name="eventSourced">A source object.</param>
 /// <param name="correlationId">Related correlation id.</param>
 public void Save(T eventSourced, string correlationId)
 {
     CoreExceptionProcessor.ProcessInfrastructure(() =>
     {
         using (var context = new EventSourcingContext())
         {
             var eventsSet = context.Set <EventData>();
             while (eventSourced.Events.Count() > 0)
             {
                 try
                 {
                     var versionedEvent      = eventSourced.Events.Dequeue();
                     versionedEvent.SourceId = versionedEvent.SourceId == Guid.Empty ? eventSourced.Id : versionedEvent.SourceId;
                     this.messagingRandomRetry.ExecuteAction(() => this.eventBus.Publish(new Envelope <IEvent>(versionedEvent)
                     {
                         CorrelationId = correlationId
                     }));
                     eventsSet.Add(this.Serialize(versionedEvent, correlationId));
                 }
                 catch (Exception ex)
                 {
                     try
                     {
                         this.sqlIncrementalRetry.ExecuteAction(() => { context.SaveChanges(); }); //Save processed store events
                     }
                     catch (Exception exSql)
                     {
                         Exception exSqlOut = null;
                         EventSourcingExceptionProcessor.HandleException(exSql, out exSqlOut);
                         throw exSqlOut;
                     }
                     Exception exOut = null;
                     EventSourcingExceptionProcessor.HandleException(ex, out exOut);
                     throw exOut;
                 }
             }
             try
             {
                 this.sqlIncrementalRetry.ExecuteAction(() => { context.SaveChanges(); });
                 saveMemento(eventSourced);
             }
             catch (Exception ex)
             {
                 Exception exOut = null;
                 EventSourcingExceptionProcessor.HandleException(ex, out exOut);
                 throw exOut;
             }
         }
     });
 }
Ejemplo n.º 3
0
        public void ESProcessExceptionReturnValue()
        {
            int    expectedInteger = 3;
            string expectedString  = new String("test".ToCharArray());

            int actualInteger = EventSourcingExceptionProcessor.Process <int>(() =>
            {
                return(3);
            });

            string actualString = EventSourcingExceptionProcessor.Process <String>(() =>
            {
                return("test");
            });

            Assert.AreEqual(expectedInteger, actualInteger, "Expected int different than actual.");
            Assert.AreEqual(expectedString, actualString, "Expected string different than actual.");
        }