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); }
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); }); var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0); await dynamicEntityPropertyManagerCache.Received().SetAsync(cacheKey, 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(cacheKey, dynamicEntityProperty); await WithUnitOfWorkAsync(async() => { var val = await dynamicEntityPropertyManager.GetAsync(dynamicEntityProperty.Id); val.ShouldNotBeNull(); val.DynamicPropertyId.ShouldBe(dynamicProperty2.Id); }); }
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); }); var cacheKey = dynamicEntityProperty.Id + "@" + (dynamicEntityProperty.TenantId ?? 0); dynamicEntityPropertyManagerCache.Received().Set(cacheKey, 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(cacheKey); WithUnitOfWork(() => { try { var val = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id); val.ShouldBeNull(); } catch (EntityNotFoundException) { } }); }
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); } }
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); }); dynamicEntityPropertyManagerCache.Received().Set(dynamicEntityProperty.Id.ToString(), 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(dynamicEntityProperty.Id.ToString(), dynamicEntityProperty); WithUnitOfWork(() => { var val = dynamicEntityPropertyManager.Get(dynamicEntityProperty.Id); val.ShouldNotBeNull(); val.DynamicPropertyId.ShouldBe(dynamicProperty2.Id); }); }