public void Should_Get_From_Cache()
        {
            var dynamicEntityPropertyStoreSubstitute = RegisterFake <IDynamicEntityPropertyStore>();

            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) =
                InitializeDynamicEntityPropertyManagerWithCacheSubstitute();

            var dynamicProperty       = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName
            };

            var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0);

            dynamicEntityPropertyManagerCache
            .Get(cacheKey, Arg.Any <Func <string, object> >())
            .Returns(dynamicEntityProperty);

            var entity = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

            CheckEquality(entity, dynamicEntityProperty);

            dynamicEntityPropertyManagerCache.Received().Get(cacheKey, Arg.Any <Func <string, object> >());
            dynamicEntityPropertyStoreSubstitute.DidNotReceive().Get(dynamicEntityProperty.Id);
        }
        public void Should_Not_Get_From_Cache_For_Different_Tenant()
        {
            var dynamicEntityPropertyStoreSubstitute = RegisterFake <IDynamicEntityPropertyStore>();

            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) =
                InitializeDynamicEntityPropertyManagerWithCacheSubstitute();

            var dynamicProperty       = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = 2
            };

            var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0);

            dynamicEntityPropertyManagerCache
            .Get(cacheKey, Arg.Any <Func <string, object> >())
            .Returns(dynamicEntityProperty);

            Assert.Throws <NullReferenceException>(
                () => dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id)
                );
        }
        public async Task Should_Add_Property_Async()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) =
                InitializeDynamicEntityPropertyManagerWithCacheSubstitute();
            var dynamicProperty = CreateAndGetDynamicPropertyWithTestPermission();

            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            await RunAndCheckIfPermissionControlledAsync(async() =>
            {
                await dynamicEntityPropertyManager.AddAsync(dynamicEntityProperty);
            });

            var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0);
            await dynamicEntityPropertyManagerCache.Received().SetAsync(cacheKey, dynamicEntityProperty);

            WithUnitOfWork(() =>
            {
                var val = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

                val.ShouldNotBeNull();

                val.DynamicPropertyId.ShouldBe(dynamicEntityProperty.DynamicPropertyId);
                val.EntityFullName.ShouldBe(dynamicEntityProperty.EntityFullName);
            });
        }
Exemplo n.º 4
0
        public void Should_Add_Property()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) = InitializeDynamicEntityPropertyManagerWithCacheSubstitute();

            var dynamicProperty       = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            RunAndCheckIfPermissionControlled(() => { dynamicEntityPropertyManager.Add(dynamicEntityProperty); });

            dynamicEntityPropertyManagerCache.Received().Set(dynamicEntityProperty.Id.ToString(), dynamicEntityProperty);

            WithUnitOfWork(() =>
            {
                var val = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

                val.ShouldNotBeNull();

                val.DynamicPropertyId.ShouldBe(dynamicEntityProperty.DynamicPropertyId);
                val.EntityFullName.ShouldBe(dynamicEntityProperty.EntityFullName);
            });
        }
 private void CheckEquality(DynamicEntityProperty edp1, DynamicEntityProperty edp2)
 {
     edp1.ShouldNotBeNull();
     edp2.ShouldNotBeNull();
     edp1.DynamicPropertyId.ShouldBe(edp2.DynamicPropertyId);
     edp1.EntityFullName.ShouldBe(edp2.EntityFullName);
     edp1.TenantId.ShouldBe(edp2.TenantId);
 }
Exemplo n.º 6
0
        /// <summary>
        /// 实体-创建property
        /// </summary>
        public void DynamicPropertyTest4()
        {
            var contractProperty      = _dynamicPropertyManager.Get("CompanyName");
            var dynamicEntityProperty = new DynamicEntityProperty
            {
                DynamicPropertyId = contractProperty.Id,
                EntityFullName    = typeof(Contract).FullName
            };

            _dynamicEntityPropertyManager.Add(dynamicEntityProperty);
        }
Exemplo n.º 7
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);
        }
        public static async Task <DynamicEntityProperty> AddAsync <TEntity, TPrimaryKey>(this IDynamicEntityPropertyManager manager, int dynamicPropertyId, int?tenantId)
            where TEntity : IEntity <TPrimaryKey>
        {
            var entity = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicPropertyId,
                EntityFullName    = typeof(TEntity).FullName,
                TenantId          = tenantId
            };
            await manager.AddAsync(entity);

            return(entity);
        }
        public async Task Should_Delete_Property_Async()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) =
                InitializeDynamicEntityPropertyManagerWithCacheSubstitute();
            var dynamicProperty = CreateAndGetDynamicPropertyWithTestPermission();

            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            await WithUnitOfWorkAsync(async() =>
            {
                await dynamicEntityPropertyManager.AddAsync(dynamicEntityProperty);
            });

            var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0);

            await dynamicEntityPropertyManagerCache.Received().SetAsync(cacheKey, dynamicEntityProperty);

            await WithUnitOfWorkAsync(async() =>
            {
                var val = await dynamicEntityPropertyManager.GetAsync(dynamicEntityProperty.Id);

                val.ShouldNotBeNull();
                val.DynamicPropertyId.ShouldBe(dynamicEntityProperty.DynamicPropertyId);
                val.EntityFullName.ShouldBe(dynamicEntityProperty.EntityFullName);
            });

            dynamicEntityPropertyManagerCache.ClearReceivedCalls();
            await RunAndCheckIfPermissionControlledAsync(async() =>
            {
                await dynamicEntityPropertyManager.DeleteAsync(dynamicEntityProperty.Id);
            });

            await dynamicEntityPropertyManagerCache.Received().RemoveAsync(cacheKey);

            await WithUnitOfWorkAsync(async() =>
            {
                try
                {
                    var val = await dynamicEntityPropertyManager.GetAsync(dynamicEntityProperty.Id);
                    val.ShouldBeNull();
                }
                catch (EntityNotFoundException)
                {
                }
            });
        }
        protected DynamicEntityProperty CreateAndGetDynamicEntityProperty()
        {
            var dynamicProperty = CreateAndGetDynamicPropertyWithTestPermission();

            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            WithUnitOfWork(() => { DynamicEntityPropertyStore.Add(dynamicEntityProperty); });
            return(dynamicEntityProperty);
        }
        public void Should_Update_Property()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) =
                InitializeDynamicEntityPropertyManagerWithCacheSubstitute();

            var dynamicProperty       = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicProperty2      = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            WithUnitOfWork(() => { dynamicEntityPropertyManager.Add(dynamicEntityProperty); });

            var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0);

            dynamicEntityPropertyManagerCache.Received().Set(cacheKey, dynamicEntityProperty);
            dynamicEntityPropertyManagerCache.ClearReceivedCalls();

            WithUnitOfWork(() =>
            {
                dynamicEntityProperty = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

                dynamicEntityProperty.ShouldNotBeNull();
                dynamicEntityProperty.DynamicPropertyId.ShouldBe(dynamicEntityProperty.DynamicPropertyId);
                dynamicEntityProperty.EntityFullName.ShouldBe(dynamicEntityProperty.EntityFullName);
            });

            dynamicEntityProperty.DynamicPropertyId = dynamicProperty2.Id;

            dynamicEntityPropertyManagerCache.ClearReceivedCalls();
            RunAndCheckIfPermissionControlled(() => { dynamicEntityPropertyManager.Update(dynamicEntityProperty); });
            dynamicEntityPropertyManagerCache.Received().Set(cacheKey, dynamicEntityProperty);

            WithUnitOfWork(() =>
            {
                var val = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

                val.ShouldNotBeNull();
                val.DynamicPropertyId.ShouldBe(dynamicProperty2.Id);
            });
        }
        public void Should_Not_Update_Property_If_Entity_Not_Registered_Async()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) =
                InitializeDynamicEntityPropertyManagerWithCacheSubstitute();


            var dynamicProperty       = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            WithUnitOfWork(() => { dynamicEntityPropertyManager.Add(dynamicEntityProperty); });

            var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0);

            dynamicEntityPropertyManagerCache.Received().Set(cacheKey, dynamicEntityProperty);
            dynamicEntityPropertyManagerCache.ClearReceivedCalls();

            WithUnitOfWork(() =>
            {
                dynamicEntityProperty = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

                dynamicEntityProperty.ShouldNotBeNull();
                dynamicEntityProperty.DynamicPropertyId.ShouldBe(dynamicEntityProperty.DynamicPropertyId);
                dynamicEntityProperty.EntityFullName.ShouldBe(dynamicEntityProperty.EntityFullName);
            });

            dynamicEntityProperty.EntityFullName = typeof(Post).FullName;
            try
            {
                dynamicEntityPropertyManager.Update(dynamicEntityProperty);
                throw new Exception("Should check if entity registered");
            }
            catch (Exception e)
            {
                e.Message.ShouldContain(typeof(Post).FullName);
            }
        }
Exemplo n.º 13
0
        public async Task Should_Update_Property_Async()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) = InitializeDynamicEntityPropertyManagerWithCacheSubstitute();
            var dynamicProperty  = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicProperty2 = CreateAndGetDynamicPropertyWithTestPermission();

            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            await WithUnitOfWorkAsync(async() => { await dynamicEntityPropertyManager.AddAsync(dynamicEntityProperty); });

            await dynamicEntityPropertyManagerCache.Received().SetAsync(dynamicEntityProperty.Id.ToString(), dynamicEntityProperty);

            await WithUnitOfWorkAsync(async() =>
            {
                dynamicEntityProperty = await dynamicEntityPropertyManager.GetAsync(dynamicEntityProperty.Id);

                dynamicEntityProperty.ShouldNotBeNull();
                dynamicEntityProperty.DynamicPropertyId.ShouldBe(dynamicEntityProperty.DynamicPropertyId);
                dynamicEntityProperty.EntityFullName.ShouldBe(dynamicEntityProperty.EntityFullName);
            });

            dynamicEntityProperty.DynamicPropertyId = dynamicProperty2.Id;

            dynamicEntityPropertyManagerCache.ClearReceivedCalls();
            await RunAndCheckIfPermissionControlledAsync(async() => { await dynamicEntityPropertyManager.UpdateAsync(dynamicEntityProperty); });

            await dynamicEntityPropertyManagerCache.Received().SetAsync(dynamicEntityProperty.Id.ToString(), dynamicEntityProperty);

            await WithUnitOfWorkAsync(async() =>
            {
                var val = await dynamicEntityPropertyManager.GetAsync(dynamicEntityProperty.Id);

                val.ShouldNotBeNull();
                val.DynamicPropertyId.ShouldBe(dynamicProperty2.Id);
            });
        }
Exemplo n.º 14
0
        public void Should_Delete_Property()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) = InitializeDynamicEntityPropertyManagerWithCacheSubstitute();
            var dynamicProperty = CreateAndGetDynamicPropertyWithTestPermission();

            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            WithUnitOfWork(() => { dynamicEntityPropertyManager.Add(dynamicEntityProperty); });

            dynamicEntityPropertyManagerCache.Received().Set(dynamicEntityProperty.Id.ToString(), dynamicEntityProperty);

            WithUnitOfWork(() =>
            {
                dynamicEntityProperty = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

                dynamicEntityProperty.ShouldNotBeNull();
                dynamicEntityProperty.DynamicPropertyId.ShouldBe(dynamicEntityProperty.DynamicPropertyId);
                dynamicEntityProperty.EntityFullName.ShouldBe(dynamicEntityProperty.EntityFullName);
            });

            dynamicEntityPropertyManagerCache.ClearReceivedCalls();
            RunAndCheckIfPermissionControlled(() => { dynamicEntityPropertyManager.Delete(dynamicEntityProperty.Id); });
            dynamicEntityPropertyManagerCache.Received().Remove(dynamicEntityProperty.Id.ToString());

            WithUnitOfWork(() =>
            {
                try
                {
                    var val = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);
                    val.ShouldBeNull();
                }
                catch (EntityNotFoundException)
                {
                }
            });
        }
Exemplo n.º 15
0
        public void Should_Not_Add_Property_If_Entity_Not_Registered()
        {
            var(dynamicEntityPropertyManagerCache, dynamicEntityPropertyManager) = InitializeDynamicEntityPropertyManagerWithCacheSubstitute();

            var dynamicProperty       = CreateAndGetDynamicPropertyWithTestPermission();
            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = typeof(Post).FullName,
                TenantId          = AbpSession.TenantId
            };

            try
            {
                dynamicEntityPropertyManager.Add(dynamicEntityProperty);
                throw new Exception("Should check if entity registered");
            }
            catch (Exception e)
            {
                e.Message.ShouldContain(typeof(Post).FullName);
            }
        }
        public void Should_Get_From_Db()
        {
            var dynamicProperty = CreateAndGetDynamicPropertyWithTestPermission();

            var dynamicEntityProperty = new DynamicEntityProperty()
            {
                Id = -1,
                DynamicPropertyId = dynamicProperty.Id,
                EntityFullName    = TestEntityFullName,
                TenantId          = AbpSession.TenantId
            };

            var dynamicEntityPropertyStoreSubstitute = RegisterFake <IDynamicEntityPropertyStore>();

            dynamicEntityPropertyStoreSubstitute.Get(dynamicEntityProperty.Id).Returns(dynamicEntityProperty);

            var dynamicEntityPropertyManager = Resolve <IDynamicEntityPropertyManager>();

            var entity = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id);

            CheckEquality(entity, dynamicEntityProperty);

            dynamicEntityPropertyStoreSubstitute.Received().Get(dynamicEntityProperty.Id);
        }