Пример #1
0
        public given_a_sql_log_with_three_events()
        {
            using (var context = new MessageLogDbContext(dbName))
            {
                if (context.Database.Exists())
                {
                    context.Database.Delete();
                }

                context.Database.Create();
            }

            this.eventA = new EventA();
            this.eventB = new EventB();
            this.eventC = new EventC();

            var metadata = Mock.Of<IMetadataProvider>(x =>
                x.GetMetadata(eventA) == new Dictionary<string, string>
                {
                    { StandardMetadata.SourceId, eventA.SourceId.ToString() },
                    { StandardMetadata.SourceType, "SourceA" }, 
                    { StandardMetadata.Kind, StandardMetadata.EventKind },
                    { StandardMetadata.AssemblyName, "A" }, 
                    { StandardMetadata.Namespace, "Namespace" }, 
                    { StandardMetadata.FullName, "Namespace.EventA" }, 
                    { StandardMetadata.TypeName, "EventA" }, 
                } &&
                x.GetMetadata(eventB) == new Dictionary<string, string>
                {
                    { StandardMetadata.SourceId, eventB.SourceId.ToString() },
                    { StandardMetadata.SourceType, "SourceB" }, 
                    { StandardMetadata.Kind, StandardMetadata.EventKind },
                    { StandardMetadata.AssemblyName, "B" }, 
                    { StandardMetadata.Namespace, "Namespace" }, 
                    { StandardMetadata.FullName, "Namespace.EventB" }, 
                    { StandardMetadata.TypeName, "EventB" }, 
                } &&
                x.GetMetadata(eventC) == new Dictionary<string, string>
                {
                    { StandardMetadata.SourceId, eventC.SourceId.ToString() },
                    { StandardMetadata.SourceType, "SourceC" }, 
                    { StandardMetadata.Kind, StandardMetadata.EventKind },
                    { StandardMetadata.AssemblyName, "B" }, 
                    { StandardMetadata.Namespace, "AnotherNamespace" }, 
                    { StandardMetadata.FullName, "AnotherNamespace.EventC" }, 
                    { StandardMetadata.TypeName, "EventC" }, 
                });

            this.metadata = Mock.Get(metadata);
            this.sut = new SqlMessageLog(dbName, new JsonTextSerializer(), metadata);
            this.sut.Save(eventA);
            this.sut.Save(eventB);
            this.sut.Save(eventC);
        }
Пример #2
0
 public void Dispose()
 {
     if (_context != null)
     {
         _context.Dispose();
         _context = null;
         GC.SuppressFinalize(this);
     }
     if (_events != null)
     {
         _events.Dispose();
     }
 }
Пример #3
0
 public void Dispose()
 {
     if (context != null)
     {
         context.Dispose();
         context = null;
         GC.SuppressFinalize(this);
     }
     if (events != null)
     {
         events.Dispose();
     }
 }
Пример #4
0
                public bool MoveNext()
                {
                    if (_context == null)
                    {
                        _context = new MessageLogDbContext(_sqlQuery._nameOrConnectionString);
                        IQueryable <MessageLogEntity> queryable = _context.Set <MessageLogEntity>().AsQueryable()
                                                                  .Where(x => x.Kind == StandardMetadata.EventKind);
                        Expression <Func <MessageLogEntity, bool> > where = _sqlQuery._criteria.ToExpression();
                        if (where != null)
                        {
                            queryable = queryable.Where(where);
                        }

                        _events = queryable.AsEnumerable()
                                  .Select(x => this._sqlQuery._serializer.Deserialize <IEvent>(x.Payload)).GetEnumerator();
                    }

                    return(_events.MoveNext());
                }
Пример #5
0
        public void Save(ICommand command)
        {
            using (var context = new MessageLogDbContext(nameOrConnectionString)) {
                var metadata = metadataProvider.GetMetadata(command);

                context.Set <MessageLogEntity>()
                .Add(new MessageLogEntity {
                    Id           = Guid.NewGuid(),
                    SourceId     = command.Id.ToString(),
                    Kind         = metadata.TryGetValue(StandardMetadata.Kind),
                    AssemblyName = metadata.TryGetValue(StandardMetadata.AssemblyName),
                    FullName     = metadata.TryGetValue(StandardMetadata.FullName),
                    Namespace    = metadata.TryGetValue(StandardMetadata.Namespace),
                    TypeName     = metadata.TryGetValue(StandardMetadata.TypeName),
                    SourceType   = metadata.TryGetValue(StandardMetadata.SourceType),
                    CreationDate = DateTime.UtcNow.ToString("o"),
                    Payload      = serializer.Serialize(command)
                });
                context.SaveChanges();
            }
        }
Пример #6
0
        public void Save(IEvent @event)
        {
            using (var context = new MessageLogDbContext(this._nameOrConnectionString)) {
                IDictionary <string, string> metadata = this._metadataProvider.GetMetadata(@event);

                context.Set <MessageLogEntity>().Add(new MessageLogEntity()
                {
                    Id           = Guid.NewGuid(),
                    SourceId     = @event.SourceId.ToString(),
                    Kind         = metadata.TryGetValue(StandardMetadata.Kind),
                    AssemblyName = metadata.TryGetValue(StandardMetadata.AssemblyName),
                    FullName     = metadata.TryGetValue(StandardMetadata.FullName),
                    Namespace    = metadata.TryGetValue(StandardMetadata.Namespace),
                    TypeName     = metadata.TryGetValue(StandardMetadata.TypeName),
                    SourceType   = metadata.TryGetValue(StandardMetadata.SourceType),
                    CreationDate = DateTime.UtcNow.ToString("o"),
                    Payload      = _serializer.Serialize(@event)
                });

                context.SaveChanges();
            }
        }
Пример #7
0
                public bool MoveNext()
                {
                    if (context == null)
                    {
                        context = new MessageLogDbContext(sqlQuery.nameOrConnectionString);
                        var queryable = context.Set <MessageLogEntity>().AsQueryable()
                                        .Where(x => x.Kind == StandardMetadata.EventKind);

                        var where = sqlQuery.criteria.ToExpression();
                        if (where != null)
                        {
                            queryable = queryable.Where(where);
                        }

                        events = queryable
                                 .AsEnumerable()
                                 .Select(x => this.sqlQuery.serializer.Deserialize <IEvent>(x.Payload))
                                 .GetEnumerator();
                    }

                    return(events.MoveNext());
                }
Пример #8
0
 public void Dispose()
 {
     using (var context = new MessageLogDbContext(dbName))
     {
         if (context.Database.Exists())
         {
             context.Database.Delete();
         }
     }
 }