Browse Source

Merge pull request #24373 from MarkCiliaVincenti/Frozen

Use frozen collections where suitable
pr/6814
Ma Liming 10 months ago
committed by GitHub
parent
commit
c9a4ab4fe5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 31
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/DatePicker/AbpDatePickerBaseTagHelperService.cs
  2. 6
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs
  3. 8
      framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpBackgroundWorkersTickerQOptions.cs
  4. 11
      framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiObjectExtensionPropertyInfoExtensions.cs
  5. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs
  6. 4
      framework/src/Volo.Abp.Core/Volo/Abp/Logging/DefaultInitLoggerFactory.cs
  7. 9
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs
  8. 33
      framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs
  9. 6
      framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs
  10. 2
      framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LocalizationResourceDictionary.cs
  11. 2
      framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDatabaseCollection.cs
  12. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs
  13. 2
      framework/src/Volo.Abp.Specifications/Volo/Abp/Specifications/ParameterRebinder.cs
  14. 165
      framework/test/Volo.Abp.MultiLingualObjects.Tests/Volo/Abp/MultiLingualObjects/MultiLingualObjectManager_Tests.cs
  15. 5
      modules/docs/app/VoloDocs.Web/Pages/Error.cshtml.cs

31
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/DatePicker/AbpDatePickerBaseTagHelperService.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@ -23,7 +24,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.DatePicker;
public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelperService<TTagHelper> public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelperService<TTagHelper>
where TTagHelper : AbpDatePickerBaseTagHelper<TTagHelper> where TTagHelper : AbpDatePickerBaseTagHelper<TTagHelper>
{ {
protected readonly Dictionary<Type, Func<object, string>> SupportedInputTypes; protected readonly FrozenDictionary<Type, Func<object, string>> SupportedInputTypes;
protected readonly IJsonSerializer JsonSerializer; protected readonly IJsonSerializer JsonSerializer;
protected readonly IHtmlGenerator Generator; protected readonly IHtmlGenerator Generator;
@ -103,7 +104,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
return string.Empty; return string.Empty;
} }
} }
}; }.ToFrozenDictionary();
} }
protected virtual T? GetAttribute<T>() where T : Attribute protected virtual T? GetAttribute<T>() where T : Attribute
@ -136,7 +137,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
? await ProcessButtonAndGetContentAsync(context, output, "calendar", "open") ? await ProcessButtonAndGetContentAsync(context, output, "calendar", "open")
: ""; : "";
var clearButtonContent = TagHelper.ClearButton == true || (!TagHelper.ClearButton.HasValue && TagHelper.AutoUpdateInput != true) var clearButtonContent = TagHelper.ClearButton == true || (!TagHelper.ClearButton.HasValue && TagHelper.AutoUpdateInput != true)
? await ProcessButtonAndGetContentAsync(context, output, "times", "clear", visible:!TagHelper.SingleOpenAndClearButton) ? await ProcessButtonAndGetContentAsync(context, output, "times", "clear", visible: !TagHelper.SingleOpenAndClearButton)
: ""; : "";
var labelContent = await GetLabelAsHtmlAsync(context, output, TagHelperOutput); var labelContent = await GetLabelAsHtmlAsync(context, output, TagHelperOutput);
@ -269,7 +270,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
{ {
var attrList = new TagHelperAttributeList(); var attrList = new TagHelperAttributeList();
if(options == null) if (options == null)
{ {
return attrList; return attrList;
} }
@ -401,29 +402,29 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
attrList.Add("data-visible-date-format", options.VisibleDateFormat); attrList.Add("data-visible-date-format", options.VisibleDateFormat);
} }
if(!options.InputDateFormat.IsNullOrEmpty()) if (!options.InputDateFormat.IsNullOrEmpty())
{ {
attrList.Add("data-input-date-format", options.InputDateFormat); attrList.Add("data-input-date-format", options.InputDateFormat);
} }
if(options.Ranges != null && options.Ranges.Any()) if (options.Ranges != null && options.Ranges.Any())
{ {
var ranges = options.Ranges.ToDictionary(r => r.Label, r => r.Dates); var ranges = options.Ranges.ToDictionary(r => r.Label, r => r.Dates);
attrList.Add("data-ranges", JsonSerializer.Serialize(ranges)); attrList.Add("data-ranges", JsonSerializer.Serialize(ranges));
} }
if(options.AlwaysShowCalendars != null) if (options.AlwaysShowCalendars != null)
{ {
attrList.Add("data-always-show-calendars", options.AlwaysShowCalendars.ToString()!.ToLowerInvariant()); attrList.Add("data-always-show-calendars", options.AlwaysShowCalendars.ToString()!.ToLowerInvariant());
} }
if(options.ShowCustomRangeLabel == false) if (options.ShowCustomRangeLabel == false)
{ {
attrList.Add("data-show-custom-range-label", options.ShowCustomRangeLabel.ToString()!.ToLowerInvariant()); attrList.Add("data-show-custom-range-label", options.ShowCustomRangeLabel.ToString()!.ToLowerInvariant());
} }
if(options.Options != null) if (options.Options != null)
{ {
attrList.Add("data-options", JsonSerializer.Serialize(options.Options)); attrList.Add("data-options", JsonSerializer.Serialize(options.Options));
} }
@ -443,7 +444,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
attrList.Add("id", options.PickerId); attrList.Add("id", options.PickerId);
} }
if(!options.SingleOpenAndClearButton) if (!options.SingleOpenAndClearButton)
{ {
attrList.Add("data-single-open-and-clear-button", options.SingleOpenAndClearButton.ToString().ToLowerInvariant()); attrList.Add("data-single-open-and-clear-button", options.SingleOpenAndClearButton.ToString().ToLowerInvariant());
} }
@ -614,7 +615,8 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
{ {
return string.Empty; return string.Empty;
} }
var labelTagHelper = new LabelTagHelper(Generator) { var labelTagHelper = new LabelTagHelper(Generator)
{
ViewContext = TagHelper.ViewContext, ViewContext = TagHelper.ViewContext,
For = modelExpression For = modelExpression
}; };
@ -764,7 +766,8 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
TagHelper.Size = attribute.Size; TagHelper.Size = attribute.Size;
} }
return TagHelper.Size switch { return TagHelper.Size switch
{
AbpFormControlSize.Small => "form-control-sm", AbpFormControlSize.Small => "form-control-sm",
AbpFormControlSize.Medium => "form-control-md", AbpFormControlSize.Medium => "form-control-md",
AbpFormControlSize.Large => "form-control-lg", AbpFormControlSize.Large => "form-control-lg",
@ -785,14 +788,14 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
protected virtual async Task<string> GetValidationAsHtmlByInputAsync(TagHelperContext context, protected virtual async Task<string> GetValidationAsHtmlByInputAsync(TagHelperContext context,
TagHelperOutput output, TagHelperOutput output,
[NotNull]ModelExpression @for) [NotNull] ModelExpression @for)
{ {
var validationMessageTagHelper = var validationMessageTagHelper =
new ValidationMessageTagHelper(Generator) { For = @for, ViewContext = TagHelper.ViewContext }; new ValidationMessageTagHelper(Generator) { For = @for, ViewContext = TagHelper.ViewContext };
var attributeList = new TagHelperAttributeList { { "class", "text-danger" } }; var attributeList = new TagHelperAttributeList { { "class", "text-danger" } };
if(!output.Attributes.TryGetAttribute("name", out var nameAttribute) || nameAttribute == null || nameAttribute.Value == null) if (!output.Attributes.TryGetAttribute("name", out var nameAttribute) || nameAttribute == null || nameAttribute.Value == null)
{ {
if (nameAttribute != null) if (nameAttribute != null)
{ {

6
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -8,7 +9,8 @@ namespace Volo.Abp.ObjectExtending;
public static class MvcUiObjectExtensionPropertyInfoExtensions public static class MvcUiObjectExtensionPropertyInfoExtensions
{ {
private static readonly HashSet<Type> NumberTypes = new HashSet<Type> { private static readonly FrozenSet<Type> NumberTypes = new HashSet<Type>
{
typeof(int), typeof(int),
typeof(long), typeof(long),
typeof(byte), typeof(byte),
@ -33,7 +35,7 @@ public static class MvcUiObjectExtensionPropertyInfoExtensions
typeof(float?), typeof(float?),
typeof(double?), typeof(double?),
typeof(decimal?) typeof(decimal?)
}; }.ToFrozenSet();
public static string? GetInputFormatOrNull(this IBasicObjectExtensionPropertyInfo property) public static string? GetInputFormatOrNull(this IBasicObjectExtensionPropertyInfo property)
{ {

8
framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpBackgroundWorkersTickerQOptions.cs

@ -5,11 +5,11 @@ namespace Volo.Abp.BackgroundWorkers.TickerQ;
public class AbpBackgroundWorkersTickerQOptions public class AbpBackgroundWorkersTickerQOptions
{ {
private readonly Dictionary<Type, AbpBackgroundWorkersCronTickerConfiguration> _onfigurations; private readonly Dictionary<Type, AbpBackgroundWorkersCronTickerConfiguration> _configurations;
public AbpBackgroundWorkersTickerQOptions() public AbpBackgroundWorkersTickerQOptions()
{ {
_onfigurations = new Dictionary<Type, AbpBackgroundWorkersCronTickerConfiguration>(); _configurations = new Dictionary<Type, AbpBackgroundWorkersCronTickerConfiguration>();
} }
public void AddConfiguration<TWorker>(AbpBackgroundWorkersCronTickerConfiguration configuration) public void AddConfiguration<TWorker>(AbpBackgroundWorkersCronTickerConfiguration configuration)
@ -19,7 +19,7 @@ public class AbpBackgroundWorkersTickerQOptions
public void AddConfiguration(Type workerType, AbpBackgroundWorkersCronTickerConfiguration configuration) public void AddConfiguration(Type workerType, AbpBackgroundWorkersCronTickerConfiguration configuration)
{ {
_onfigurations[workerType] = configuration; _configurations[workerType] = configuration;
} }
public AbpBackgroundWorkersCronTickerConfiguration? GetConfigurationOrNull<TJob>() public AbpBackgroundWorkersCronTickerConfiguration? GetConfigurationOrNull<TJob>()
@ -29,6 +29,6 @@ public class AbpBackgroundWorkersTickerQOptions
public AbpBackgroundWorkersCronTickerConfiguration? GetConfigurationOrNull(Type workerType) public AbpBackgroundWorkersCronTickerConfiguration? GetConfigurationOrNull(Type workerType)
{ {
return _onfigurations.GetValueOrDefault(workerType); return _configurations.GetValueOrDefault(workerType);
} }
} }

11
framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiObjectExtensionPropertyInfoExtensions.cs

@ -1,5 +1,6 @@
using Blazorise; using Blazorise;
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@ -11,7 +12,8 @@ namespace Volo.Abp.BlazoriseUI;
public static class BlazoriseUiObjectExtensionPropertyInfoExtensions public static class BlazoriseUiObjectExtensionPropertyInfoExtensions
{ {
private static readonly HashSet<Type> NumberTypes = new HashSet<Type> { private static readonly FrozenSet<Type> NumberTypes = new HashSet<Type>
{
typeof(int), typeof(int),
typeof(long), typeof(long),
typeof(byte), typeof(byte),
@ -36,13 +38,14 @@ public static class BlazoriseUiObjectExtensionPropertyInfoExtensions
typeof(float?), typeof(float?),
typeof(double?), typeof(double?),
typeof(decimal?) typeof(decimal?)
}; }.ToFrozenSet();
private static readonly HashSet<Type> TextEditSupportedAttributeTypes = new HashSet<Type> { private static readonly FrozenSet<Type> TextEditSupportedAttributeTypes = new HashSet<Type>
{
typeof(EmailAddressAttribute), typeof(EmailAddressAttribute),
typeof(UrlAttribute), typeof(UrlAttribute),
typeof(PhoneAttribute) typeof(PhoneAttribute)
}; }.ToFrozenSet();
public static string? GetDateEditInputFormatOrNull(this IBasicObjectExtensionPropertyInfo property) public static string? GetDateEditInputFormatOrNull(this IBasicObjectExtensionPropertyInfo property)
{ {

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

@ -3,14 +3,12 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NuGet.Versioning; using NuGet.Versioning;
using Volo.Abp.Cli.Http;
using Volo.Abp.Cli.LIbs; using Volo.Abp.Cli.LIbs;
using Volo.Abp.Cli.Utils; using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -28,14 +26,12 @@ public class NpmPackagesUpdater : ITransientDependency
private readonly PackageJsonFileFinder _packageJsonFileFinder; private readonly PackageJsonFileFinder _packageJsonFileFinder;
private readonly NpmGlobalPackagesChecker _npmGlobalPackagesChecker; private readonly NpmGlobalPackagesChecker _npmGlobalPackagesChecker;
private readonly Dictionary<string, string> _fileVersionStorage = new Dictionary<string, string>(); private readonly Dictionary<string, string> _fileVersionStorage = [];
private readonly CliHttpClientFactory _cliHttpClientFactory;
public NpmPackagesUpdater( public NpmPackagesUpdater(
PackageJsonFileFinder packageJsonFileFinder, PackageJsonFileFinder packageJsonFileFinder,
NpmGlobalPackagesChecker npmGlobalPackagesChecker, NpmGlobalPackagesChecker npmGlobalPackagesChecker,
ICancellationTokenProvider cancellationTokenProvider, ICancellationTokenProvider cancellationTokenProvider,
CliHttpClientFactory cliHttpClientFactory,
IInstallLibsService installLibsService, IInstallLibsService installLibsService,
ICmdHelper cmdHelper) ICmdHelper cmdHelper)
{ {
@ -44,7 +40,6 @@ public class NpmPackagesUpdater : ITransientDependency
CancellationTokenProvider = cancellationTokenProvider; CancellationTokenProvider = cancellationTokenProvider;
InstallLibsService = installLibsService; InstallLibsService = installLibsService;
CmdHelper = cmdHelper; CmdHelper = cmdHelper;
_cliHttpClientFactory = cliHttpClientFactory;
Logger = NullLogger<NpmPackagesUpdater>.Instance; Logger = NullLogger<NpmPackagesUpdater>.Instance;
} }

4
framework/src/Volo.Abp.Core/Volo/Abp/Logging/DefaultInitLoggerFactory.cs

@ -5,10 +5,10 @@ namespace Volo.Abp.Logging;
public class DefaultInitLoggerFactory : IInitLoggerFactory public class DefaultInitLoggerFactory : IInitLoggerFactory
{ {
private readonly Dictionary<Type, object> _cache = new Dictionary<Type, object>(); private readonly Dictionary<Type, object> _cache = [];
public virtual IInitLogger<T> Create<T>() public virtual IInitLogger<T> Create<T>()
{ {
return (IInitLogger<T>)_cache.GetOrAdd(typeof(T), () => new DefaultInitLogger<T>()); ; return (IInitLogger<T>)_cache.GetOrAdd(typeof(T), () => new DefaultInitLogger<T>());
} }
} }

9
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.ComponentModel; using System.ComponentModel;
@ -13,14 +14,14 @@ namespace Volo.Abp.Reflection;
public static class TypeHelper public static class TypeHelper
{ {
private static readonly HashSet<Type> FloatingTypes = new HashSet<Type> private static readonly FrozenSet<Type> FloatingTypes = new HashSet<Type>
{ {
typeof(float), typeof(float),
typeof(double), typeof(double),
typeof(decimal) typeof(decimal)
}; }.ToFrozenSet();
private static readonly HashSet<Type> NonNullablePrimitiveTypes = new HashSet<Type> private static readonly FrozenSet<Type> NonNullablePrimitiveTypes = new HashSet<Type>
{ {
typeof(byte), typeof(byte),
typeof(short), typeof(short),
@ -37,7 +38,7 @@ public static class TypeHelper
typeof(DateTimeOffset), typeof(DateTimeOffset),
typeof(TimeSpan), typeof(TimeSpan),
typeof(Guid) typeof(Guid)
}; }.ToFrozenSet();
public static bool IsNonNullablePrimitiveType(Type type) public static bool IsNonNullablePrimitiveType(Type type)
{ {

33
framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs

@ -1,3 +1,4 @@
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -5,23 +6,23 @@ namespace Volo.Abp.EventBus.RabbitMq;
public class PostConfigureAbpRabbitMqEventBusOptions : IPostConfigureOptions<AbpRabbitMqEventBusOptions> public class PostConfigureAbpRabbitMqEventBusOptions : IPostConfigureOptions<AbpRabbitMqEventBusOptions>
{ {
private readonly HashSet<string> _uint64QueueArguments = private readonly FrozenSet<string> _uint64QueueArguments = new HashSet<string>
[ {
"x-delivery-limit", "x-delivery-limit",
"x-expires", "x-expires",
"x-message-ttl", "x-message-ttl",
"x-max-length", "x-max-length",
"x-max-length-bytes", "x-max-length-bytes",
"x-quorum-initial-group-size", "x-quorum-initial-group-size",
"x-quorum-target-group-size", "x-quorum-target-group-size",
"x-stream-filter-size-bytes", "x-stream-filter-size-bytes",
"x-stream-max-segment-size-bytes", "x-stream-max-segment-size-bytes",
]; }.ToFrozenSet();
private readonly HashSet<string> _boolQueueArguments = private readonly FrozenSet<string> _boolQueueArguments = new HashSet<string>
[ {
"x-single-active-consumer" "x-single-active-consumer"
]; }.ToFrozenSet();
public virtual void PostConfigure(string? name, AbpRabbitMqEventBusOptions options) public virtual void PostConfigure(string? name, AbpRabbitMqEventBusOptions options)
{ {

6
framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -10,7 +11,8 @@ internal static class ProxyScriptingJsFuncHelper
{ {
private const string ValidJsVariableNameChars = "abcdefghijklmnopqrstuxwvyzABCDEFGHIJKLMNOPQRSTUXWVYZ0123456789_"; private const string ValidJsVariableNameChars = "abcdefghijklmnopqrstuxwvyzABCDEFGHIJKLMNOPQRSTUXWVYZ0123456789_";
private static readonly HashSet<string> ReservedWords = new HashSet<string> { private static readonly FrozenSet<string> ReservedWords = new HashSet<string>
{
"abstract", "abstract",
"else", "else",
"instanceof", "instanceof",
@ -71,7 +73,7 @@ internal static class ProxyScriptingJsFuncHelper
"in", "in",
"static", "static",
"with" "with"
}; }.ToFrozenSet();
public static string NormalizeJsVariableName(string name, string additionalChars = "") public static string NormalizeJsVariableName(string name, string additionalChars = "")
{ {

2
framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LocalizationResourceDictionary.cs

@ -6,7 +6,7 @@ namespace Volo.Abp.Localization;
public class LocalizationResourceDictionary : Dictionary<string, LocalizationResourceBase> public class LocalizationResourceDictionary : Dictionary<string, LocalizationResourceBase>
{ {
private readonly Dictionary<Type, LocalizationResourceBase> _resourcesByTypes = new(); private readonly Dictionary<Type, LocalizationResourceBase> _resourcesByTypes = [];
public LocalizationResource Add<TResouce>(string? defaultCultureName = null) public LocalizationResource Add<TResouce>(string? defaultCultureName = null)
{ {

2
framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDatabaseCollection.cs

@ -9,7 +9,7 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb;
public class MemoryDatabaseCollection<TEntity> : IMemoryDatabaseCollection<TEntity> public class MemoryDatabaseCollection<TEntity> : IMemoryDatabaseCollection<TEntity>
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
private readonly Dictionary<string, byte[]> _dictionary = new Dictionary<string, byte[]>(); private readonly Dictionary<string, byte[]> _dictionary = [];
private readonly IMemoryDbSerializer _memoryDbSerializer; private readonly IMemoryDbSerializer _memoryDbSerializer;

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs

@ -17,7 +17,7 @@ public class MongoModelBuilder : IMongoModelBuilder
{ {
private readonly Dictionary<Type, object> _entityModelBuilders; private readonly Dictionary<Type, object> _entityModelBuilders;
private static readonly object SyncObj = new object(); private static readonly object SyncObj = new();
public MongoModelBuilder() public MongoModelBuilder()
{ {

2
framework/src/Volo.Abp.Specifications/Volo/Abp/Specifications/ParameterRebinder.cs

@ -15,7 +15,7 @@ internal class ParameterRebinder : ExpressionVisitor
internal ParameterRebinder(Dictionary<ParameterExpression, ParameterExpression> map) internal ParameterRebinder(Dictionary<ParameterExpression, ParameterExpression> map)
{ {
_map = map ?? new Dictionary<ParameterExpression, ParameterExpression>(); _map = map ?? [];
} }
internal static Expression ReplaceParameters(Dictionary<ParameterExpression, ParameterExpression> map, internal static Expression ReplaceParameters(Dictionary<ParameterExpression, ParameterExpression> map,

165
framework/test/Volo.Abp.MultiLingualObjects.Tests/Volo/Abp/MultiLingualObjects/MultiLingualObjectManager_Tests.cs

@ -1,37 +1,38 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Shouldly; using Shouldly;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.MultiLingualObjects.TestObjects; using Volo.Abp.MultiLingualObjects.TestObjects;
using Volo.Abp.Testing; using Volo.Abp.Testing;
using Xunit; using Xunit;
namespace Volo.Abp.MultiLingualObjects; namespace Volo.Abp.MultiLingualObjects;
public class MultiLingualObjectManager_Tests : AbpIntegratedTest<AbpMultiLingualObjectsTestModule> public class MultiLingualObjectManager_Tests : AbpIntegratedTest<AbpMultiLingualObjectsTestModule>
{ {
private readonly IMultiLingualObjectManager _multiLingualObjectManager; private readonly IMultiLingualObjectManager _multiLingualObjectManager;
private readonly MultiLingualBook _book; private readonly MultiLingualBook _book;
private readonly List<MultiLingualBook> _books; private readonly List<MultiLingualBook> _books;
private readonly IMapperAccessor _mapperAccessor; private readonly IMapperAccessor _mapperAccessor;
private readonly Dictionary<string, string> _testTranslations = new() private readonly FrozenDictionary<string, string> _testTranslations = new Dictionary<string, string>
{ {
["ar"] = "C# التعمق في", ["ar"] = "C# التعمق في",
["zh-Hans"] = "深入理解C#", ["zh-Hans"] = "深入理解C#",
["en"] = "C# in Depth" ["en"] = "C# in Depth"
}; }.ToFrozenDictionary();
public MultiLingualObjectManager_Tests() public MultiLingualObjectManager_Tests()
{ {
_multiLingualObjectManager = ServiceProvider.GetRequiredService<IMultiLingualObjectManager>(); _multiLingualObjectManager = ServiceProvider.GetRequiredService<IMultiLingualObjectManager>();
//Single Lookup //Single Lookup
_book = GetTestBook("en", "zh-Hans"); _book = GetTestBook("en", "zh-Hans");
//Bulk lookup //Bulk lookup
_books = new List<MultiLingualBook> _books = new List<MultiLingualBook>
{ {
//has no translations //has no translations
@ -45,14 +46,14 @@ public class MultiLingualObjectManager_Tests : AbpIntegratedTest<AbpMultiLingual
//arabic + english + chineese //arabic + english + chineese
GetTestBook("en", "ar", "zh-Hans") GetTestBook("en", "ar", "zh-Hans")
}; };
_mapperAccessor = ServiceProvider.GetRequiredService<IMapperAccessor>(); _mapperAccessor = ServiceProvider.GetRequiredService<IMapperAccessor>();
} }
MultiLingualBook GetTestBook(params string[] included) MultiLingualBook GetTestBook(params string[] included)
{ {
var id = Guid.NewGuid(); var id = Guid.NewGuid();
//Single book //Single book
var res = new MultiLingualBook(id, 100); var res = new MultiLingualBook(id, 100);
foreach (var language in included) foreach (var language in included)
{ {
res.Translations.Add(new MultiLingualBookTranslation res.Translations.Add(new MultiLingualBookTranslation
@ -65,45 +66,45 @@ public class MultiLingualObjectManager_Tests : AbpIntegratedTest<AbpMultiLingual
return res; return res;
} }
[Fact] [Fact]
public async Task GetTranslationAsync() public async Task GetTranslationAsync()
{ {
using (CultureHelper.Use("en-us")) using (CultureHelper.Use("en-us"))
{ {
var translation = await _multiLingualObjectManager.GetTranslationAsync<MultiLingualBook, MultiLingualBookTranslation>(_book); var translation = await _multiLingualObjectManager.GetTranslationAsync<MultiLingualBook, MultiLingualBookTranslation>(_book);
translation.ShouldNotBeNull(); translation.ShouldNotBeNull();
translation.Name.ShouldBe(_testTranslations["en"]); translation.Name.ShouldBe(_testTranslations["en"]);
} }
} }
[Fact] [Fact]
public async Task GetTranslationFromListAsync() public async Task GetTranslationFromListAsync()
{ {
using (CultureHelper.Use("en-us")) using (CultureHelper.Use("en-us"))
{ {
var translation = await _multiLingualObjectManager.GetTranslationAsync(_book.Translations); var translation = await _multiLingualObjectManager.GetTranslationAsync(_book.Translations);
translation.ShouldNotBeNull(); translation.ShouldNotBeNull();
translation.Name.ShouldBe(_testTranslations["en"]); translation.Name.ShouldBe(_testTranslations["en"]);
} }
} }
[Fact] [Fact]
public async Task Should_Get_Specified_Language() public async Task Should_Get_Specified_Language()
{ {
using (CultureHelper.Use("zh-Hans")) using (CultureHelper.Use("zh-Hans"))
{ {
var translation = await _multiLingualObjectManager.GetTranslationAsync<MultiLingualBook, MultiLingualBookTranslation>(_book, culture: "en"); var translation = await _multiLingualObjectManager.GetTranslationAsync<MultiLingualBook, MultiLingualBookTranslation>(_book, culture: "en");
translation.ShouldNotBeNull(); translation.ShouldNotBeNull();
translation.Name.ShouldBe(_testTranslations["en"]); translation.Name.ShouldBe(_testTranslations["en"]);
} }
} }
[Fact] [Fact]
public async Task GetBulkTranslationsAsync() public async Task GetBulkTranslationsAsync()
{ {
using (CultureHelper.Use("en-us")) using (CultureHelper.Use("en-us"))
{ {
var translations = await _multiLingualObjectManager.GetBulkTranslationsAsync<MultiLingualBook, MultiLingualBookTranslation>(_books); var translations = await _multiLingualObjectManager.GetBulkTranslationsAsync<MultiLingualBook, MultiLingualBookTranslation>(_books);
foreach (var (entity, translation) in translations) foreach (var (entity, translation) in translations)
{ {
@ -117,26 +118,26 @@ public class MultiLingualObjectManager_Tests : AbpIntegratedTest<AbpMultiLingual
translation.ShouldBeNull(); translation.ShouldBeNull();
} }
} }
} }
} }
[Fact] [Fact]
public async Task GetBulkTranslationsFromListAsync() public async Task GetBulkTranslationsFromListAsync()
{ {
using (CultureHelper.Use("en-us")) using (CultureHelper.Use("en-us"))
{ {
var translations = await _multiLingualObjectManager.GetBulkTranslationsAsync(_books.Select(x => x.Translations)); var translations = await _multiLingualObjectManager.GetBulkTranslationsAsync(_books.Select(x => x.Translations));
foreach (var translation in translations) foreach (var translation in translations)
{ {
translation?.Name.ShouldBe(_testTranslations["en"]); translation?.Name.ShouldBe(_testTranslations["en"]);
} }
} }
} }
[Fact] [Fact]
public async Task TestBulkMapping() public async Task TestBulkMapping()
{ {
using (CultureHelper.Use("en-us")) using (CultureHelper.Use("en-us"))
{ {
var translations = await _multiLingualObjectManager.GetBulkTranslationsAsync<MultiLingualBook, MultiLingualBookTranslation>(_books); var translations = await _multiLingualObjectManager.GetBulkTranslationsAsync<MultiLingualBook, MultiLingualBookTranslation>(_books);
var translationsDict = translations.ToDictionary(x => x.entity.Id, x => x.translation); var translationsDict = translations.ToDictionary(x => x.entity.Id, x => x.translation);
@ -152,5 +153,5 @@ public class MultiLingualObjectManager_Tests : AbpIntegratedTest<AbpMultiLingual
Assert.Equal(og.Translations.FirstOrDefault(x => x.Language == "en")?.Name, m.Name); Assert.Equal(og.Translations.FirstOrDefault(x => x.Language == "en")?.Name, m.Name);
} }
} }
} }
} }

5
modules/docs/app/VoloDocs.Web/Pages/Error.cshtml.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Diagnostics;
@ -48,7 +49,7 @@ namespace VoloDocs.Web.Pages
#region Error Messages #region Error Messages
/*For more ASCII arts http://patorjk.com/software/taag/#p=display&h=0&f=Big&t=400*/ /*For more ASCII arts http://patorjk.com/software/taag/#p=display&h=0&f=Big&t=400*/
private readonly Dictionary<int, string> _errorMessages = new Dictionary<int, string> private readonly FrozenDictionary<int, string> _errorMessages = new Dictionary<int, string>
{ {
{ {
400, @" 400, @"
@ -131,7 +132,7 @@ Ooops! Our server is experiencing a mild case of the hiccups."
Looks like we're having some server issues." Looks like we're having some server issues."
} }
}; }.ToFrozenDictionary();
#endregion #endregion
} }
} }
Loading…
Cancel
Save