示例#1
0
        public void should_Save_IndexConstraint()
        {
            eventWraps = new List <EventStorageBufferWrap>();
            for (int i = 0; i < 3; i++)
            {
                var e = TestEvent.Create(i);
                if (i == 2)
                {
                    e.RelationEvent = "RelationEvent1";
                }
                else
                {
                    e.RelationEvent = "RelationEvent" + i;
                }

                e.StateId = 3000;
                EventStorageModel model = new EventStorageModel(e.StateId, e, this.EventSourceName, this.TableName);
                eventWraps.Add(new EventStorageBufferWrap(model));
            }

            this.Given(f => f.Given_CreateTable())
            .When(f => f.When_Save(eventWraps))
            .Then(f => Then_Save_IndexConstraint(eventWraps))
            .BDDfy();
        }
示例#2
0
        public async Task SqlSaveAsync(PostgreSqlDbContext db, List <IDataflowBufferWrap <EventStorageModel> > eventWraps)
        {
            using (var trans = db.BeginTransaction())
            {
                try
                {
                    foreach (var wrap in eventWraps)
                    {
                        EventStorageModel model = wrap.Data;
                        var data = this.GetSerializer().Serialize(model.Event);

                        wrap.Data.Result = await db.ExecuteAsync(this.insertSql, new
                        {
                            Id            = model.Id,
                            RelationEvent = model.Event.RelationEvent,
                            TypeCode      = model.Event.TypeCode,
                            Data          = data,
                            DataType      = this.options.SerializationType,
                            Version       = model.Event.Version,
                            AddTime       = model.Event.Timestamp
                        }) > 0;
                    }
                    trans.Commit();
                    eventWraps.ForEach(wrap => wrap.CompleteHandler(wrap.Data.Result));
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    eventWraps.ForEach(wrap => wrap.ExceptionHandler(ex));
                }
            }
        }
示例#3
0
        public void should_GetList()
        {
            eventWraps = new List <EventStorageBufferWrap>();
            for (int i = 0; i < 100; i++)
            {
                var e = TestEvent.Create(1);
                e.StateId = 4000 + i;

                if (i < 50)
                {
                    e.RelationEvent = "Test";
                }
                else
                {
                    e.RelationEvent = "ABC";
                }
                EventStorageModel model = new EventStorageModel(e.StateId, e, this.EventSourceName, this.TableName);
                eventWraps.Add(new EventStorageBufferWrap(model));
            }

            this.Given(f => f.Given_CreateTable())
            .When(f => f.When_Save(eventWraps))
            .Then(f => f.Then_GetList_Success(eventWraps))
            .BDDfy();
        }
示例#4
0
        public async Task <bool> SaveAsync(IEvent <TStateKey> @event)
        {
            //Sharding processing
            string storageTableName = await this.GetEventTableName();

            EventStorageModel storageModel = new EventStorageModel(@event.StateId, @event, this.Options.EventSourceName, storageTableName);

            return(await this._eventBufferBlock.SendAsync(storageModel));
        }
示例#5
0
        public void should_Save_MickleSuccess()
        {
            eventWraps = new List <EventStorageBufferWrap>();
            for (int i = 0; i < 100; i++)
            {
                var e = TestEvent.Create(1);
                e.StateId = 1001 + i;
                EventStorageModel model = new EventStorageModel(e.StateId, e, this.EventSourceName, this.TableName);
                eventWraps.Add(new EventStorageBufferWrap(model));
            }

            this.Given(f => f.Given_CreateTable())
            .When(f => f.When_Save(eventWraps))
            .Then(f => f.Then_Save_MickleSuccess())
            .BDDfy();
        }
示例#6
0
        public async Task <bool> SaveAsync(IList <IEvent <TStateKey> > events)
        {
            if (events.Count == 0)
            {
                return(true);
            }
            string storageTableName = await this.GetEventTableName();

            EventCollectionStorageModel storageModel = new EventCollectionStorageModel(this.Options.EventSourceName, storageTableName);

            foreach (var e in events)
            {
                EventStorageModel eventModel = new EventStorageModel(e.StateId, e);
                storageModel.Events.Add(eventModel);
            }
            return(await this._eventStorage.SaveAsync(storageModel));
        }
示例#7
0
        public void should_Save_UniqueConstraint()
        {
            eventWraps = new List <EventStorageBufferWrap>();
            for (int i = 0; i < 3; i++)
            {
                var e = TestEvent.Create(i);
                if (i == 2)
                {
                    e.Version = 1;
                }
                e.StateId = 2000;
                EventStorageModel model = new EventStorageModel(e.StateId, e, this.EventSourceName, this.TableName);
                eventWraps.Add(new EventStorageBufferWrap(model));
            }

            this.Given(f => f.Given_CreateTable())
            .Then(f => Then_Save_UniqueConstraint(eventWraps))
            .BDDfy();
        }
示例#8
0
        public void should_Save_SingleSuccess()
        {
            var e = TestEvent.Create(1);

            e.StateId = 1000;
            EventStorageModel model = new EventStorageModel(e.StateId, e, this.EventSourceName, this.TableName);

            eventWrap = new EventStorageBufferWrap(model);
            List <EventStorageBufferWrap> eventWraps = new List <EventStorageBufferWrap>
            {
                eventWrap
            };

            this
            .Given(f => f.Given_CreateTable())
            .When(f => f.When_Save(eventWraps))
            .When(f => f.When_Get(e.StateId, e.Version))
            .Then(f => f.Then_Save_SingleSuccess(e))
            .BDDfy();
        }
示例#9
0
        //public IEnumerable<Event> GetEvents()
        //{
        //    return _culturalHubContext.Events
        //        .Where(e => e.Deleted == null)
        //        .Select(e =>
        //            new Event(new EventId(e.Id),
        //                new ClientId(e.ClientId),
        //                new EventTitle(e.Title),
        //                new EventDescription(e.Description),
        //                new Location(e.LocationAddress, (LocationType) e.LocationType),
        //                new EventDate(e.StartsAt.Year, e.StartsAt.Month, e.StartsAt.Day, e.StartsAt.Hour,
        //                    e.StartsAt.Minute),
        //                new EventDate(e.EndsAt.Year, e.EndsAt.Month, e.EndsAt.Day, e.EndsAt.Hour, e.EndsAt.Minute),
        //                (EventType) e.Type,
        //                (Audience) e.Audience,
        //                new EventPublishDate(e.PublishDate),
        //                e.IsActive)
        //        );
        //}

        //public List<Event> GetEvents()
        //{
        //    return _culturalHubContext.Events
        //        .Where(e => e.Deleted == null)
        //        .Select(e =>
        //            new Event(new EventId(e.Id),
        //                new ClientId(e.ClientId),
        //                new EventTitle(e.Title),
        //                new EventDescription(e.Description),
        //                new Location(e.LocationAddress, (LocationType) e.LocationType),
        //                new EventDate(e.StartsAt.Year, e.StartsAt.Month, e.StartsAt.Day, e.StartsAt.Hour,
        //                    e.StartsAt.Minute),
        //                new EventDate(e.EndsAt.Year, e.EndsAt.Month, e.EndsAt.Day, e.EndsAt.Hour, e.EndsAt.Minute),
        //                (EventType) e.Type,
        //                (Audience) e.Audience,
        //                new EventPublishDate(e.PublishDate),
        //                e.IsActive)
        //        )
        //        .ToList();
        //}

        public Event AddEvent(Event e)
        {
            var eventStorageModel = new EventStorageModel
            {
                Id              = e.Id.Value,
                ClientId        = e.ClientId.Value,
                Title           = e.Title.TitleValue,
                StartsAt        = e.StartsAt.Value,
                Description     = e.Description.DescriptionValue,
                EndsAt          = e.EndsAt.Value,
                Audience        = (int)e.Audience,
                Type            = (int)e.Type,
                PublishDate     = e.PublishDate.Value,
                IsActive        = e.IsActive,
                LocationAddress = e.Location.Address,
                LocationType    = (int)e.Location.Type
            };

            _culturalHubContext.Events.Add(eventStorageModel);

            _culturalHubContext.SaveChanges();

            return(e);
        }