示例#1
0
        public entity_items CreateEntityItem(string description, int displayIndex, int entityGroupId, string entityItemUId, string microtingUId, string name, short?synced, int version, string workflowState)
        {
            entity_items eI = new entity_items();

            eI.created_at      = DateTime.Now;
            eI.description     = description;
            eI.display_index   = displayIndex;
            eI.entity_group_id = entityGroupId;
            eI.entity_item_uid = entityItemUId;
            eI.microting_uid   = microtingUId;
            eI.name            = name;
            eI.synced          = synced;
            eI.updated_at      = DateTime.Now;
            eI.version         = version;
            eI.workflow_state  = workflowState;

            DbContext.entity_items.Add(eI);
            DbContext.SaveChanges();

            return(eI);
        }
        public async Task <entity_items> CreateEntityItem(string description, int displayIndex, int entityGroupId, string entityItemUId, string microtingUId, string name, short?synced, int version, string workflowState)
        {
            entity_items eI = new entity_items();

            eI.CreatedAt     = DateTime.UtcNow;
            eI.Description   = description;
            eI.DisplayIndex  = displayIndex;
            eI.EntityGroupId = entityGroupId;
            eI.EntityItemUid = entityItemUId;
            eI.MicrotingUid  = microtingUId;
            eI.Name          = name;
            eI.Synced        = synced;
            eI.UpdatedAt     = DateTime.UtcNow;
            eI.Version       = version;
            eI.WorkflowState = workflowState;

            dbContext.entity_items.Add(eI);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            return(eI);
        }
        public async Task EntityItems_Create_DoesCreate()
        {
            //Arrange

            short shortMinValue = Int16.MinValue;
            short shortmaxValue = Int16.MaxValue;

            Random rnd = new Random();

            entity_groups entityGroup = new entity_groups
            {
                Name         = Guid.NewGuid().ToString(),
                Type         = Guid.NewGuid().ToString(),
                MicrotingUid = Guid.NewGuid().ToString()
            };
            await entityGroup.Create(dbContext).ConfigureAwait(false);

            entity_items entityItem = new entity_items
            {
                Description   = Guid.NewGuid().ToString(),
                Name          = Guid.NewGuid().ToString(),
                Synced        = (short)rnd.Next(shortMinValue, shortmaxValue),
                DisplayIndex  = rnd.Next(1, 255),
                MicrotingUid  = Guid.NewGuid().ToString(),
                EntityItemUid = Guid.NewGuid().ToString(),
                EntityGroupId = entityGroup.Id
            };

            //Act

            await entityItem.Create(dbContext).ConfigureAwait(false);

            List <entity_items>         entityItems       = dbContext.entity_items.AsNoTracking().ToList();
            List <entity_item_versions> entityItemVersion = dbContext.entity_item_versions.AsNoTracking().ToList();

            //Assert

            Assert.NotNull(entityItems);
            Assert.NotNull(entityItemVersion);

            Assert.AreEqual(1, entityItems.Count());
            Assert.AreEqual(1, entityItemVersion.Count());

            Assert.AreEqual(entityItem.CreatedAt.ToString(), entityItems[0].CreatedAt.ToString());
            Assert.AreEqual(entityItem.Version, entityItems[0].Version);
//            Assert.AreEqual(entityItem.UpdatedAt.ToString(), entityItems[0].UpdatedAt.ToString());
            Assert.AreEqual(entityItems[0].WorkflowState, Constants.WorkflowStates.Created);
            Assert.AreEqual(entityItem.Id, entityItems[0].Id);
            Assert.AreEqual(entityItem.Name, entityItems[0].Name);
            Assert.AreEqual(entityItem.Description, entityItems[0].Description);
            Assert.AreEqual(entityItem.Synced, entityItems[0].Synced);
            Assert.AreEqual(entityItem.DisplayIndex, entityItems[0].DisplayIndex);
            Assert.AreEqual(entityItem.EntityItemUid, entityItems[0].EntityItemUid);
            Assert.AreEqual(entityItem.MicrotingUid, entityItems[0].MicrotingUid);
            Assert.AreEqual(entityItem.EntityGroupId, entityGroup.Id);

            //Versions
            Assert.AreEqual(entityItem.CreatedAt.ToString(), entityItemVersion[0].CreatedAt.ToString());
            Assert.AreEqual(entityItem.Version, entityItemVersion[0].Version);
//            Assert.AreEqual(entityItem.UpdatedAt.ToString(), entityItemVersion[0].UpdatedAt.ToString());
            Assert.AreEqual(entityItemVersion[0].WorkflowState, Constants.WorkflowStates.Created);
            Assert.AreEqual(entityItem.Id, entityItemVersion[0].EntityItemsId);
            Assert.AreEqual(entityItem.Name, entityItemVersion[0].Name);
            Assert.AreEqual(entityItem.Description, entityItemVersion[0].Description);
            Assert.AreEqual(entityItem.Synced, entityItemVersion[0].Synced);
            Assert.AreEqual(entityItem.DisplayIndex, entityItemVersion[0].DisplayIndex);
            Assert.AreEqual(entityItem.EntityItemUid, entityItemVersion[0].EntityItemUid);
            Assert.AreEqual(entityItem.MicrotingUid, entityItemVersion[0].MicrotingUid);
            Assert.AreEqual(entityGroup.Id, entityItemVersion[0].EntityGroupId);
        }