Merge pull request #15199 from abpframework/auto-merge/rel-7-0/1605

Merge branch dev with rel-7.0
pull/15202/head
maliming 3 years ago committed by GitHub
commit c72d3659dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,8 @@ using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Caching;
using Volo.Abp.Json.SystemTextJson;
using Volo.Abp.Json.SystemTextJson.Modifiers;
namespace Volo.Abp.Domain.Entities.Caching;
@ -11,7 +13,7 @@ public static class EntityCacheServiceCollectionExtensions
{
public static IServiceCollection AddEntityCache<TEntity, TKey>(
this IServiceCollection services,
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
where TEntity : Entity<TKey>
{
services
@ -21,18 +23,23 @@ public static class EntityCacheServiceCollectionExtensions
>();
services
.TryAddTransient<EntityCacheWithoutCacheItem<TEntity, TKey>>();
services.Configure<AbpDistributedCacheOptions>(options =>
{
options.ConfigureCache<TEntity>(cacheOptions ?? GetDefaultCacheOptions());
});
services.Configure<AbpSystemTextJsonSerializerModifiersOptions>(options =>
{
options.Modifiers.Add(new AbpIncludeNonPublicPropertiesModifiers<TEntity, TKey>().CreateModifyAction(x => x.Id));
});
return services;
}
public static IServiceCollection AddEntityCache<TEntity, TEntityCacheItem, TKey>(
this IServiceCollection services,
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
where TEntity : Entity<TKey>
where TEntityCacheItem : class
{
@ -43,18 +50,18 @@ public static class EntityCacheServiceCollectionExtensions
>();
services
.TryAddTransient<EntityCacheWithObjectMapper<TEntity, TEntityCacheItem, TKey>>();
services.Configure<AbpDistributedCacheOptions>(options =>
{
options.ConfigureCache<TEntityCacheItem>(cacheOptions ?? GetDefaultCacheOptions());
});
return services;
}
public static IServiceCollection AddEntityCache<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>(
this IServiceCollection services,
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
where TEntity : Entity<TKey>
where TEntityCacheItem : class
{
@ -64,12 +71,12 @@ public static class EntityCacheServiceCollectionExtensions
EntityCacheWithObjectMapperContext<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>
>();
services.TryAddTransient<EntityCacheWithObjectMapperContext<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>>();
services.Configure<AbpDistributedCacheOptions>(options =>
{
options.ConfigureCache<TEntityCacheItem>(cacheOptions ?? GetDefaultCacheOptions());
});
return services;
}
@ -79,4 +86,4 @@ public static class EntityCacheServiceCollectionExtensions
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(2)
};
}
}
}

@ -28,14 +28,10 @@ public class AbpIncludeNonPublicPropertiesModifiers<TClass, TProperty>
x.Set == null);
if (propertyJsonInfo != null)
{
var propertyInfo = typeof(TClass).GetProperty(propertyName, BindingFlags.NonPublic);
var propertyInfo = typeof(TClass).GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (propertyInfo != null)
{
var jsonPropertyInfo = jsonTypeInfo.CreateJsonPropertyInfo(typeof(TProperty), propertyJsonInfo.Name);
jsonPropertyInfo.Get = propertyInfo.GetValue;
jsonPropertyInfo.Set = propertyInfo.SetValue;
jsonTypeInfo.Properties.Remove(propertyJsonInfo);
jsonTypeInfo.Properties.Add(jsonPropertyInfo);
propertyJsonInfo.Set = propertyInfo.SetValue;
}
}
}

@ -29,10 +29,14 @@ public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonTestBase
[Fact]
public void Test()
{
var json = _jsonSerializer.Serialize(new NonPublicPropertiesClass()
var model = new NonPublicPropertiesClass
{
Id = "id"
});
};
model.SetName("my-name");
model.SetAge("42");
var json = _jsonSerializer.Serialize(model);
json.ShouldContain("id");
json.ShouldContain("name");
@ -40,8 +44,8 @@ public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonTestBase
var obj = _jsonSerializer.Deserialize<NonPublicPropertiesClass>(json);
obj.Id.ShouldBe("id");
obj.Name.ShouldBe("name");
obj.Age.ShouldBe("age");
obj.Name.ShouldBe("my-name");
obj.Age.ShouldBe("42");
}
class NonPublicPropertiesClass
@ -52,10 +56,14 @@ public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonTestBase
public string Age { get; protected set; }
public NonPublicPropertiesClass()
public void SetName(string name)
{
Name = name;
}
public void SetAge(string age)
{
Name = "name";
Age = "age";
Age = age;
}
}
}

@ -1,11 +1,12 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp.MemoryDb;
using Volo.Abp.Data;
using Volo.Abp.Autofac;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.MemoryDb;
using Volo.Abp.Json.SystemTextJson;
using Volo.Abp.MemoryDb.JsonConverters;
using Volo.Abp.TestApp;
using Volo.Abp.TestApp.Domain;
@ -33,9 +34,12 @@ public class AbpMemoryDbTestModule : AbpModule
options.AddRepository<City, CityRepository>();
});
Configure<Utf8JsonMemoryDbSerializerOptions>(options =>
{
options.JsonSerializerOptions.Converters.Add(new EntityJsonConverter<EntityWithIntPk, int>());
});
context.Services.AddOptions<Utf8JsonMemoryDbSerializerOptions>()
.Configure<IServiceProvider>((options, serviceProvider) =>
{
options.JsonSerializerOptions.Converters.Add(new EntityJsonConverter<EntityWithIntPk, int>());
options.JsonSerializerOptions.TypeInfoResolver = new AbpDefaultJsonTypeInfoResolver(serviceProvider
.GetRequiredService<IOptions<AbpSystemTextJsonSerializerModifiersOptions>>());
});
}
}

@ -25,7 +25,7 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart
ProductEntityCache = GetRequiredService<IEntityCache<Product, Guid>>();
ProductCacheItem = GetRequiredService<IEntityCache<ProductCacheItem, Guid>>();
}
[Fact]
public async Task Should_Return_Null_IF_Entity_Not_Exist()
{
@ -41,28 +41,32 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart
await Assert.ThrowsAsync<EntityNotFoundException>(() => ProductEntityCache.GetAsync(notExistId));
await Assert.ThrowsAsync<EntityNotFoundException>(() => ProductCacheItem.GetAsync(notExistId));
}
[Fact]
public async Task Should_Return_EntityCache()
{
var product = await ProductEntityCache.FindAsync(TestDataBuilder.ProductId);
product.ShouldNotBeNull();
product = await ProductEntityCache.FindAsync(TestDataBuilder.ProductId);
product.ShouldNotBeNull();
product.Id.ShouldBe(TestDataBuilder.ProductId);
product.Name.ShouldBe("Product1");
product.Price.ShouldBe(decimal.One);
var productCacheItem = await ProductCacheItem.FindAsync(product.Id);
productCacheItem.ShouldNotBeNull();
productCacheItem = await ProductCacheItem.FindAsync(product.Id);
productCacheItem.ShouldNotBeNull();
productCacheItem.Id.ShouldBe(TestDataBuilder.ProductId);
productCacheItem.Name.ShouldBe("Product1");
productCacheItem.Price.ShouldBe(decimal.One);
}
[Fact]
public async Task Should_Return_Null_IF_Deleted()
{
await ProductRepository.DeleteAsync(TestDataBuilder.ProductId);
(await ProductEntityCache.FindAsync(TestDataBuilder.ProductId)).ShouldBeNull();
(await ProductCacheItem.FindAsync(TestDataBuilder.ProductId)).ShouldBeNull();
}
@ -77,13 +81,13 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart
product.Name = "Product2";
product.Price = decimal.Zero;
await ProductRepository.UpdateAsync(product);
product = await ProductEntityCache.FindAsync(product.Id);
product.ShouldNotBeNull();
product.Id.ShouldBe(TestDataBuilder.ProductId);
product.Name.ShouldBe("Product2");
product.Price.ShouldBe(decimal.Zero);
var productCacheItem = await ProductCacheItem.FindAsync(product.Id);
productCacheItem.ShouldNotBeNull();
productCacheItem.Id.ShouldBe(TestDataBuilder.ProductId);
@ -95,6 +99,11 @@ public abstract class EntityCache_Tests<TStartupModule> : TestAppTestBase<TStart
[Serializable]
public class Product : FullAuditedAggregateRoot<Guid>
{
public Product()
{
}
public Product(Guid id, string name, decimal price)
: base(id)
{

@ -87,7 +87,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>compile; contentFiles; build; buildMultitargeting; buildTransitive; analyzers; native</PrivateAssets>
</PackageReference>

@ -79,7 +79,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>compile; contentFiles; build; buildMultitargeting; buildTransitive; analyzers; native</PrivateAssets>
</PackageReference>

@ -82,7 +82,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>compile; contentFiles; build; buildMultitargeting; buildTransitive; analyzers; native</PrivateAssets>
</PackageReference>

@ -22,7 +22,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

@ -14,7 +14,7 @@
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

@ -17,7 +17,7 @@
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.1.4.1" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1" />
</ItemGroup>
<ItemGroup>

@ -16,7 +16,7 @@
<PackageReference Include="IdentityModel" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Caching.StackExchangeRedis\Volo.Abp.Caching.StackExchangeRedis.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy\Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.csproj" />

@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

Loading…
Cancel
Save