public void Should_Delete_Property_Value()
        {
            var dynamicEntityProperty = CreateAndGetDynamicEntityProperty();
            var propertyValue         = new DynamicEntityPropertyValue()
            {
                DynamicEntityPropertyId = dynamicEntityProperty.Id,
                EntityId = "123",
                Value    = "TestValue",
                TenantId = AbpSession.TenantId
            };

            WithUnitOfWork(() => { _dynamicEntityPropertyValueManager.Add(propertyValue); });

            RunAndCheckIfPermissionControlled(() => { _dynamicEntityPropertyValueManager.Delete(propertyValue.Id); });

            WithUnitOfWork(() =>
            {
                try
                {
                    var dynamicEntityPropertyValue = _dynamicEntityPropertyValueManager.Get(propertyValue.Id);
                    dynamicEntityPropertyValue.ShouldBeNull();
                }
                catch (EntityNotFoundException)
                {
                }
            });
        }
        public void Should_Add_Property_Value()
        {
            var dynamicEntityProperty = CreateAndGetDynamicEntityProperty();
            var val = new DynamicEntityPropertyValue()
            {
                DynamicEntityPropertyId = dynamicEntityProperty.Id,
                EntityId = "123",
                Value    = "TestValue",
                TenantId = AbpSession.TenantId
            };

            RunAndCheckIfPermissionControlled(() => { _dynamicEntityPropertyValueManager.Add(val); });

            WithUnitOfWork(() =>
            {
                var val2 = _dynamicEntityPropertyValueManager.Get(val.Id);

                val.ShouldNotBeNull();
                val2.ShouldNotBeNull();

                val.DynamicEntityPropertyId.ShouldBe(val2.DynamicEntityPropertyId);
                val.EntityId.ShouldBe(val2.EntityId);
                val.Value.ShouldBe(val2.Value);
            });
        }
        private (DynamicEntityProperty dynamicEntityProperty, List <DynamicEntityPropertyValue> values) AddTestItems(int loop = 3, string rowId = "123")
        {
            var dynamicEntityProperty = CreateAndGetDynamicEntityProperty();

            var user = AsyncHelper.RunSync(() => UserManager.FindByIdAsync(AbpSession.UserId.Value));

            AsyncHelper.RunSync(() => GrantPermissionAsync(user, TestPermission));

            var items = new List <DynamicEntityPropertyValue>();

            for (int i = 0; i < loop; i++)
            {
                WithUnitOfWork(() =>
                {
                    var item = new DynamicEntityPropertyValue()
                    {
                        DynamicEntityPropertyId = dynamicEntityProperty.Id,
                        EntityId = rowId,
                        Value    = "TestValue",
                        TenantId = AbpSession.TenantId
                    };
                    _dynamicEntityPropertyValueManager.Add(item);

                    items.Add(item);
                });
            }

            return(dynamicEntityProperty, items);
        }
        public async Task Should_Delete_Property_Value_Async()
        {
            var dynamicEntityProperty = CreateAndGetDynamicEntityProperty();
            var propertyValue         = new DynamicEntityPropertyValue()
            {
                DynamicEntityPropertyId = dynamicEntityProperty.Id,
                EntityId = "123",
                Value    = "TestValue",
                TenantId = AbpSession.TenantId
            };

            await WithUnitOfWorkAsync(async() => { await _dynamicEntityPropertyValueManager.AddAsync(propertyValue); });

            await RunAndCheckIfPermissionControlledAsync(async() => { await _dynamicEntityPropertyValueManager.DeleteAsync(propertyValue.Id); });

            await WithUnitOfWorkAsync(async() =>
            {
                try
                {
                    var dynamicEntityPropertyValue = await _dynamicEntityPropertyValueManager.GetAsync(propertyValue.Id);
                    dynamicEntityPropertyValue.ShouldBeNull();
                }
                catch (EntityNotFoundException)
                {
                }
            });
        }
        public async Task Should_Update_Property_Value_Async()
        {
            var dynamicEntityProperty = CreateAndGetDynamicEntityProperty();
            var propertyValue         = new DynamicEntityPropertyValue()
            {
                DynamicEntityPropertyId = dynamicEntityProperty.Id,
                EntityId = "123",
                Value    = "TestValue",
                TenantId = AbpSession.TenantId
            };

            await WithUnitOfWorkAsync(async() => { await _dynamicEntityPropertyValueManager.AddAsync(propertyValue); });

            await RunAndCheckIfPermissionControlledAsync(async() =>
            {
                propertyValue.Value = "TestValue2";
                await _dynamicEntityPropertyValueManager.UpdateAsync(propertyValue);
            });

            await WithUnitOfWorkAsync(async() =>
            {
                var propertyValueLatest = await _dynamicEntityPropertyValueManager.GetAsync(propertyValue.Id);
                propertyValueLatest.Value.ShouldBe("TestValue2");
                propertyValueLatest.EntityId.ShouldBe(propertyValue.EntityId);
                propertyValueLatest.DynamicEntityPropertyId.ShouldBe(propertyValue.DynamicEntityPropertyId);
            });
        }
Esempio n. 6
0
        /// <summary>
        /// 实体-创建value
        /// </summary>
        public void DynamicPropertyTest5()
        {
            var companyNameProperty = _dynamicPropertyManager.Get("CompanyName");
            List <DynamicEntityProperty> propertyList  = _dynamicEntityPropertyManager.GetAll(typeof(Contract).FullName);
            DynamicEntityProperty        dynamicEntity = propertyList.FirstOrDefault(x => x.DynamicPropertyId == companyNameProperty.Id);

            DynamicEntityPropertyValue value1 = new DynamicEntityPropertyValue(dynamicEntity, "08d936e2-88fa-4ca0-823b-b7f454685c8d",
                                                                               "伊泰集团", 1);

            _dynamicEntityPropertyValueManager.Add(value1);
        }
        private void CheckEquality(DynamicEntityPropertyValue value1, DynamicEntityPropertyValue value2)
        {
            value1.ShouldNotBeNull();
            value2.ShouldNotBeNull();

            value1.Id.ShouldBe(value2.Id);
            value1.DynamicEntityPropertyId.ShouldBe(value2.DynamicEntityPropertyId);
            value1.EntityId.ShouldBe(value2.EntityId);
            value1.Value.ShouldBe(value2.Value);
            value1.TenantId.ShouldBe(value2.TenantId);
        }
        public void Should_Update_Property_Value()
        {
            var dynamicEntityProperty = CreateAndGetDynamicEntityProperty();
            var propertyValue         = new DynamicEntityPropertyValue()
            {
                DynamicEntityPropertyId = dynamicEntityProperty.Id,
                EntityId = "123",
                Value    = "TestValue",
                TenantId = AbpSession.TenantId
            };

            WithUnitOfWork(() => { _dynamicEntityPropertyValueManager.Add(propertyValue); });

            propertyValue.Value = "TestValue2";
            RunAndCheckIfPermissionControlled(() => { _dynamicEntityPropertyValueManager.Update(propertyValue); });

            WithUnitOfWork(() =>
            {
                var propertyValueLatest = _dynamicEntityPropertyValueManager.Get(propertyValue.Id);
                propertyValueLatest.Value.ShouldBe("TestValue2");
                propertyValueLatest.EntityId.ShouldBe(propertyValue.EntityId);
                propertyValueLatest.DynamicEntityPropertyId.ShouldBe(propertyValue.DynamicEntityPropertyId);
            });
        }
        public async Task Should_Add_Property_Value_Async()
        {
            var dynamicEntityProperty = CreateAndGetDynamicEntityProperty();
            var val = new DynamicEntityPropertyValue()
            {
                DynamicEntityPropertyId = dynamicEntityProperty.Id,
                EntityId = "123",
                Value    = "TestValue",
                TenantId = AbpSession.TenantId
            };

            await RunAndCheckIfPermissionControlledAsync(() => _dynamicEntityPropertyValueManager.AddAsync(val));

            await WithUnitOfWorkAsync(async() =>
            {
                var val2 = await _dynamicEntityPropertyValueManager.GetAsync(val.Id);
                val.ShouldNotBeNull();
                val2.ShouldNotBeNull();

                val.DynamicEntityPropertyId.ShouldBe(val2.DynamicEntityPropertyId);
                val.EntityId.ShouldBe(val2.EntityId);
                val.Value.ShouldBe(val2.Value);
            });
        }