diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs index ca0209a620..8ab6756ebe 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs @@ -2,16 +2,15 @@ using Volo.Abp.Localization; using Volo.Abp.Modularity; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AbpAuditLoggingDomainSharedModule : AbpModule { - public class AbpAuditLoggingDomainSharedModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => - { - options.Resources.Add("en"); - }); - } + options.Resources.Add("en"); + }); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs index 5f1967804e..0df63383f9 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs @@ -1,20 +1,19 @@ -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AuditLogActionConsts { - public class AuditLogActionConsts - { - /// - /// Default value: 256 - /// - public static int MaxServiceNameLength { get; set; } = 256; + /// + /// Default value: 256 + /// + public static int MaxServiceNameLength { get; set; } = 256; - /// - /// Default value: 128 - /// - public static int MaxMethodNameLength { get; set; } = 128; + /// + /// Default value: 128 + /// + public static int MaxMethodNameLength { get; set; } = 128; - /// - /// Default value: 2000 - /// - public static int MaxParametersLength { get; set; } = 2000; - } + /// + /// Default value: 2000 + /// + public static int MaxParametersLength { get; set; } = 2000; } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs index 5b2e2dd226..78d27a40d7 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs @@ -1,60 +1,59 @@ -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public static class AuditLogConsts { - public static class AuditLogConsts - { - /// - /// Default value: 96 - /// - public static int MaxApplicationNameLength { get; set; } = 96; - - /// - /// Default value: 64 - /// - public static int MaxClientIpAddressLength { get; set; } = 64; - - /// - /// Default value: 128 - /// - public static int MaxClientNameLength { get; set; } = 128; - - /// - /// Default value: 64 - /// - public static int MaxClientIdLength { get; set; } = 64; - - /// - /// Default value: 64 - /// - public static int MaxCorrelationIdLength { get; set; } = 64; - - /// - /// Default value: 512 - /// - public static int MaxBrowserInfoLength { get; set; } = 512; - - /// - /// Default value: 256 - /// - public static int MaxCommentsLength { get; set; } = 256; - - /// - /// Default value: 256 - /// - public static int MaxUrlLength { get; set; } = 256; - - /// - /// Default value: 16 - /// - public static int MaxHttpMethodLength { get; set; } = 16; - - /// - /// Default value: 256 - /// - public static int MaxUserNameLength { get; set; } = 256; - - /// - /// Default value: 64 - /// - public static int MaxTenantNameLength { get; set; } = 64; - } + /// + /// Default value: 96 + /// + public static int MaxApplicationNameLength { get; set; } = 96; + + /// + /// Default value: 64 + /// + public static int MaxClientIpAddressLength { get; set; } = 64; + + /// + /// Default value: 128 + /// + public static int MaxClientNameLength { get; set; } = 128; + + /// + /// Default value: 64 + /// + public static int MaxClientIdLength { get; set; } = 64; + + /// + /// Default value: 64 + /// + public static int MaxCorrelationIdLength { get; set; } = 64; + + /// + /// Default value: 512 + /// + public static int MaxBrowserInfoLength { get; set; } = 512; + + /// + /// Default value: 256 + /// + public static int MaxCommentsLength { get; set; } = 256; + + /// + /// Default value: 256 + /// + public static int MaxUrlLength { get; set; } = 256; + + /// + /// Default value: 16 + /// + public static int MaxHttpMethodLength { get; set; } = 16; + + /// + /// Default value: 256 + /// + public static int MaxUserNameLength { get; set; } = 256; + + /// + /// Default value: 64 + /// + public static int MaxTenantNameLength { get; set; } = 64; } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityChangeConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityChangeConsts.cs index b7f88db3e2..9a01c44454 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityChangeConsts.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityChangeConsts.cs @@ -1,15 +1,14 @@ -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class EntityChangeConsts { - public class EntityChangeConsts - { - /// - /// Default value: 128 - /// - public static int MaxEntityTypeFullNameLength { get; set; } = 128; + /// + /// Default value: 128 + /// + public static int MaxEntityTypeFullNameLength { get; set; } = 128; - /// - /// Default value: 128 - /// - public static int MaxEntityIdLength { get; set; } = 128; - } + /// + /// Default value: 128 + /// + public static int MaxEntityIdLength { get; set; } = 128; } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityPropertyChangeConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityPropertyChangeConsts.cs index 8d592e06aa..86f1b0588a 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityPropertyChangeConsts.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityPropertyChangeConsts.cs @@ -1,25 +1,24 @@ -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class EntityPropertyChangeConsts { - public class EntityPropertyChangeConsts - { - /// - /// Default value: 512 - /// - public static int MaxNewValueLength { get; set; } = 512; + /// + /// Default value: 512 + /// + public static int MaxNewValueLength { get; set; } = 512; - /// - /// Default value: 512 - /// - public static int MaxOriginalValueLength { get; set; } = 512; + /// + /// Default value: 512 + /// + public static int MaxOriginalValueLength { get; set; } = 512; - /// - /// Default value: 128 - /// - public static int MaxPropertyNameLength { get; set; } = 128; + /// + /// Default value: 128 + /// + public static int MaxPropertyNameLength { get; set; } = 128; - /// - /// Default value: 64 - /// - public static int MaxPropertyTypeFullNameLength { get; set; } = 64; - } + /// + /// Default value: 64 + /// + public static int MaxPropertyTypeFullNameLength { get; set; } = 64; } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/Localization/AuditLoggingResource.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/Localization/AuditLoggingResource.cs index ed9bc7051e..e6c1ff20e4 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/Localization/AuditLoggingResource.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/Localization/AuditLoggingResource.cs @@ -1,9 +1,8 @@ using Volo.Abp.Localization; -namespace Volo.Abp.AuditLogging.Localization +namespace Volo.Abp.AuditLogging.Localization; + +[LocalizationResourceName("AbpAuditLogging")] +public class AuditLoggingResource { - [LocalizationResourceName("AbpAuditLogging")] - public class AuditLoggingResource - { - } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs index 24c54e4b55..c0a62caf25 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs @@ -1,35 +1,34 @@ using System; using Volo.Abp.ObjectExtending.Modularity; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending; + +public class AuditLoggingModuleExtensionConfiguration : ModuleExtensionConfiguration { - public class AuditLoggingModuleExtensionConfiguration : ModuleExtensionConfiguration + public AuditLoggingModuleExtensionConfiguration ConfigureAuditLog( + Action configureAction) { - public AuditLoggingModuleExtensionConfiguration ConfigureAuditLog( - Action configureAction) - { - return this.ConfigureEntity( - AuditLoggingModuleExtensionConsts.EntityNames.AuditLog, - configureAction - ); - } + return this.ConfigureEntity( + AuditLoggingModuleExtensionConsts.EntityNames.AuditLog, + configureAction + ); + } - public AuditLoggingModuleExtensionConfiguration ConfigureAuditLogAction( - Action configureAction) - { - return this.ConfigureEntity( - AuditLoggingModuleExtensionConsts.EntityNames.AuditLogAction, - configureAction - ); - } + public AuditLoggingModuleExtensionConfiguration ConfigureAuditLogAction( + Action configureAction) + { + return this.ConfigureEntity( + AuditLoggingModuleExtensionConsts.EntityNames.AuditLogAction, + configureAction + ); + } - public AuditLoggingModuleExtensionConfiguration ConfigureEntityChange( - Action configureAction) - { - return this.ConfigureEntity( - AuditLoggingModuleExtensionConsts.EntityNames.EntityChange, - configureAction - ); - } + public AuditLoggingModuleExtensionConfiguration ConfigureEntityChange( + Action configureAction) + { + return this.ConfigureEntity( + AuditLoggingModuleExtensionConsts.EntityNames.EntityChange, + configureAction + ); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs index 3de08783e1..3dd062f1ac 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs @@ -1,18 +1,17 @@ using System; using Volo.Abp.ObjectExtending.Modularity; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending; + +public static class AuditLoggingModuleExtensionConfigurationDictionaryExtensions { - public static class AuditLoggingModuleExtensionConfigurationDictionaryExtensions + public static ModuleExtensionConfigurationDictionary ConfigureAuditLogging( + this ModuleExtensionConfigurationDictionary modules, + Action configureAction) { - public static ModuleExtensionConfigurationDictionary ConfigureAuditLogging( - this ModuleExtensionConfigurationDictionary modules, - Action configureAction) - { - return modules.ConfigureModule( - AuditLoggingModuleExtensionConsts.ModuleName, - configureAction - ); - } + return modules.ConfigureModule( + AuditLoggingModuleExtensionConsts.ModuleName, + configureAction + ); } -} \ No newline at end of file +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs index ec8be4914b..411a3c6034 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs @@ -1,16 +1,15 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending; + +public static class AuditLoggingModuleExtensionConsts { - public static class AuditLoggingModuleExtensionConsts + public const string ModuleName = "AuditLogging"; + + public static class EntityNames { - public const string ModuleName = "AuditLogging"; + public const string AuditLog = "AuditLog"; + + public const string AuditLogAction = "AuditLogAction"; - public static class EntityNames - { - public const string AuditLog = "AuditLog"; - - public const string AuditLogAction = "AuditLogAction"; - - public const string EntityChange = "EntityChange"; - } + public const string EntityChange = "EntityChange"; } -} \ No newline at end of file +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDbProperties.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDbProperties.cs index d58a9b3566..385358587d 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDbProperties.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDbProperties.cs @@ -1,13 +1,12 @@ using Volo.Abp.Data; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public static class AbpAuditLoggingDbProperties { - public static class AbpAuditLoggingDbProperties - { - public static string DbTablePrefix { get; set; } = AbpCommonDbProperties.DbTablePrefix; + public static string DbTablePrefix { get; set; } = AbpCommonDbProperties.DbTablePrefix; - public static string DbSchema { get; set; } = AbpCommonDbProperties.DbSchema; + public static string DbSchema { get; set; } = AbpCommonDbProperties.DbSchema; - public const string ConnectionStringName = "AbpAuditLogging"; - } + public const string ConnectionStringName = "AbpAuditLogging"; } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs index c61fb2c855..1d72aed141 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs @@ -7,39 +7,38 @@ using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.Threading; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[DependsOn(typeof(AbpAuditingModule))] +[DependsOn(typeof(AbpDddDomainModule))] +[DependsOn(typeof(AbpAuditLoggingDomainSharedModule))] +[DependsOn(typeof(AbpExceptionHandlingModule))] +[DependsOn(typeof(AbpJsonModule))] +public class AbpAuditLoggingDomainModule : AbpModule { - [DependsOn(typeof(AbpAuditingModule))] - [DependsOn(typeof(AbpDddDomainModule))] - [DependsOn(typeof(AbpAuditLoggingDomainSharedModule))] - [DependsOn(typeof(AbpExceptionHandlingModule))] - [DependsOn(typeof(AbpJsonModule))] - public class AbpAuditLoggingDomainModule : AbpModule - { - private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); + private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); - public override void PostConfigureServices(ServiceConfigurationContext context) + public override void PostConfigureServices(ServiceConfigurationContext context) + { + OneTimeRunner.Run(() => { - OneTimeRunner.Run(() => - { - ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( - AuditLoggingModuleExtensionConsts.ModuleName, - AuditLoggingModuleExtensionConsts.EntityNames.AuditLog, - typeof(AuditLog) - ); + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + AuditLoggingModuleExtensionConsts.ModuleName, + AuditLoggingModuleExtensionConsts.EntityNames.AuditLog, + typeof(AuditLog) + ); - ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( - AuditLoggingModuleExtensionConsts.ModuleName, - AuditLoggingModuleExtensionConsts.EntityNames.AuditLogAction, - typeof(AuditLogAction) - ); + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + AuditLoggingModuleExtensionConsts.ModuleName, + AuditLoggingModuleExtensionConsts.EntityNames.AuditLogAction, + typeof(AuditLogAction) + ); - ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( - AuditLoggingModuleExtensionConsts.ModuleName, - AuditLoggingModuleExtensionConsts.EntityNames.EntityChange, - typeof(EntityChange) - ); - }); - } + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + AuditLoggingModuleExtensionConsts.ModuleName, + AuditLoggingModuleExtensionConsts.EntityNames.EntityChange, + typeof(EntityChange) + ); + }); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs index 26b8b6650d..ac7df6a47f 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs @@ -7,107 +7,106 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.AuditLogging -{ - [DisableAuditing] - public class AuditLog : AggregateRoot, IMultiTenant - { - public virtual string ApplicationName { get; set; } +namespace Volo.Abp.AuditLogging; - public virtual Guid? UserId { get; protected set; } +[DisableAuditing] +public class AuditLog : AggregateRoot, IMultiTenant +{ + public virtual string ApplicationName { get; set; } - public virtual string UserName { get; protected set; } + public virtual Guid? UserId { get; protected set; } - public virtual Guid? TenantId { get; protected set; } + public virtual string UserName { get; protected set; } - public virtual string TenantName { get; protected set; } + public virtual Guid? TenantId { get; protected set; } - public virtual Guid? ImpersonatorUserId { get; protected set; } + public virtual string TenantName { get; protected set; } - public virtual Guid? ImpersonatorTenantId { get; protected set; } + public virtual Guid? ImpersonatorUserId { get; protected set; } - public virtual DateTime ExecutionTime { get; protected set; } + public virtual Guid? ImpersonatorTenantId { get; protected set; } - public virtual int ExecutionDuration { get; protected set; } + public virtual DateTime ExecutionTime { get; protected set; } - public virtual string ClientIpAddress { get; protected set; } + public virtual int ExecutionDuration { get; protected set; } - public virtual string ClientName { get; protected set; } + public virtual string ClientIpAddress { get; protected set; } - public virtual string ClientId { get; set; } + public virtual string ClientName { get; protected set; } - public virtual string CorrelationId { get; set; } + public virtual string ClientId { get; set; } - public virtual string BrowserInfo { get; protected set; } + public virtual string CorrelationId { get; set; } - public virtual string HttpMethod { get; protected set; } + public virtual string BrowserInfo { get; protected set; } - public virtual string Url { get; protected set; } + public virtual string HttpMethod { get; protected set; } - public virtual string Exceptions { get; protected set; } + public virtual string Url { get; protected set; } - public virtual string Comments { get; protected set; } + public virtual string Exceptions { get; protected set; } - public virtual int? HttpStatusCode { get; set; } + public virtual string Comments { get; protected set; } - public virtual ICollection EntityChanges { get; protected set; } + public virtual int? HttpStatusCode { get; set; } - public virtual ICollection Actions { get; protected set; } + public virtual ICollection EntityChanges { get; protected set; } - protected AuditLog() - { + public virtual ICollection Actions { get; protected set; } - } + protected AuditLog() + { - public AuditLog( - Guid id, - string applicationName, - Guid? tenantId, - string tenantName, - Guid? userId, - string userName, - DateTime executionTime, - int executionDuration, - string clientIpAddress, - string clientName, - string clientId, - string correlationId, - string browserInfo, - string httpMethod, - string url, - int? httpStatusCode, - Guid? impersonatorUserId, - Guid? impersonatorTenantId, - ExtraPropertyDictionary extraPropertyDictionary, - List entityChanges, - List actions, - string exceptions, - string comments) - : base(id) - { - ApplicationName = applicationName.Truncate(AuditLogConsts.MaxApplicationNameLength); - TenantId = tenantId; - TenantName = tenantName.Truncate(AuditLogConsts.MaxTenantNameLength); - UserId = userId; - UserName = userName.Truncate(AuditLogConsts.MaxUserNameLength); - ExecutionTime = executionTime; - ExecutionDuration = executionDuration; - ClientIpAddress = clientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength); - ClientName = clientName.Truncate(AuditLogConsts.MaxClientNameLength); - ClientId = clientId.Truncate(AuditLogConsts.MaxClientIdLength); - CorrelationId = correlationId.Truncate(AuditLogConsts.MaxCorrelationIdLength); - BrowserInfo = browserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength); - HttpMethod = httpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength); - Url = url.Truncate(AuditLogConsts.MaxUrlLength); - HttpStatusCode = httpStatusCode; - ImpersonatorUserId = impersonatorUserId; - ImpersonatorTenantId = impersonatorTenantId; + } - ExtraProperties = extraPropertyDictionary; - EntityChanges = entityChanges; - Actions = actions; - Exceptions = exceptions; - Comments = comments.Truncate(AuditLogConsts.MaxCommentsLength); - } + public AuditLog( + Guid id, + string applicationName, + Guid? tenantId, + string tenantName, + Guid? userId, + string userName, + DateTime executionTime, + int executionDuration, + string clientIpAddress, + string clientName, + string clientId, + string correlationId, + string browserInfo, + string httpMethod, + string url, + int? httpStatusCode, + Guid? impersonatorUserId, + Guid? impersonatorTenantId, + ExtraPropertyDictionary extraPropertyDictionary, + List entityChanges, + List actions, + string exceptions, + string comments) + : base(id) + { + ApplicationName = applicationName.Truncate(AuditLogConsts.MaxApplicationNameLength); + TenantId = tenantId; + TenantName = tenantName.Truncate(AuditLogConsts.MaxTenantNameLength); + UserId = userId; + UserName = userName.Truncate(AuditLogConsts.MaxUserNameLength); + ExecutionTime = executionTime; + ExecutionDuration = executionDuration; + ClientIpAddress = clientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength); + ClientName = clientName.Truncate(AuditLogConsts.MaxClientNameLength); + ClientId = clientId.Truncate(AuditLogConsts.MaxClientIdLength); + CorrelationId = correlationId.Truncate(AuditLogConsts.MaxCorrelationIdLength); + BrowserInfo = browserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength); + HttpMethod = httpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength); + Url = url.Truncate(AuditLogConsts.MaxUrlLength); + HttpStatusCode = httpStatusCode; + ImpersonatorUserId = impersonatorUserId; + ImpersonatorTenantId = impersonatorTenantId; + + ExtraProperties = extraPropertyDictionary; + EntityChanges = entityChanges; + Actions = actions; + Exceptions = exceptions; + Comments = comments.Truncate(AuditLogConsts.MaxCommentsLength); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs index 7f6db9af5f..0e6f52b9e9 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs @@ -4,43 +4,42 @@ using Volo.Abp.Data; using Volo.Abp.Domain.Entities; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[DisableAuditing] +public class AuditLogAction : Entity, IMultiTenant, IHasExtraProperties { - [DisableAuditing] - public class AuditLogAction : Entity, IMultiTenant, IHasExtraProperties - { - public virtual Guid? TenantId { get; protected set; } + public virtual Guid? TenantId { get; protected set; } - public virtual Guid AuditLogId { get; protected set; } + public virtual Guid AuditLogId { get; protected set; } - public virtual string ServiceName { get; protected set; } + public virtual string ServiceName { get; protected set; } - public virtual string MethodName { get; protected set; } + public virtual string MethodName { get; protected set; } - public virtual string Parameters { get; protected set; } + public virtual string Parameters { get; protected set; } - public virtual DateTime ExecutionTime { get; protected set; } + public virtual DateTime ExecutionTime { get; protected set; } - public virtual int ExecutionDuration { get; protected set; } + public virtual int ExecutionDuration { get; protected set; } - public virtual ExtraPropertyDictionary ExtraProperties { get; protected set; } + public virtual ExtraPropertyDictionary ExtraProperties { get; protected set; } - protected AuditLogAction() - { - } + protected AuditLogAction() + { + } - public AuditLogAction(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo, Guid? tenantId = null) - { + public AuditLogAction(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo, Guid? tenantId = null) + { - Id = id; - TenantId = tenantId; - AuditLogId = auditLogId; - ExecutionTime = actionInfo.ExecutionTime; - ExecutionDuration = actionInfo.ExecutionDuration; - ExtraProperties = new ExtraPropertyDictionary(actionInfo.ExtraProperties); - ServiceName = actionInfo.ServiceName.TruncateFromBeginning(AuditLogActionConsts.MaxServiceNameLength); - MethodName = actionInfo.MethodName.TruncateFromBeginning(AuditLogActionConsts.MaxMethodNameLength); - Parameters = actionInfo.Parameters.Length > AuditLogActionConsts.MaxParametersLength ? "" : actionInfo.Parameters; - } + Id = id; + TenantId = tenantId; + AuditLogId = auditLogId; + ExecutionTime = actionInfo.ExecutionTime; + ExecutionDuration = actionInfo.ExecutionDuration; + ExtraProperties = new ExtraPropertyDictionary(actionInfo.ExtraProperties); + ServiceName = actionInfo.ServiceName.TruncateFromBeginning(AuditLogActionConsts.MaxServiceNameLength); + MethodName = actionInfo.MethodName.TruncateFromBeginning(AuditLogActionConsts.MaxMethodNameLength); + Parameters = actionInfo.Parameters.Length > AuditLogActionConsts.MaxParametersLength ? "" : actionInfo.Parameters; } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogInfoToAuditLogConverter.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogInfoToAuditLogConverter.cs index f27497324e..20f5a3629f 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogInfoToAuditLogConverter.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogInfoToAuditLogConverter.cs @@ -10,84 +10,83 @@ using Volo.Abp.Guids; using Volo.Abp.Http; using Volo.Abp.Json; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AuditLogInfoToAuditLogConverter : IAuditLogInfoToAuditLogConverter, ITransientDependency { - public class AuditLogInfoToAuditLogConverter : IAuditLogInfoToAuditLogConverter, ITransientDependency + protected IGuidGenerator GuidGenerator { get; } + protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; } + protected IJsonSerializer JsonSerializer { get; } + + public AuditLogInfoToAuditLogConverter(IGuidGenerator guidGenerator, IExceptionToErrorInfoConverter exceptionToErrorInfoConverter, IJsonSerializer jsonSerializer) { - protected IGuidGenerator GuidGenerator { get; } - protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; } - protected IJsonSerializer JsonSerializer { get; } + GuidGenerator = guidGenerator; + ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter; + JsonSerializer = jsonSerializer; + } - public AuditLogInfoToAuditLogConverter(IGuidGenerator guidGenerator, IExceptionToErrorInfoConverter exceptionToErrorInfoConverter, IJsonSerializer jsonSerializer) - { - GuidGenerator = guidGenerator; - ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter; - JsonSerializer = jsonSerializer; - } + public virtual Task ConvertAsync(AuditLogInfo auditLogInfo) + { + var auditLogId = GuidGenerator.Create(); - public virtual Task ConvertAsync(AuditLogInfo auditLogInfo) + var extraProperties = new ExtraPropertyDictionary(); + if (auditLogInfo.ExtraProperties != null) { - var auditLogId = GuidGenerator.Create(); - - var extraProperties = new ExtraPropertyDictionary(); - if (auditLogInfo.ExtraProperties != null) + foreach (var pair in auditLogInfo.ExtraProperties) { - foreach (var pair in auditLogInfo.ExtraProperties) - { - extraProperties.Add(pair.Key, pair.Value); - } + extraProperties.Add(pair.Key, pair.Value); } + } - var entityChanges = auditLogInfo - .EntityChanges? - .Select(entityChangeInfo => new EntityChange(GuidGenerator, auditLogId, entityChangeInfo, tenantId: auditLogInfo.TenantId)) - .ToList() - ?? new List(); + var entityChanges = auditLogInfo + .EntityChanges? + .Select(entityChangeInfo => new EntityChange(GuidGenerator, auditLogId, entityChangeInfo, tenantId: auditLogInfo.TenantId)) + .ToList() + ?? new List(); - var actions = auditLogInfo - .Actions? - .Select(auditLogActionInfo => new AuditLogAction(GuidGenerator.Create(), auditLogId, auditLogActionInfo, tenantId: auditLogInfo.TenantId)) - .ToList() - ?? new List(); + var actions = auditLogInfo + .Actions? + .Select(auditLogActionInfo => new AuditLogAction(GuidGenerator.Create(), auditLogId, auditLogActionInfo, tenantId: auditLogInfo.TenantId)) + .ToList() + ?? new List(); - var remoteServiceErrorInfos = auditLogInfo.Exceptions?.Select(exception => ExceptionToErrorInfoConverter.Convert(exception, true)) - ?? new List(); + var remoteServiceErrorInfos = auditLogInfo.Exceptions?.Select(exception => ExceptionToErrorInfoConverter.Convert(exception, true)) + ?? new List(); - var exceptions = remoteServiceErrorInfos.Any() - ? JsonSerializer.Serialize(remoteServiceErrorInfos, indented: true) - : null; + var exceptions = remoteServiceErrorInfos.Any() + ? JsonSerializer.Serialize(remoteServiceErrorInfos, indented: true) + : null; - var comments = auditLogInfo - .Comments? - .JoinAsString(Environment.NewLine); + var comments = auditLogInfo + .Comments? + .JoinAsString(Environment.NewLine); - var auditLog = new AuditLog( - auditLogId, - auditLogInfo.ApplicationName, - auditLogInfo.TenantId, - auditLogInfo.TenantName, - auditLogInfo.UserId, - auditLogInfo.UserName, - auditLogInfo.ExecutionTime, - auditLogInfo.ExecutionDuration, - auditLogInfo.ClientIpAddress, - auditLogInfo.ClientName, - auditLogInfo.ClientId, - auditLogInfo.CorrelationId, - auditLogInfo.BrowserInfo, - auditLogInfo.HttpMethod, - auditLogInfo.Url, - auditLogInfo.HttpStatusCode, - auditLogInfo.ImpersonatorUserId, - auditLogInfo.ImpersonatorTenantId, - extraProperties, - entityChanges, - actions, - exceptions, - comments - ); + var auditLog = new AuditLog( + auditLogId, + auditLogInfo.ApplicationName, + auditLogInfo.TenantId, + auditLogInfo.TenantName, + auditLogInfo.UserId, + auditLogInfo.UserName, + auditLogInfo.ExecutionTime, + auditLogInfo.ExecutionDuration, + auditLogInfo.ClientIpAddress, + auditLogInfo.ClientName, + auditLogInfo.ClientId, + auditLogInfo.CorrelationId, + auditLogInfo.BrowserInfo, + auditLogInfo.HttpMethod, + auditLogInfo.Url, + auditLogInfo.HttpStatusCode, + auditLogInfo.ImpersonatorUserId, + auditLogInfo.ImpersonatorTenantId, + extraProperties, + entityChanges, + actions, + exceptions, + comments + ); - return Task.FromResult(auditLog); - } + return Task.FromResult(auditLog); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs index ccc76a4bad..9a81655900 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs @@ -7,55 +7,54 @@ using Volo.Abp.Auditing; using Volo.Abp.DependencyInjection; using Volo.Abp.Uow; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AuditingStore : IAuditingStore, ITransientDependency { - public class AuditingStore : IAuditingStore, ITransientDependency + public ILogger Logger { get; set; } + protected IAuditLogRepository AuditLogRepository { get; } + protected IUnitOfWorkManager UnitOfWorkManager { get; } + protected AbpAuditingOptions Options { get; } + protected IAuditLogInfoToAuditLogConverter Converter { get; } + public AuditingStore( + IAuditLogRepository auditLogRepository, + IUnitOfWorkManager unitOfWorkManager, + IOptions options, + IAuditLogInfoToAuditLogConverter converter) { - public ILogger Logger { get; set; } - protected IAuditLogRepository AuditLogRepository { get; } - protected IUnitOfWorkManager UnitOfWorkManager { get; } - protected AbpAuditingOptions Options { get; } - protected IAuditLogInfoToAuditLogConverter Converter { get; } - public AuditingStore( - IAuditLogRepository auditLogRepository, - IUnitOfWorkManager unitOfWorkManager, - IOptions options, - IAuditLogInfoToAuditLogConverter converter) - { - AuditLogRepository = auditLogRepository; - UnitOfWorkManager = unitOfWorkManager; - Converter = converter; - Options = options.Value; + AuditLogRepository = auditLogRepository; + UnitOfWorkManager = unitOfWorkManager; + Converter = converter; + Options = options.Value; - Logger = NullLogger.Instance; - } + Logger = NullLogger.Instance; + } - public virtual async Task SaveAsync(AuditLogInfo auditInfo) + public virtual async Task SaveAsync(AuditLogInfo auditInfo) + { + if (!Options.HideErrors) { - if (!Options.HideErrors) - { - await SaveLogAsync(auditInfo); - return; - } + await SaveLogAsync(auditInfo); + return; + } - try - { - await SaveLogAsync(auditInfo); - } - catch (Exception ex) - { - Logger.LogWarning("Could not save the audit log object: " + Environment.NewLine + auditInfo.ToString()); - Logger.LogException(ex, LogLevel.Error); - } + try + { + await SaveLogAsync(auditInfo); + } + catch (Exception ex) + { + Logger.LogWarning("Could not save the audit log object: " + Environment.NewLine + auditInfo.ToString()); + Logger.LogException(ex, LogLevel.Error); } + } - protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo) + protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo) + { + using (var uow = UnitOfWorkManager.Begin(true)) { - using (var uow = UnitOfWorkManager.Begin(true)) - { - await AuditLogRepository.InsertAsync(await Converter.ConvertAsync(auditInfo)); - await uow.CompleteAsync(); - } + await AuditLogRepository.InsertAsync(await Converter.ConvertAsync(auditInfo)); + await uow.CompleteAsync(); } } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs index 6bb86b7980..05de8f7181 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs @@ -7,61 +7,60 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[DisableAuditing] +public class EntityChange : Entity, IMultiTenant, IHasExtraProperties { - [DisableAuditing] - public class EntityChange : Entity, IMultiTenant, IHasExtraProperties - { - public virtual Guid AuditLogId { get; protected set; } + public virtual Guid AuditLogId { get; protected set; } - public virtual Guid? TenantId { get; protected set; } + public virtual Guid? TenantId { get; protected set; } - public virtual DateTime ChangeTime { get; protected set; } + public virtual DateTime ChangeTime { get; protected set; } - public virtual EntityChangeType ChangeType { get; protected set; } + public virtual EntityChangeType ChangeType { get; protected set; } - public virtual Guid? EntityTenantId { get; protected set; } + public virtual Guid? EntityTenantId { get; protected set; } - public virtual string EntityId { get; protected set; } + public virtual string EntityId { get; protected set; } - public virtual string EntityTypeFullName { get; protected set; } + public virtual string EntityTypeFullName { get; protected set; } - public virtual ICollection PropertyChanges { get; protected set; } + public virtual ICollection PropertyChanges { get; protected set; } - public virtual ExtraPropertyDictionary ExtraProperties { get; protected set; } + public virtual ExtraPropertyDictionary ExtraProperties { get; protected set; } - protected EntityChange() - { - ExtraProperties = new ExtraPropertyDictionary(); - } + protected EntityChange() + { + ExtraProperties = new ExtraPropertyDictionary(); + } - public EntityChange( - IGuidGenerator guidGenerator, - Guid auditLogId, - EntityChangeInfo entityChangeInfo, - Guid? tenantId = null) - { - Id = guidGenerator.Create(); - AuditLogId = auditLogId; - TenantId = tenantId; - ChangeTime = entityChangeInfo.ChangeTime; - ChangeType = entityChangeInfo.ChangeType; - EntityId = entityChangeInfo.EntityId.Truncate(EntityChangeConsts.MaxEntityTypeFullNameLength); - EntityTypeFullName = entityChangeInfo.EntityTypeFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength); + public EntityChange( + IGuidGenerator guidGenerator, + Guid auditLogId, + EntityChangeInfo entityChangeInfo, + Guid? tenantId = null) + { + Id = guidGenerator.Create(); + AuditLogId = auditLogId; + TenantId = tenantId; + ChangeTime = entityChangeInfo.ChangeTime; + ChangeType = entityChangeInfo.ChangeType; + EntityId = entityChangeInfo.EntityId.Truncate(EntityChangeConsts.MaxEntityTypeFullNameLength); + EntityTypeFullName = entityChangeInfo.EntityTypeFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength); - PropertyChanges = entityChangeInfo - .PropertyChanges? - .Select(p => new EntityPropertyChange(guidGenerator, Id, p, tenantId)) - .ToList() - ?? new List(); + PropertyChanges = entityChangeInfo + .PropertyChanges? + .Select(p => new EntityPropertyChange(guidGenerator, Id, p, tenantId)) + .ToList() + ?? new List(); - ExtraProperties = new ExtraPropertyDictionary(); - if (entityChangeInfo.ExtraProperties != null) + ExtraProperties = new ExtraPropertyDictionary(); + if (entityChangeInfo.ExtraProperties != null) + { + foreach (var pair in entityChangeInfo.ExtraProperties) { - foreach (var pair in entityChangeInfo.ExtraProperties) - { - ExtraProperties.Add(pair.Key, pair.Value); - } + ExtraProperties.Add(pair.Key, pair.Value); } } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChangeWithUsername.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChangeWithUsername.cs index 8f59b2900e..407533c783 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChangeWithUsername.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChangeWithUsername.cs @@ -1,9 +1,8 @@ -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class EntityChangeWithUsername { - public class EntityChangeWithUsername - { - public EntityChange EntityChange { get; set; } - - public string UserName { get; set; } - } -} \ No newline at end of file + public EntityChange EntityChange { get; set; } + + public string UserName { get; set; } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs index 2d60270e20..d68b06e936 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs @@ -4,41 +4,40 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[DisableAuditing] +public class EntityPropertyChange : Entity, IMultiTenant { - [DisableAuditing] - public class EntityPropertyChange : Entity, IMultiTenant - { - public virtual Guid? TenantId { get; protected set; } + public virtual Guid? TenantId { get; protected set; } - public virtual Guid EntityChangeId { get; protected set; } + public virtual Guid EntityChangeId { get; protected set; } - public virtual string NewValue { get; protected set; } + public virtual string NewValue { get; protected set; } - public virtual string OriginalValue { get; protected set; } + public virtual string OriginalValue { get; protected set; } - public virtual string PropertyName { get; protected set; } + public virtual string PropertyName { get; protected set; } - public virtual string PropertyTypeFullName { get; protected set; } + public virtual string PropertyTypeFullName { get; protected set; } - protected EntityPropertyChange() - { + protected EntityPropertyChange() + { - } + } - public EntityPropertyChange( - IGuidGenerator guidGenerator, - Guid entityChangeId, - EntityPropertyChangeInfo entityChangeInfo, - Guid? tenantId = null) - { - Id = guidGenerator.Create(); - TenantId = tenantId; - EntityChangeId = entityChangeId; - NewValue = entityChangeInfo.NewValue.Truncate(EntityPropertyChangeConsts.MaxNewValueLength); - OriginalValue = entityChangeInfo.OriginalValue.Truncate(EntityPropertyChangeConsts.MaxOriginalValueLength); - PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength); - PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength); - } + public EntityPropertyChange( + IGuidGenerator guidGenerator, + Guid entityChangeId, + EntityPropertyChangeInfo entityChangeInfo, + Guid? tenantId = null) + { + Id = guidGenerator.Create(); + TenantId = tenantId; + EntityChangeId = entityChangeId; + NewValue = entityChangeInfo.NewValue.Truncate(EntityPropertyChangeConsts.MaxNewValueLength); + OriginalValue = entityChangeInfo.OriginalValue.Truncate(EntityPropertyChangeConsts.MaxOriginalValueLength); + PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength); + PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength); } -} \ No newline at end of file +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogInfoToAuditLogConverter.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogInfoToAuditLogConverter.cs index faba811d4f..76ee4de1d2 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogInfoToAuditLogConverter.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogInfoToAuditLogConverter.cs @@ -1,10 +1,9 @@ using System.Threading.Tasks; using Volo.Abp.Auditing; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public interface IAuditLogInfoToAuditLogConverter { - public interface IAuditLogInfoToAuditLogConverter - { - Task ConvertAsync(AuditLogInfo auditLogInfo); - } + Task ConvertAsync(AuditLogInfo auditLogInfo); } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs index 7f24616280..e6dc042989 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs @@ -6,77 +6,76 @@ using System.Threading.Tasks; using Volo.Abp.Auditing; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public interface IAuditLogRepository : IRepository { - public interface IAuditLogRepository : IRepository - { - Task> GetListAsync( - string sorting = null, - int maxResultCount = 50, - int skipCount = 0, - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxExecutionDuration = null, - int? minExecutionDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - bool includeDetails = false, - CancellationToken cancellationToken = default); + Task> GetListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = false, + CancellationToken cancellationToken = default); - Task GetCountAsync( - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxExecutionDuration = null, - int? minExecutionDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - CancellationToken cancellationToken = default); + Task GetCountAsync( + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + CancellationToken cancellationToken = default); - Task> GetAverageExecutionDurationPerDayAsync( - DateTime startDate, - DateTime endDate, - CancellationToken cancellationToken = default); + Task> GetAverageExecutionDurationPerDayAsync( + DateTime startDate, + DateTime endDate, + CancellationToken cancellationToken = default); - Task GetEntityChange(Guid entityChangeId, CancellationToken cancellationToken = default); + Task GetEntityChange(Guid entityChangeId, CancellationToken cancellationToken = default); - Task> GetEntityChangeListAsync( - string sorting = null, - int maxResultCount = 50, - int skipCount = 0, - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - bool includeDetails = false, - CancellationToken cancellationToken = default); + Task> GetEntityChangeListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + bool includeDetails = false, + CancellationToken cancellationToken = default); - Task GetEntityChangeCountAsync( - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - CancellationToken cancellationToken = default); + Task GetEntityChangeCountAsync( + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + CancellationToken cancellationToken = default); - Task GetEntityChangeWithUsernameAsync(Guid entityChangeId, CancellationToken cancellationToken = default); + Task GetEntityChangeWithUsernameAsync(Guid entityChangeId, CancellationToken cancellationToken = default); - Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName, CancellationToken cancellationToken = default); - } + Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName, CancellationToken cancellationToken = default); } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs index 6dc4bfadb8..95e9363024 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs @@ -1,34 +1,33 @@ using System.Linq; using Microsoft.EntityFrameworkCore; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public static class AbpAuditLoggingEfCoreQueryableExtensions { - public static class AbpAuditLoggingEfCoreQueryableExtensions + public static IQueryable IncludeDetails( + this IQueryable queryable, + bool include = true) { - public static IQueryable IncludeDetails( - this IQueryable queryable, - bool include = true) + if (!include) { - if (!include) - { - return queryable; - } - - return queryable - .Include(x => x.Actions) - .Include(x => x.EntityChanges).ThenInclude(ec=>ec.PropertyChanges); + return queryable; } - public static IQueryable IncludeDetails( - this IQueryable queryable, - bool include = true) - { - if (!include) - { - return queryable; - } + return queryable + .Include(x => x.Actions) + .Include(x => x.EntityChanges).ThenInclude(ec => ec.PropertyChanges); + } - return queryable.Include(x => x.PropertyChanges); + public static IQueryable IncludeDetails( + this IQueryable queryable, + bool include = true) + { + if (!include) + { + return queryable; } + + return queryable.Include(x => x.PropertyChanges); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs index 880f6b996a..b0e4eee5ba 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs @@ -2,24 +2,23 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +[ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] +public class AbpAuditLoggingDbContext : AbpDbContext, IAuditLoggingDbContext { - [ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] - public class AbpAuditLoggingDbContext : AbpDbContext, IAuditLoggingDbContext - { - public DbSet AuditLogs { get; set; } + public DbSet AuditLogs { get; set; } - public AbpAuditLoggingDbContext(DbContextOptions options) - : base(options) - { + public AbpAuditLoggingDbContext(DbContextOptions options) + : base(options) + { - } + } - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); - builder.ConfigureAuditLogging(); - } + builder.ConfigureAuditLogging(); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContextModelBuilderExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContextModelBuilderExtensions.cs index 37abf469ef..1c17a374ce 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContextModelBuilderExtensions.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContextModelBuilderExtensions.cs @@ -2,105 +2,104 @@ using Microsoft.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Modeling; -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +public static class AbpAuditLoggingDbContextModelBuilderExtensions { - public static class AbpAuditLoggingDbContextModelBuilderExtensions + public static void ConfigureAuditLogging( + [NotNull] this ModelBuilder builder) { - public static void ConfigureAuditLogging( - [NotNull] this ModelBuilder builder) - { - Check.NotNull(builder, nameof(builder)); - - builder.Entity(b => - { - b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "AuditLogs", AbpAuditLoggingDbProperties.DbSchema); - - b.ConfigureByConvention(); - - b.Property(x => x.ApplicationName).HasMaxLength(AuditLogConsts.MaxApplicationNameLength).HasColumnName(nameof(AuditLog.ApplicationName)); - b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength).HasColumnName(nameof(AuditLog.ClientIpAddress)); - b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength).HasColumnName(nameof(AuditLog.ClientName)); - b.Property(x => x.ClientId).HasMaxLength(AuditLogConsts.MaxClientIdLength).HasColumnName(nameof(AuditLog.ClientId)); - b.Property(x => x.CorrelationId).HasMaxLength(AuditLogConsts.MaxCorrelationIdLength).HasColumnName(nameof(AuditLog.CorrelationId)); - b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength).HasColumnName(nameof(AuditLog.BrowserInfo)); - b.Property(x => x.HttpMethod).HasMaxLength(AuditLogConsts.MaxHttpMethodLength).HasColumnName(nameof(AuditLog.HttpMethod)); - b.Property(x => x.Url).HasMaxLength(AuditLogConsts.MaxUrlLength).HasColumnName(nameof(AuditLog.Url)); - b.Property(x => x.HttpStatusCode).HasColumnName(nameof(AuditLog.HttpStatusCode)); - - b.Property(x => x.Comments).HasMaxLength(AuditLogConsts.MaxCommentsLength).HasColumnName(nameof(AuditLog.Comments)); - b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLog.ExecutionDuration)); - b.Property(x => x.ImpersonatorTenantId).HasColumnName(nameof(AuditLog.ImpersonatorTenantId)); - b.Property(x => x.ImpersonatorUserId).HasColumnName(nameof(AuditLog.ImpersonatorUserId)); - b.Property(x => x.UserId).HasColumnName(nameof(AuditLog.UserId)); - b.Property(x => x.UserName).HasMaxLength(AuditLogConsts.MaxUserNameLength).HasColumnName(nameof(AuditLog.UserName)); - b.Property(x => x.TenantId).HasColumnName(nameof(AuditLog.TenantId)); - - b.HasMany(a => a.Actions).WithOne().HasForeignKey(x => x.AuditLogId).IsRequired(); - b.HasMany(a => a.EntityChanges).WithOne().HasForeignKey(x => x.AuditLogId).IsRequired(); + Check.NotNull(builder, nameof(builder)); - b.HasIndex(x => new { x.TenantId, x.ExecutionTime }); - b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime }); - - b.ApplyObjectExtensionMappings(); - }); - - builder.Entity(b => - { - b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "AuditLogActions", AbpAuditLoggingDbProperties.DbSchema); + builder.Entity(b => + { + b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "AuditLogs", AbpAuditLoggingDbProperties.DbSchema); + + b.ConfigureByConvention(); + + b.Property(x => x.ApplicationName).HasMaxLength(AuditLogConsts.MaxApplicationNameLength).HasColumnName(nameof(AuditLog.ApplicationName)); + b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength).HasColumnName(nameof(AuditLog.ClientIpAddress)); + b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength).HasColumnName(nameof(AuditLog.ClientName)); + b.Property(x => x.ClientId).HasMaxLength(AuditLogConsts.MaxClientIdLength).HasColumnName(nameof(AuditLog.ClientId)); + b.Property(x => x.CorrelationId).HasMaxLength(AuditLogConsts.MaxCorrelationIdLength).HasColumnName(nameof(AuditLog.CorrelationId)); + b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength).HasColumnName(nameof(AuditLog.BrowserInfo)); + b.Property(x => x.HttpMethod).HasMaxLength(AuditLogConsts.MaxHttpMethodLength).HasColumnName(nameof(AuditLog.HttpMethod)); + b.Property(x => x.Url).HasMaxLength(AuditLogConsts.MaxUrlLength).HasColumnName(nameof(AuditLog.Url)); + b.Property(x => x.HttpStatusCode).HasColumnName(nameof(AuditLog.HttpStatusCode)); + + b.Property(x => x.Comments).HasMaxLength(AuditLogConsts.MaxCommentsLength).HasColumnName(nameof(AuditLog.Comments)); + b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLog.ExecutionDuration)); + b.Property(x => x.ImpersonatorTenantId).HasColumnName(nameof(AuditLog.ImpersonatorTenantId)); + b.Property(x => x.ImpersonatorUserId).HasColumnName(nameof(AuditLog.ImpersonatorUserId)); + b.Property(x => x.UserId).HasColumnName(nameof(AuditLog.UserId)); + b.Property(x => x.UserName).HasMaxLength(AuditLogConsts.MaxUserNameLength).HasColumnName(nameof(AuditLog.UserName)); + b.Property(x => x.TenantId).HasColumnName(nameof(AuditLog.TenantId)); + + b.HasMany(a => a.Actions).WithOne().HasForeignKey(x => x.AuditLogId).IsRequired(); + b.HasMany(a => a.EntityChanges).WithOne().HasForeignKey(x => x.AuditLogId).IsRequired(); + + b.HasIndex(x => new { x.TenantId, x.ExecutionTime }); + b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime }); + + b.ApplyObjectExtensionMappings(); + }); + + builder.Entity(b => + { + b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "AuditLogActions", AbpAuditLoggingDbProperties.DbSchema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.Property(x => x.AuditLogId).HasColumnName(nameof(AuditLogAction.AuditLogId)); - b.Property(x => x.ServiceName).HasMaxLength(AuditLogActionConsts.MaxServiceNameLength).HasColumnName(nameof(AuditLogAction.ServiceName)); - b.Property(x => x.MethodName).HasMaxLength(AuditLogActionConsts.MaxMethodNameLength).HasColumnName(nameof(AuditLogAction.MethodName)); - b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength).HasColumnName(nameof(AuditLogAction.Parameters)); - b.Property(x => x.ExecutionTime).HasColumnName(nameof(AuditLogAction.ExecutionTime)); - b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLogAction.ExecutionDuration)); + b.Property(x => x.AuditLogId).HasColumnName(nameof(AuditLogAction.AuditLogId)); + b.Property(x => x.ServiceName).HasMaxLength(AuditLogActionConsts.MaxServiceNameLength).HasColumnName(nameof(AuditLogAction.ServiceName)); + b.Property(x => x.MethodName).HasMaxLength(AuditLogActionConsts.MaxMethodNameLength).HasColumnName(nameof(AuditLogAction.MethodName)); + b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength).HasColumnName(nameof(AuditLogAction.Parameters)); + b.Property(x => x.ExecutionTime).HasColumnName(nameof(AuditLogAction.ExecutionTime)); + b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLogAction.ExecutionDuration)); - b.HasIndex(x => new { x.AuditLogId }); - b.HasIndex(x => new { x.TenantId, x.ServiceName, x.MethodName, x.ExecutionTime }); + b.HasIndex(x => new { x.AuditLogId }); + b.HasIndex(x => new { x.TenantId, x.ServiceName, x.MethodName, x.ExecutionTime }); - b.ApplyObjectExtensionMappings(); - }); + b.ApplyObjectExtensionMappings(); + }); - builder.Entity(b => - { - b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "EntityChanges", AbpAuditLoggingDbProperties.DbSchema); + builder.Entity(b => + { + b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "EntityChanges", AbpAuditLoggingDbProperties.DbSchema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.Property(x => x.EntityTypeFullName).HasMaxLength(EntityChangeConsts.MaxEntityTypeFullNameLength).IsRequired().HasColumnName(nameof(EntityChange.EntityTypeFullName)); - b.Property(x => x.EntityId).HasMaxLength(EntityChangeConsts.MaxEntityIdLength).IsRequired().HasColumnName(nameof(EntityChange.EntityId)); - b.Property(x => x.AuditLogId).IsRequired().HasColumnName(nameof(EntityChange.AuditLogId)); - b.Property(x => x.ChangeTime).IsRequired().HasColumnName(nameof(EntityChange.ChangeTime)); - b.Property(x => x.ChangeType).IsRequired().HasColumnName(nameof(EntityChange.ChangeType)); - b.Property(x => x.TenantId).HasColumnName(nameof(EntityChange.TenantId)); + b.Property(x => x.EntityTypeFullName).HasMaxLength(EntityChangeConsts.MaxEntityTypeFullNameLength).IsRequired().HasColumnName(nameof(EntityChange.EntityTypeFullName)); + b.Property(x => x.EntityId).HasMaxLength(EntityChangeConsts.MaxEntityIdLength).IsRequired().HasColumnName(nameof(EntityChange.EntityId)); + b.Property(x => x.AuditLogId).IsRequired().HasColumnName(nameof(EntityChange.AuditLogId)); + b.Property(x => x.ChangeTime).IsRequired().HasColumnName(nameof(EntityChange.ChangeTime)); + b.Property(x => x.ChangeType).IsRequired().HasColumnName(nameof(EntityChange.ChangeType)); + b.Property(x => x.TenantId).HasColumnName(nameof(EntityChange.TenantId)); - b.HasMany(a => a.PropertyChanges).WithOne().HasForeignKey(x => x.EntityChangeId); + b.HasMany(a => a.PropertyChanges).WithOne().HasForeignKey(x => x.EntityChangeId); - b.HasIndex(x => new { x.AuditLogId }); - b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName, x.EntityId }); + b.HasIndex(x => new { x.AuditLogId }); + b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName, x.EntityId }); - b.ApplyObjectExtensionMappings(); - }); + b.ApplyObjectExtensionMappings(); + }); - builder.Entity(b => - { - b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "EntityPropertyChanges", AbpAuditLoggingDbProperties.DbSchema); + builder.Entity(b => + { + b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "EntityPropertyChanges", AbpAuditLoggingDbProperties.DbSchema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.Property(x => x.NewValue).HasMaxLength(EntityPropertyChangeConsts.MaxNewValueLength).HasColumnName(nameof(EntityPropertyChange.NewValue)); - b.Property(x => x.PropertyName).HasMaxLength(EntityPropertyChangeConsts.MaxPropertyNameLength).IsRequired().HasColumnName(nameof(EntityPropertyChange.PropertyName)); - b.Property(x => x.PropertyTypeFullName).HasMaxLength(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength).IsRequired().HasColumnName(nameof(EntityPropertyChange.PropertyTypeFullName)); - b.Property(x => x.OriginalValue).HasMaxLength(EntityPropertyChangeConsts.MaxOriginalValueLength).HasColumnName(nameof(EntityPropertyChange.OriginalValue)); + b.Property(x => x.NewValue).HasMaxLength(EntityPropertyChangeConsts.MaxNewValueLength).HasColumnName(nameof(EntityPropertyChange.NewValue)); + b.Property(x => x.PropertyName).HasMaxLength(EntityPropertyChangeConsts.MaxPropertyNameLength).IsRequired().HasColumnName(nameof(EntityPropertyChange.PropertyName)); + b.Property(x => x.PropertyTypeFullName).HasMaxLength(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength).IsRequired().HasColumnName(nameof(EntityPropertyChange.PropertyTypeFullName)); + b.Property(x => x.OriginalValue).HasMaxLength(EntityPropertyChangeConsts.MaxOriginalValueLength).HasColumnName(nameof(EntityPropertyChange.OriginalValue)); - b.HasIndex(x => new { x.EntityChangeId }); + b.HasIndex(x => new { x.EntityChangeId }); - b.ApplyObjectExtensionMappings(); - }); + b.ApplyObjectExtensionMappings(); + }); - builder.TryConfigureObjectExtensions(); - } + builder.TryConfigureObjectExtensions(); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs index 4336024cda..d413994f87 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs @@ -2,18 +2,17 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Modularity; -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +[DependsOn(typeof(AbpAuditLoggingDomainModule))] +[DependsOn(typeof(AbpEntityFrameworkCoreModule))] +public class AbpAuditLoggingEntityFrameworkCoreModule : AbpModule { - [DependsOn(typeof(AbpAuditLoggingDomainModule))] - [DependsOn(typeof(AbpEntityFrameworkCoreModule))] - public class AbpAuditLoggingEntityFrameworkCoreModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + context.Services.AddAbpDbContext(options => { - context.Services.AddAbpDbContext(options => - { - options.AddRepository(); - }); - } + options.AddRepository(); + }); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs index 361ae25f91..add342e075 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs @@ -11,265 +11,264 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +public class EfCoreAuditLogRepository : EfCoreRepository, IAuditLogRepository { - public class EfCoreAuditLogRepository : EfCoreRepository, IAuditLogRepository + public EfCoreAuditLogRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) { - public EfCoreAuditLogRepository(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - - } - public virtual async Task> GetListAsync( - string sorting = null, - int maxResultCount = 50, - int skipCount = 0, - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxExecutionDuration = null, - int? minExecutionDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - var query = await GetListQueryAsync( - startTime, - endTime, - httpMethod, - url, - userId, - userName, - applicationName, - clientIpAddress, - correlationId, - maxExecutionDuration, - minExecutionDuration, - hasException, - httpStatusCode, - includeDetails - ); + } - var auditLogs = await query - .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(AuditLog.ExecutionTime) + " DESC") : sorting) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + public virtual async Task> GetListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var query = await GetListQueryAsync( + startTime, + endTime, + httpMethod, + url, + userId, + userName, + applicationName, + clientIpAddress, + correlationId, + maxExecutionDuration, + minExecutionDuration, + hasException, + httpStatusCode, + includeDetails + ); - return auditLogs; - } + var auditLogs = await query + .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(AuditLog.ExecutionTime) + " DESC") : sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); - public virtual async Task GetCountAsync( - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxExecutionDuration = null, - int? minExecutionDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - CancellationToken cancellationToken = default) - { - var query = await GetListQueryAsync( - startTime, - endTime, - httpMethod, - url, - userId, - userName, - applicationName, - clientIpAddress, - correlationId, - maxExecutionDuration, - minExecutionDuration, - hasException, - httpStatusCode - ); + return auditLogs; + } - var totalCount = await query.LongCountAsync(GetCancellationToken(cancellationToken)); + public virtual async Task GetCountAsync( + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + CancellationToken cancellationToken = default) + { + var query = await GetListQueryAsync( + startTime, + endTime, + httpMethod, + url, + userId, + userName, + applicationName, + clientIpAddress, + correlationId, + maxExecutionDuration, + minExecutionDuration, + hasException, + httpStatusCode + ); - return totalCount; - } + var totalCount = await query.LongCountAsync(GetCancellationToken(cancellationToken)); - protected virtual async Task> GetListQueryAsync( - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxExecutionDuration = null, - int? minExecutionDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - bool includeDetails = false) - { - var nHttpStatusCode = (int?) httpStatusCode; - return (await GetDbSetAsync()).AsNoTracking() - .IncludeDetails(includeDetails) - .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime) - .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime) - .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "") - .WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null || auditLog.Exceptions == "") - .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod == httpMethod) - .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.Contains(url)) - .WhereIf(userId != null, auditLog => auditLog.UserId == userId) - .WhereIf(userName != null, auditLog => auditLog.UserName == userName) - .WhereIf(applicationName != null, auditLog => auditLog.ApplicationName == applicationName) - .WhereIf(clientIpAddress != null, auditLog => auditLog.ClientIpAddress != null && auditLog.ClientIpAddress == clientIpAddress) - .WhereIf(correlationId != null, auditLog => auditLog.CorrelationId == correlationId) - .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == nHttpStatusCode) - .WhereIf(maxExecutionDuration != null && maxExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration <= maxExecutionDuration) - .WhereIf(minExecutionDuration != null && minExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration); - } + return totalCount; + } - public virtual async Task> GetAverageExecutionDurationPerDayAsync( - DateTime startDate, - DateTime endDate, - CancellationToken cancellationToken = default) - { - var result = await (await GetDbSetAsync()).AsNoTracking() - .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) - .OrderBy(t => t.ExecutionTime) - .GroupBy(t => new { t.ExecutionTime.Date }) - .Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) }) - .ToListAsync(GetCancellationToken(cancellationToken)); + protected virtual async Task> GetListQueryAsync( + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxExecutionDuration = null, + int? minExecutionDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = false) + { + var nHttpStatusCode = (int?)httpStatusCode; + return (await GetDbSetAsync()).AsNoTracking() + .IncludeDetails(includeDetails) + .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime) + .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime) + .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "") + .WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null || auditLog.Exceptions == "") + .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod == httpMethod) + .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.Contains(url)) + .WhereIf(userId != null, auditLog => auditLog.UserId == userId) + .WhereIf(userName != null, auditLog => auditLog.UserName == userName) + .WhereIf(applicationName != null, auditLog => auditLog.ApplicationName == applicationName) + .WhereIf(clientIpAddress != null, auditLog => auditLog.ClientIpAddress != null && auditLog.ClientIpAddress == clientIpAddress) + .WhereIf(correlationId != null, auditLog => auditLog.CorrelationId == correlationId) + .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == nHttpStatusCode) + .WhereIf(maxExecutionDuration != null && maxExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration <= maxExecutionDuration) + .WhereIf(minExecutionDuration != null && minExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration); + } - return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime); - } + public virtual async Task> GetAverageExecutionDurationPerDayAsync( + DateTime startDate, + DateTime endDate, + CancellationToken cancellationToken = default) + { + var result = await (await GetDbSetAsync()).AsNoTracking() + .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) + .OrderBy(t => t.ExecutionTime) + .GroupBy(t => new { t.ExecutionTime.Date }) + .Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) }) + .ToListAsync(GetCancellationToken(cancellationToken)); - [Obsolete("Use WithDetailsAsync method.")] - public override IQueryable WithDetails() - { - return GetQueryable().IncludeDetails(); - } + return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime); + } - public override async Task> WithDetailsAsync() - { - return (await GetQueryableAsync()).IncludeDetails(); - } + [Obsolete("Use WithDetailsAsync method.")] + public override IQueryable WithDetails() + { + return GetQueryable().IncludeDetails(); + } - public virtual async Task GetEntityChange( - Guid entityChangeId, - CancellationToken cancellationToken = default) - { - var entityChange = await (await GetDbContextAsync()).Set() - .AsNoTracking() - .IncludeDetails() - .Where(x => x.Id == entityChangeId) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); + } - if (entityChange == null) - { - throw new EntityNotFoundException(typeof(EntityChange)); - } + public virtual async Task GetEntityChange( + Guid entityChangeId, + CancellationToken cancellationToken = default) + { + var entityChange = await (await GetDbContextAsync()).Set() + .AsNoTracking() + .IncludeDetails() + .Where(x => x.Id == entityChangeId) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); - return entityChange; + if (entityChange == null) + { + throw new EntityNotFoundException(typeof(EntityChange)); } - public virtual async Task> GetEntityChangeListAsync( - string sorting = null, - int maxResultCount = 50, - int skipCount = 0, - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, includeDetails); + return entityChange; + } - return await query.OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(EntityChange.ChangeTime) + " DESC") : sorting) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetEntityChangeListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, includeDetails); - public virtual async Task GetEntityChangeCountAsync( - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - CancellationToken cancellationToken = default) - { - var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName); + return await query.OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(EntityChange.ChangeTime) + " DESC") : sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - var totalCount = await query.LongCountAsync(GetCancellationToken(cancellationToken)); + public virtual async Task GetEntityChangeCountAsync( + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + CancellationToken cancellationToken = default) + { + var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName); - return totalCount; - } + var totalCount = await query.LongCountAsync(GetCancellationToken(cancellationToken)); - public virtual async Task GetEntityChangeWithUsernameAsync( - Guid entityChangeId, - CancellationToken cancellationToken = default) - { - var auditLog = await (await GetDbSetAsync()).AsNoTracking().IncludeDetails() - .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)).FirstAsync(GetCancellationToken(cancellationToken)); + return totalCount; + } - return new EntityChangeWithUsername() - { - EntityChange = auditLog.EntityChanges.First(x => x.Id == entityChangeId), - UserName = auditLog.UserName - }; - } + public virtual async Task GetEntityChangeWithUsernameAsync( + Guid entityChangeId, + CancellationToken cancellationToken = default) + { + var auditLog = await (await GetDbSetAsync()).AsNoTracking().IncludeDetails() + .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)).FirstAsync(GetCancellationToken(cancellationToken)); - public virtual async Task> GetEntityChangesWithUsernameAsync( - string entityId, - string entityTypeFullName, - CancellationToken cancellationToken = default) + return new EntityChangeWithUsername() { - var dbContext = await GetDbContextAsync(); + EntityChange = auditLog.EntityChanges.First(x => x.Id == entityChangeId), + UserName = auditLog.UserName + }; + } - var query = dbContext.Set() - .AsNoTracking() - .IncludeDetails() - .Where(x => x.EntityId == entityId && x.EntityTypeFullName == entityTypeFullName); + public virtual async Task> GetEntityChangesWithUsernameAsync( + string entityId, + string entityTypeFullName, + CancellationToken cancellationToken = default) + { + var dbContext = await GetDbContextAsync(); - return await (from e in query - join auditLog in dbContext.AuditLogs on e.AuditLogId equals auditLog.Id - select new EntityChangeWithUsername {EntityChange = e, UserName = auditLog.UserName}) - .OrderByDescending(x => x.EntityChange.ChangeTime).ToListAsync(GetCancellationToken(cancellationToken)); - } + var query = dbContext.Set() + .AsNoTracking() + .IncludeDetails() + .Where(x => x.EntityId == entityId && x.EntityTypeFullName == entityTypeFullName); - protected virtual async Task> GetEntityChangeListQueryAsync( - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - bool includeDetails = false) - { - return (await GetDbContextAsync()) - .Set() - .AsNoTracking() - .IncludeDetails(includeDetails) - .WhereIf(auditLogId.HasValue, e => e.AuditLogId == auditLogId) - .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) - .WhereIf(endTime.HasValue, e => e.ChangeTime <= endTime) - .WhereIf(changeType.HasValue, e => e.ChangeType == changeType) - .WhereIf(!string.IsNullOrWhiteSpace(entityId), e => e.EntityId == entityId) - .WhereIf(!string.IsNullOrWhiteSpace(entityTypeFullName), e => e.EntityTypeFullName.Contains(entityTypeFullName)); - } + return await (from e in query + join auditLog in dbContext.AuditLogs on e.AuditLogId equals auditLog.Id + select new EntityChangeWithUsername { EntityChange = e, UserName = auditLog.UserName }) + .OrderByDescending(x => x.EntityChange.ChangeTime).ToListAsync(GetCancellationToken(cancellationToken)); + } + + protected virtual async Task> GetEntityChangeListQueryAsync( + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + bool includeDetails = false) + { + return (await GetDbContextAsync()) + .Set() + .AsNoTracking() + .IncludeDetails(includeDetails) + .WhereIf(auditLogId.HasValue, e => e.AuditLogId == auditLogId) + .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) + .WhereIf(endTime.HasValue, e => e.ChangeTime <= endTime) + .WhereIf(changeType.HasValue, e => e.ChangeType == changeType) + .WhereIf(!string.IsNullOrWhiteSpace(entityId), e => e.EntityId == entityId) + .WhereIf(!string.IsNullOrWhiteSpace(entityTypeFullName), e => e.EntityTypeFullName.Contains(entityTypeFullName)); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs index 12330463f3..ca03f6b6a3 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs @@ -2,11 +2,10 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +[ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] +public interface IAuditLoggingDbContext : IEfCoreDbContext { - [ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] - public interface IAuditLoggingDbContext : IEfCoreDbContext - { - DbSet AuditLogs { get; } - } -} \ No newline at end of file + DbSet AuditLogs { get; } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AbpAuditLoggingInstallerModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AbpAuditLoggingInstallerModule.cs index d634e7aa60..52ed214a90 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AbpAuditLoggingInstallerModule.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AbpAuditLoggingInstallerModule.cs @@ -2,20 +2,19 @@ using Volo.Abp.Studio; using Volo.Abp.VirtualFileSystem; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[DependsOn( + typeof(AbpStudioModuleInstallerModule), + typeof(AbpVirtualFileSystemModule) + )] +public class AbpAuditLoggingInstallerModule : AbpModule { - [DependsOn( - typeof(AbpStudioModuleInstallerModule), - typeof(AbpVirtualFileSystemModule) - )] - public class AbpAuditLoggingInstallerModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => - { - options.FileSets.AddEmbedded(); - }); - } + options.FileSets.AddEmbedded(); + }); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AuditLoggingInstallerPipelineBuilder.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AuditLoggingInstallerPipelineBuilder.cs index ad0128c639..94ae5d81fc 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AuditLoggingInstallerPipelineBuilder.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Installer/Volo/Abp/AuditLogging/AuditLoggingInstallerPipelineBuilder.cs @@ -3,22 +3,21 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; using Volo.Abp.Studio.ModuleInstalling; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[Dependency(ServiceLifetime.Transient, ReplaceServices = true)] +[ExposeServices(typeof(IModuleInstallingPipelineBuilder))] +public class AuditLoggingInstallerPipelineBuilder : ModuleInstallingPipelineBuilderBase, IModuleInstallingPipelineBuilder, ITransientDependency { - [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] - [ExposeServices(typeof(IModuleInstallingPipelineBuilder))] - public class AuditLoggingInstallerPipelineBuilder : ModuleInstallingPipelineBuilderBase, IModuleInstallingPipelineBuilder, ITransientDependency + public async Task BuildAsync(ModuleInstallingContext context) { - public async Task BuildAsync(ModuleInstallingContext context) - { - context.AddEfCoreConfigurationMethodDeclaration( - new EfCoreConfigurationMethodDeclaration( - "Volo.Abp.AuditLogging.EntityFrameworkCore", - "ConfigureAuditLogging" - ) - ); - - return GetBasePipeline(context); - } + context.AddEfCoreConfigurationMethodDeclaration( + new EfCoreConfigurationMethodDeclaration( + "Volo.Abp.AuditLogging.EntityFrameworkCore", + "ConfigureAuditLogging" + ) + ); + + return GetBasePipeline(context); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbContextExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbContextExtensions.cs index 48b60107ff..b20a2b20a2 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbContextExtensions.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbContextExtensions.cs @@ -1,18 +1,17 @@ using Volo.Abp.MongoDB; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +public static class AbpAuditLoggingMongoDbContextExtensions { - public static class AbpAuditLoggingMongoDbContextExtensions + public static void ConfigureAuditLogging( + this IMongoModelBuilder builder) { - public static void ConfigureAuditLogging( - this IMongoModelBuilder builder) - { - Check.NotNull(builder, nameof(builder)); + Check.NotNull(builder, nameof(builder)); - builder.Entity(b => - { - b.CollectionName = AbpAuditLoggingDbProperties.DbTablePrefix + "AuditLogs"; - }); - } + builder.Entity(b => + { + b.CollectionName = AbpAuditLoggingDbProperties.DbTablePrefix + "AuditLogs"; + }); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs index e73e3642b7..116df1f0f6 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs @@ -2,18 +2,17 @@ using Volo.Abp.Modularity; using Volo.Abp.MongoDB; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +[DependsOn(typeof(AbpAuditLoggingDomainModule))] +[DependsOn(typeof(AbpMongoDbModule))] +public class AbpAuditLoggingMongoDbModule : AbpModule { - [DependsOn(typeof(AbpAuditLoggingDomainModule))] - [DependsOn(typeof(AbpMongoDbModule))] - public class AbpAuditLoggingMongoDbModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + context.Services.AddMongoDbContext(options => { - context.Services.AddMongoDbContext(options => - { - options.AddRepository(); - }); - } + options.AddRepository(); + }); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs index 5f76a82ff4..d755029372 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs @@ -2,18 +2,17 @@ using Volo.Abp.Data; using Volo.Abp.MongoDB; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +[ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] +public class AuditLoggingMongoDbContext : AbpMongoDbContext, IAuditLoggingMongoDbContext { - [ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] - public class AuditLoggingMongoDbContext : AbpMongoDbContext, IAuditLoggingMongoDbContext - { - public IMongoCollection AuditLogs => Collection(); + public IMongoCollection AuditLogs => Collection(); - protected override void CreateModel(IMongoModelBuilder modelBuilder) - { - base.CreateModel(modelBuilder); + protected override void CreateModel(IMongoModelBuilder modelBuilder) + { + base.CreateModel(modelBuilder); - modelBuilder.ConfigureAuditLogging(); - } + modelBuilder.ConfigureAuditLogging(); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs index 2edd1cb003..54350672ab 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs @@ -2,11 +2,10 @@ using Volo.Abp.Data; using Volo.Abp.MongoDB; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +[ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] +public interface IAuditLoggingMongoDbContext : IAbpMongoDbContext { - [ConnectionStringName(AbpAuditLoggingDbProperties.ConnectionStringName)] - public interface IAuditLoggingMongoDbContext : IAbpMongoDbContext - { - IMongoCollection AuditLogs { get; } - } + IMongoCollection AuditLogs { get; } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index 06bf102fed..5bb84197fa 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -12,261 +12,259 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +public class MongoAuditLogRepository : MongoDbRepository, IAuditLogRepository { - public class MongoAuditLogRepository : MongoDbRepository, IAuditLogRepository + public MongoAuditLogRepository(IMongoDbContextProvider dbContextProvider) + : base(dbContextProvider) { - public MongoAuditLogRepository(IMongoDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - - } - public virtual async Task> GetListAsync( - string sorting = null, - int maxResultCount = 50, - int skipCount = 0, - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxDuration = null, - int? minDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - var query = await GetListQueryAsync( - startTime, - endTime, - httpMethod, - url, - userId, - userName, - applicationName, - clientIpAddress, - correlationId, - maxDuration, - minDuration, - hasException, - httpStatusCode, - includeDetails, - cancellationToken - ); + } - return await query - .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(AuditLog.ExecutionTime) + " DESC") : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxDuration = null, + int? minDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var query = await GetListQueryAsync( + startTime, + endTime, + httpMethod, + url, + userId, + userName, + applicationName, + clientIpAddress, + correlationId, + maxDuration, + minDuration, + hasException, + httpStatusCode, + includeDetails, + cancellationToken + ); - public virtual async Task GetCountAsync( - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxDuration = null, - int? minDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - CancellationToken cancellationToken = default) - { - var query = await GetListQueryAsync( - startTime, - endTime, - httpMethod, - url, - userId, - userName, - applicationName, - clientIpAddress, - correlationId, - maxDuration, - minDuration, - hasException, - httpStatusCode, - cancellationToken: cancellationToken - ); + return await query + .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(AuditLog.ExecutionTime) + " DESC") : sorting) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - var count = await query.As>() - .LongCountAsync(GetCancellationToken(cancellationToken)); + public virtual async Task GetCountAsync( + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxDuration = null, + int? minDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + CancellationToken cancellationToken = default) + { + var query = await GetListQueryAsync( + startTime, + endTime, + httpMethod, + url, + userId, + userName, + applicationName, + clientIpAddress, + correlationId, + maxDuration, + minDuration, + hasException, + httpStatusCode, + cancellationToken: cancellationToken + ); - return count; - } + var count = await query.As>() + .LongCountAsync(GetCancellationToken(cancellationToken)); - protected virtual async Task> GetListQueryAsync( - DateTime? startTime = null, - DateTime? endTime = null, - string httpMethod = null, - string url = null, - Guid? userId = null, - string userName = null, - string applicationName = null, - string clientIpAddress = null, - string correlationId = null, - int? maxDuration = null, - int? minDuration = null, - bool? hasException = null, - HttpStatusCode? httpStatusCode = null, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime) - .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime) - .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "") - .WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null || auditLog.Exceptions == "") - .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod == httpMethod) - .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.Contains(url)) - .WhereIf(userId != null, auditLog => auditLog.UserId == userId) - .WhereIf(userName != null, auditLog => auditLog.UserName == userName) - .WhereIf(applicationName != null, auditLog => auditLog.ApplicationName == applicationName) - .WhereIf(clientIpAddress != null, auditLog => auditLog.ClientIpAddress == clientIpAddress) - .WhereIf(correlationId != null, auditLog => auditLog.CorrelationId == correlationId) - .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode) - .WhereIf(maxDuration != null && maxDuration > 0, auditLog => auditLog.ExecutionDuration <= maxDuration) - .WhereIf(minDuration != null && minDuration > 0, auditLog => auditLog.ExecutionDuration >= minDuration); - } + return count; + } - public virtual async Task> GetAverageExecutionDurationPerDayAsync( - DateTime startDate, - DateTime endDate, - CancellationToken cancellationToken = default) - { - var result = await (await GetMongoQueryableAsync(cancellationToken)) - .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) - .OrderBy(t => t.ExecutionTime) - .GroupBy(t => new - { - t.ExecutionTime.Year, - t.ExecutionTime.Month, - t.ExecutionTime.Day - }) - .Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) }) - .ToListAsync(GetCancellationToken(cancellationToken)); + protected virtual async Task> GetListQueryAsync( + DateTime? startTime = null, + DateTime? endTime = null, + string httpMethod = null, + string url = null, + Guid? userId = null, + string userName = null, + string applicationName = null, + string clientIpAddress = null, + string correlationId = null, + int? maxDuration = null, + int? minDuration = null, + bool? hasException = null, + HttpStatusCode? httpStatusCode = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime) + .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime) + .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "") + .WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null || auditLog.Exceptions == "") + .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod == httpMethod) + .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.Contains(url)) + .WhereIf(userId != null, auditLog => auditLog.UserId == userId) + .WhereIf(userName != null, auditLog => auditLog.UserName == userName) + .WhereIf(applicationName != null, auditLog => auditLog.ApplicationName == applicationName) + .WhereIf(clientIpAddress != null, auditLog => auditLog.ClientIpAddress == clientIpAddress) + .WhereIf(correlationId != null, auditLog => auditLog.CorrelationId == correlationId) + .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode) + .WhereIf(maxDuration != null && maxDuration > 0, auditLog => auditLog.ExecutionDuration <= maxDuration) + .WhereIf(minDuration != null && minDuration > 0, auditLog => auditLog.ExecutionDuration >= minDuration); + } - return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime); - } + public virtual async Task> GetAverageExecutionDurationPerDayAsync( + DateTime startDate, + DateTime endDate, + CancellationToken cancellationToken = default) + { + var result = await (await GetMongoQueryableAsync(cancellationToken)) + .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) + .OrderBy(t => t.ExecutionTime) + .GroupBy(t => new { + t.ExecutionTime.Year, + t.ExecutionTime.Month, + t.ExecutionTime.Day + }) + .Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) }) + .ToListAsync(GetCancellationToken(cancellationToken)); - public virtual async Task GetEntityChange( - Guid entityChangeId, - CancellationToken cancellationToken = default) - { - var entityChange = (await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) - .OrderBy(x => x.Id) - .FirstAsync(GetCancellationToken(cancellationToken))).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); + return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime); + } - if (entityChange == null) - { - throw new EntityNotFoundException(typeof(EntityChange)); - } + public virtual async Task GetEntityChange( + Guid entityChangeId, + CancellationToken cancellationToken = default) + { + var entityChange = (await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) + .OrderBy(x => x.Id) + .FirstAsync(GetCancellationToken(cancellationToken))).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); - return entityChange; + if (entityChange == null) + { + throw new EntityNotFoundException(typeof(EntityChange)); } - public virtual async Task> GetEntityChangeListAsync( - string sorting = null, - int maxResultCount = 50, - int skipCount = 0, - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken); + return entityChange; + } - return await query - .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(EntityChange.ChangeTime) + " DESC") : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetEntityChangeListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken); - public virtual async Task GetEntityChangeCountAsync( - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - CancellationToken cancellationToken = default) - { - var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken); + return await query + .OrderBy(sorting.IsNullOrWhiteSpace() ? (nameof(EntityChange.ChangeTime) + " DESC") : sorting) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - var count = await query.As>().LongCountAsync(GetCancellationToken(cancellationToken)); + public virtual async Task GetEntityChangeCountAsync( + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + CancellationToken cancellationToken = default) + { + var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken); - return count; - } + var count = await query.As>().LongCountAsync(GetCancellationToken(cancellationToken)); - public virtual async Task GetEntityChangeWithUsernameAsync( - Guid entityChangeId, - CancellationToken cancellationToken = default) - { - var auditLog = await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) - .FirstAsync(GetCancellationToken(cancellationToken)); + return count; + } - return new EntityChangeWithUsername() - { - EntityChange = auditLog.EntityChanges.First(x => x.Id == entityChangeId), - UserName = auditLog.UserName - }; - } + public virtual async Task GetEntityChangeWithUsernameAsync( + Guid entityChangeId, + CancellationToken cancellationToken = default) + { + var auditLog = await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) + .FirstAsync(GetCancellationToken(cancellationToken)); - public virtual async Task> GetEntityChangesWithUsernameAsync( - string entityId, - string entityTypeFullName, - CancellationToken cancellationToken = default) + return new EntityChangeWithUsername() { - var auditLogs = await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)) - .As>() - .OrderByDescending(x => x.ExecutionTime) - .ToListAsync(GetCancellationToken(cancellationToken)); + EntityChange = auditLog.EntityChanges.First(x => x.Id == entityChangeId), + UserName = auditLog.UserName + }; + } - var entityChanges = auditLogs.SelectMany(x => x.EntityChanges).ToList(); + public virtual async Task> GetEntityChangesWithUsernameAsync( + string entityId, + string entityTypeFullName, + CancellationToken cancellationToken = default) + { + var auditLogs = await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)) + .As>() + .OrderByDescending(x => x.ExecutionTime) + .ToListAsync(GetCancellationToken(cancellationToken)); - entityChanges.RemoveAll(x => x.EntityId != entityId || x.EntityTypeFullName != entityTypeFullName); + var entityChanges = auditLogs.SelectMany(x => x.EntityChanges).ToList(); - return entityChanges.Select(x => new EntityChangeWithUsername() - {EntityChange = x, UserName = auditLogs.First(y => y.Id == x.AuditLogId).UserName}).ToList(); - } + entityChanges.RemoveAll(x => x.EntityId != entityId || x.EntityTypeFullName != entityTypeFullName); - protected virtual async Task> GetEntityChangeListQueryAsync( - Guid? auditLogId = null, - DateTime? startTime = null, - DateTime? endTime = null, - EntityChangeType? changeType = null, - string entityId = null, - string entityTypeFullName = null, - CancellationToken cancellationToken = default) - { - return (await GetMongoQueryableAsync(cancellationToken)) - .SelectMany(x => x.EntityChanges) - .WhereIf(auditLogId.HasValue, e => e.Id == auditLogId) - .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) - .WhereIf(endTime.HasValue, e => e.ChangeTime <= endTime) - .WhereIf(changeType.HasValue, e => e.ChangeType == changeType) - .WhereIf(!string.IsNullOrWhiteSpace(entityId), e => e.EntityId == entityId) - .WhereIf(!string.IsNullOrWhiteSpace(entityTypeFullName), - e => e.EntityTypeFullName.Contains(entityTypeFullName)); - } + return entityChanges.Select(x => new EntityChangeWithUsername() + { EntityChange = x, UserName = auditLogs.First(y => y.Id == x.AuditLogId).UserName }).ToList(); + } + + protected virtual async Task> GetEntityChangeListQueryAsync( + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + CancellationToken cancellationToken = default) + { + return (await GetMongoQueryableAsync(cancellationToken)) + .SelectMany(x => x.EntityChanges) + .WhereIf(auditLogId.HasValue, e => e.Id == auditLogId) + .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) + .WhereIf(endTime.HasValue, e => e.ChangeTime <= endTime) + .WhereIf(changeType.HasValue, e => e.ChangeType == changeType) + .WhereIf(!string.IsNullOrWhiteSpace(entityId), e => e.EntityId == entityId) + .WhereIf(!string.IsNullOrWhiteSpace(entityTypeFullName), + e => e.EntityTypeFullName.Contains(entityTypeFullName)); } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs index 0883f5f123..bb8570d253 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs @@ -7,38 +7,37 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Sqlite; using Volo.Abp.Modularity; -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +[DependsOn( + typeof(AbpAuditLoggingTestBaseModule), + typeof(AbpAuditLoggingEntityFrameworkCoreModule), + typeof(AbpEntityFrameworkCoreSqliteModule) +)] +public class AbpAuditLoggingEntityFrameworkCoreTestModule : AbpModule { - [DependsOn( - typeof(AbpAuditLoggingTestBaseModule), - typeof(AbpAuditLoggingEntityFrameworkCoreModule), - typeof(AbpEntityFrameworkCoreSqliteModule) - )] - public class AbpAuditLoggingEntityFrameworkCoreTestModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var sqliteConnection = CreateDatabaseAndGetConnection(); + var sqliteConnection = CreateDatabaseAndGetConnection(); - Configure(options => + Configure(options => + { + options.Configure(ctx => { - options.Configure(ctx => - { - ctx.DbContextOptions.UseSqlite(sqliteConnection); - }); + ctx.DbContextOptions.UseSqlite(sqliteConnection); }); - } + }); + } - private static SqliteConnection CreateDatabaseAndGetConnection() - { - var connection = new SqliteConnection("Data Source=:memory:"); - connection.Open(); + private static SqliteConnection CreateDatabaseAndGetConnection() + { + var connection = new SqliteConnection("Data Source=:memory:"); + connection.Open(); - new AbpAuditLoggingDbContext( - new DbContextOptionsBuilder().UseSqlite(connection).Options - ).GetService().CreateTables(); + new AbpAuditLoggingDbContext( + new DbContextOptionsBuilder().UseSqlite(connection).Options + ).GetService().CreateTables(); - return connection; - } + return connection; } -} \ No newline at end of file +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditLogRepository_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditLogRepository_Tests.cs index 7330e3292e..bd12348359 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditLogRepository_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditLogRepository_Tests.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +public class AuditLogRepository_Tests : AuditLogRepository_Tests { - public class AuditLogRepository_Tests : AuditLogRepository_Tests - { - } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditStore_Basic_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditStore_Basic_Tests.cs index af623d5d5b..a3e60912dd 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditStore_Basic_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditStore_Basic_Tests.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.AuditLogging.EntityFrameworkCore +namespace Volo.Abp.AuditLogging.EntityFrameworkCore; + +public class AuditStore_Basic_Tests : AuditStore_Basic_Tests { - public class AuditStore_Basic_Tests : AuditStore_Basic_Tests - { - } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbTestModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbTestModule.cs index cd210e6985..592d11a480 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbTestModule.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbTestModule.cs @@ -3,25 +3,24 @@ using Volo.Abp.Data; using Volo.Abp.Modularity; using Volo.Abp.Uow; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +[DependsOn( + typeof(AbpAuditLoggingTestBaseModule), + typeof(AbpAuditLoggingMongoDbModule) +)] +public class AbpAuditLoggingMongoDbTestModule : AbpModule { - [DependsOn( - typeof(AbpAuditLoggingTestBaseModule), - typeof(AbpAuditLoggingMongoDbModule) - )] - public class AbpAuditLoggingMongoDbTestModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var stringArray = MongoDbFixture.ConnectionString.Split('?'); - var connectionString = stringArray[0].EnsureEndsWith('/') + - "Db_" + - Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; + var stringArray = MongoDbFixture.ConnectionString.Split('?'); + var connectionString = stringArray[0].EnsureEndsWith('/') + + "Db_" + + Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; - Configure(options => - { - options.ConnectionStrings.Default = connectionString; - }); - } + Configure(options => + { + options.ConnectionStrings.Default = connectionString; + }); } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditLogRepository_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditLogRepository_Tests.cs index a0edd58a45..6a81f80157 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditLogRepository_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditLogRepository_Tests.cs @@ -3,11 +3,10 @@ using System.Collections.Generic; using System.Text; using Xunit; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +[Collection(MongoTestCollection.Name)] +public class AuditLogRepository_Tests : AuditLogRepository_Tests { - [Collection(MongoTestCollection.Name)] - public class AuditLogRepository_Tests : AuditLogRepository_Tests - { - } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditStore_Basic_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditStore_Basic_Tests.cs index ad590c61e1..982c335b6b 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditStore_Basic_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/AuditStore_Basic_Tests.cs @@ -1,10 +1,9 @@ using Xunit; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +[Collection(MongoTestCollection.Name)] +public class AuditStore_Basic_Tests : AuditStore_Basic_Tests { - [Collection(MongoTestCollection.Name)] - public class AuditStore_Basic_Tests : AuditStore_Basic_Tests - { - } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs index f66be5d113..ea7be8dd53 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoDbFixture.cs @@ -1,22 +1,21 @@ using System; using Mongo2Go; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +public class MongoDbFixture : IDisposable { - public class MongoDbFixture : IDisposable - { - private static readonly MongoDbRunner MongoDbRunner; - public static readonly string ConnectionString; + private static readonly MongoDbRunner MongoDbRunner; + public static readonly string ConnectionString; - static MongoDbFixture() - { - MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 20); - ConnectionString = MongoDbRunner.ConnectionString; - } + static MongoDbFixture() + { + MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 20); + ConnectionString = MongoDbRunner.ConnectionString; + } - public void Dispose() - { - MongoDbRunner?.Dispose(); - } + public void Dispose() + { + MongoDbRunner?.Dispose(); } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoTestCollection.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoTestCollection.cs index 1d89caa8b0..2073b7357a 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoTestCollection.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.MongoDB.Tests/Volo/Abp/AuditLogging/MongoDB/MongoTestCollection.cs @@ -1,10 +1,9 @@ using Xunit; -namespace Volo.Abp.AuditLogging.MongoDB +namespace Volo.Abp.AuditLogging.MongoDB; + +[CollectionDefinition(Name)] +public class MongoTestCollection : ICollectionFixture { - [CollectionDefinition(Name)] - public class MongoTestCollection : ICollectionFixture - { - public const string Name = "MongoDB Collection"; - } -} \ No newline at end of file + public const string Name = "MongoDB Collection"; +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs index b157b9f81c..ed44f7cb23 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs @@ -2,27 +2,26 @@ using Volo.Abp.Autofac; using Volo.Abp.Modularity; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpTestBaseModule), + typeof(AbpAuditLoggingDomainModule))] +public class AbpAuditLoggingTestBaseModule : AbpModule { - [DependsOn( - typeof(AbpAutofacModule), - typeof(AbpTestBaseModule), - typeof(AbpAuditLoggingDomainModule))] - public class AbpAuditLoggingTestBaseModule : AbpModule + public override void OnApplicationInitialization(ApplicationInitializationContext context) { - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - SeedTestData(context); - } + SeedTestData(context); + } - private static void SeedTestData(ApplicationInitializationContext context) + private static void SeedTestData(ApplicationInitializationContext context) + { + using (var scope = context.ServiceProvider.CreateScope()) { - using (var scope = context.ServiceProvider.CreateScope()) - { - scope.ServiceProvider - .GetRequiredService () - .Build(); - } + scope.ServiceProvider + .GetRequiredService() + .Build(); } } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs index 6716b87cda..0a56e3f398 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs @@ -8,42 +8,42 @@ using Volo.Abp.Auditing; using Volo.Abp.Modularity; using Xunit; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public abstract class AuditLogRepository_Tests : AuditLoggingTestBase + where TStartupModule : IAbpModule { - public abstract class AuditLogRepository_Tests : AuditLoggingTestBase - where TStartupModule : IAbpModule + protected IAuditLogRepository AuditLogRepository { get; } + protected IAuditLogInfoToAuditLogConverter AuditLogInfoToAuditLogConverter { get; } + + protected AuditLogRepository_Tests() { - protected IAuditLogRepository AuditLogRepository { get; } - protected IAuditLogInfoToAuditLogConverter AuditLogInfoToAuditLogConverter { get; } + AuditLogRepository = GetRequiredService(); + AuditLogInfoToAuditLogConverter = GetRequiredService(); + } - protected AuditLogRepository_Tests() - { - AuditLogRepository = GetRequiredService(); - AuditLogInfoToAuditLogConverter = GetRequiredService(); - } + [Fact] + public async Task GetListAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetListAsync() + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -80,21 +80,21 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -114,40 +114,40 @@ namespace Volo.Abp.AuditLogging } } - }; + }; - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - //Assert - var logs = await AuditLogRepository.GetListAsync(); - logs.ShouldNotBeNull(); - logs.ShouldContain(x => x.UserId == userId); - logs.ShouldContain(x => x.UserId == userId2); - } + //Assert + var logs = await AuditLogRepository.GetListAsync(); + logs.ShouldNotBeNull(); + logs.ShouldContain(x => x.UserId == userId); + logs.ShouldContain(x => x.UserId == userId2); + } + + [Fact] + public async Task GetCountAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetCountAsync() + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -184,21 +184,21 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -218,38 +218,38 @@ namespace Volo.Abp.AuditLogging } } - }; + }; + + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + //Assert + var logs = await AuditLogRepository.GetCountAsync(); + logs.ShouldBe(2); + } - //Assert - var logs = await AuditLogRepository.GetCountAsync(); - logs.ShouldBe(2); - } + [Fact] + public async Task GetAverageExecutionDurationPerDayAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetAverageExecutionDurationPerDayAsync() + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.SpecifyKind(DateTime.Parse("2020-01-01 01:00:00"), DateTimeKind.Utc), - ExecutionDuration = 45, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.SpecifyKind(DateTime.Parse("2020-01-01 01:00:00"), DateTimeKind.Utc), + ExecutionDuration = 45, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -286,21 +286,21 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.SpecifyKind(DateTime.Parse("2020-01-01 03:00:00"), DateTimeKind.Utc), - ExecutionDuration = 55, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.SpecifyKind(DateTime.Parse("2020-01-01 03:00:00"), DateTimeKind.Utc), + ExecutionDuration = 55, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -320,40 +320,40 @@ namespace Volo.Abp.AuditLogging } } - }; + }; - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - //Assert - var date = DateTime.Parse("2020-01-01"); - var results = await AuditLogRepository.GetAverageExecutionDurationPerDayAsync(date, date); - results.Count.ShouldBe(1); - results.Values.First().ShouldBe(50); // (45 + 55) / 2 - } + //Assert + var date = DateTime.Parse("2020-01-01"); + var results = await AuditLogRepository.GetAverageExecutionDurationPerDayAsync(date, date); + results.Count.ShouldBe(1); + results.Values.First().ShouldBe(50); // (45 + 55) / 2 + } + + [Fact] + public async Task GetEntityChangeListAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetEntityChangeListAsync() + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -390,21 +390,21 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -423,43 +423,43 @@ namespace Volo.Abp.AuditLogging } } } - }; + }; + + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + //Assert + var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(); + entityChanges.ShouldNotBeNull(); + entityChanges.Count.ShouldBe(3); - //Assert - var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(); - entityChanges.ShouldNotBeNull(); - entityChanges.Count.ShouldBe(3); + entityChanges.Single(x => x.ChangeType == EntityChangeType.Created).ShouldNotBeNull(); + entityChanges.Single(x => x.ChangeType == EntityChangeType.Deleted).ShouldNotBeNull(); + entityChanges.Single(x => x.ChangeType == EntityChangeType.Updated).ShouldNotBeNull(); + } - entityChanges.Single(x => x.ChangeType == EntityChangeType.Created).ShouldNotBeNull(); - entityChanges.Single(x => x.ChangeType == EntityChangeType.Deleted).ShouldNotBeNull(); - entityChanges.Single(x => x.ChangeType == EntityChangeType.Updated).ShouldNotBeNull(); - } + [Fact] + public async Task GetEntityChangeAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetEntityChangeAsync() + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -496,21 +496,21 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -529,44 +529,44 @@ namespace Volo.Abp.AuditLogging } } } - }; + }; + + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(); + var entityChange = + await AuditLogRepository.GetEntityChange(entityChanges.First().Id); - var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(); - var entityChange = - await AuditLogRepository.GetEntityChange(entityChanges.First().Id); + entityChange.ChangeTime.ShouldBe(entityChanges.First().ChangeTime); + } - entityChange.ChangeTime.ShouldBe(entityChanges.First().ChangeTime); - } + [Fact] + public async Task GetOrderedEntityChangeListAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetOrderedEntityChangeListAsync() + var deletedEntityChangeTime = new DateTime(2000, 05, 05, 05, 05, 05); + var createdEntityChangeTime = new DateTime(2005, 05, 05, 05, 05, 05); + var updatedEntityChangeTime = new DateTime(2010, 05, 05, 05, 05, 05); + + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var deletedEntityChangeTime = new DateTime(2000, 05, 05, 05, 05, 05); - var createdEntityChangeTime = new DateTime(2005, 05, 05, 05, 05, 05); - var updatedEntityChangeTime = new DateTime(2010, 05, 05, 05, 05, 05); - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -603,21 +603,21 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -636,51 +636,51 @@ namespace Volo.Abp.AuditLogging } } } - }; + }; - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - //Assert - var entityChangesDesc = await AuditLogRepository.GetEntityChangeListAsync(); - entityChangesDesc.ShouldNotBeNull(); - entityChangesDesc.Count.ShouldBe(3); + //Assert + var entityChangesDesc = await AuditLogRepository.GetEntityChangeListAsync(); + entityChangesDesc.ShouldNotBeNull(); + entityChangesDesc.Count.ShouldBe(3); - entityChangesDesc.First().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Updated"); - entityChangesDesc.Last().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Deleted"); + entityChangesDesc.First().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Updated"); + entityChangesDesc.Last().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Deleted"); - var entityChangesAsc = await AuditLogRepository.GetEntityChangeListAsync("changeTime asc"); + var entityChangesAsc = await AuditLogRepository.GetEntityChangeListAsync("changeTime asc"); - entityChangesAsc.First().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Deleted"); - entityChangesAsc.Last().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Updated"); - } + entityChangesAsc.First().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Deleted"); + entityChangesAsc.Last().EntityTypeFullName.ShouldBe("Volo.Abp.AuditLogging.TestEntity_Updated"); + } + + [Fact] + public async Task GetSpecifiedEntityChangeListAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetSpecifiedEntityChangeListAsync() + var deletedEntityChangeTime = new DateTime(2000, 05, 05, 05, 05, 05); + var createdEntityChangeTime = new DateTime(2005, 05, 05, 05, 05, 05); + var updatedEntityChangeTime = new DateTime(2010, 05, 05, 05, 05, 05); + + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var deletedEntityChangeTime = new DateTime(2000, 05, 05, 05, 05, 05); - var createdEntityChangeTime = new DateTime(2005, 05, 05, 05, 05, 05); - var updatedEntityChangeTime = new DateTime(2010, 05, 05, 05, 05, 05); - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -716,21 +716,21 @@ namespace Volo.Abp.AuditLogging } } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -749,45 +749,45 @@ namespace Volo.Abp.AuditLogging } } } - }; + }; - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - //Assert - var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(changeType: EntityChangeType.Created); - entityChanges.ShouldNotBeNull(); - entityChanges.Count.ShouldBe(1); - } + //Assert + var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(changeType: EntityChangeType.Created); + entityChanges.ShouldNotBeNull(); + entityChanges.Count.ShouldBe(1); + } + + [Fact] + public async Task GetEntityChangesWithUsernameAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetEntityChangesWithUsernameAsync() + var firstUser = "Douglas"; + var secondUser = "John Doe"; + + var entityId = Guid.NewGuid().ToString(); + var entityType = "Volo.Abp.AuditLogging.TestEntity"; + + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var firstUser = "Douglas"; - var secondUser = "John Doe"; - - var entityId = Guid.NewGuid().ToString(); - var entityType = "Volo.Abp.AuditLogging.TestEntity"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = firstUser, - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = firstUser, + EntityChanges = { new EntityChangeInfo { EntityId = entityId, @@ -824,22 +824,22 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.Accepted, - UserName = secondUser, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.Accepted, + UserName = secondUser, + EntityChanges = { new EntityChangeInfo { EntityId = entityId, @@ -859,48 +859,48 @@ namespace Volo.Abp.AuditLogging } } - }; + }; + + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + //Assert + var entityHistory = await AuditLogRepository.GetEntityChangesWithUsernameAsync(entityId, entityType); - //Assert - var entityHistory = await AuditLogRepository.GetEntityChangesWithUsernameAsync(entityId, entityType); + entityHistory.Count.ShouldBe(2); + var firstUserChange = entityHistory.First(x => x.UserName == firstUser); + firstUserChange.ShouldNotBeNull(); + firstUserChange.EntityChange.ShouldNotBeNull(); + firstUserChange.EntityChange.ChangeType.ShouldBe(EntityChangeType.Created); - entityHistory.Count.ShouldBe(2); - var firstUserChange = entityHistory.First(x => x.UserName == firstUser); - firstUserChange.ShouldNotBeNull(); - firstUserChange.EntityChange.ShouldNotBeNull(); - firstUserChange.EntityChange.ChangeType.ShouldBe(EntityChangeType.Created); + var secondUserChange = entityHistory.First(x => x.UserName == secondUser); + secondUserChange.ShouldNotBeNull(); + secondUserChange.EntityChange.ShouldNotBeNull(); + secondUserChange.EntityChange.ChangeType.ShouldBe(EntityChangeType.Updated); + } - var secondUserChange = entityHistory.First(x => x.UserName == secondUser); - secondUserChange.ShouldNotBeNull(); - secondUserChange.EntityChange.ShouldNotBeNull(); - secondUserChange.EntityChange.ChangeType.ShouldBe(EntityChangeType.Updated); - } + [Fact] + public async Task GetEntityChangeWithUsernameAsync() + { + // Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task GetEntityChangeWithUsernameAsync() + var log1 = new AuditLogInfo { - // Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var userId2 = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -937,22 +937,22 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId2, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - UserName = "John Doe", - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId2, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + UserName = "John Doe", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -971,17 +971,16 @@ namespace Volo.Abp.AuditLogging } } } - }; + }; - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); - await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log1)); + await AuditLogRepository.InsertAsync(await AuditLogInfoToAuditLogConverter.ConvertAsync(log2)); - var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(); - var entityHistory = - await AuditLogRepository.GetEntityChangeWithUsernameAsync(entityChanges.First().Id); + var entityChanges = await AuditLogRepository.GetEntityChangeListAsync(); + var entityHistory = + await AuditLogRepository.GetEntityChangeWithUsernameAsync(entityChanges.First().Id); - entityHistory.EntityChange.ChangeTime.ShouldBe(entityChanges.First().ChangeTime); - entityHistory.UserName.ShouldNotBeNull(); - } + entityHistory.EntityChange.ChangeTime.ShouldBe(entityChanges.First().ChangeTime); + entityHistory.UserName.ShouldNotBeNull(); } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs index f7378f74dc..36b80f4635 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs @@ -1,14 +1,13 @@ using Volo.Abp.Modularity; using Volo.Abp.Testing; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AuditLoggingTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule { - public class AuditLoggingTestBase : AbpIntegratedTest - where TStartupModule : IAbpModule + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { - protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) - { - options.UseAutofac(); - } + options.UseAutofac(); } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogging_Repository_Resolve_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogging_Repository_Resolve_Tests.cs index 340e3c7f3c..8eb7bba8bc 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogging_Repository_Resolve_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogging_Repository_Resolve_Tests.cs @@ -3,11 +3,10 @@ using System.Collections.Generic; using System.Text; using Volo.Abp.Modularity; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AuditLogging_Repository_Resolve_Tests : AuditLoggingTestBase + where TStartupModule : IAbpModule { - public class AuditLogging_Repository_Resolve_Tests : AuditLoggingTestBase - where TStartupModule : IAbpModule - { - } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs index 05dc829440..102456bc66 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs @@ -8,40 +8,40 @@ using Volo.Abp.Auditing; using Volo.Abp.Modularity; using Xunit; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public abstract class AuditStore_Basic_Tests : AuditLoggingTestBase + where TStartupModule : IAbpModule { - public abstract class AuditStore_Basic_Tests : AuditLoggingTestBase - where TStartupModule : IAbpModule + private readonly IAuditingStore _auditingStore; + private readonly IAuditLogRepository _auditLogRepository; + + protected AuditStore_Basic_Tests() { - private readonly IAuditingStore _auditingStore; - private readonly IAuditLogRepository _auditLogRepository; + _auditingStore = GetRequiredService(); + _auditLogRepository = GetRequiredService(); + } - protected AuditStore_Basic_Tests() - { - _auditingStore = GetRequiredService(); - _auditLogRepository = GetRequiredService(); - } + [Fact] + public async Task Should_Save_An_Audit_Log() + { + //Arrange + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task Should_Save_An_Audit_Log() + var auditLog = new AuditLogInfo { - //Arrange - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var auditLog = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - EntityChanges = + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + EntityChanges = { new EntityChangeInfo { @@ -61,43 +61,43 @@ namespace Volo.Abp.AuditLogging } } } - }; + }; - //Act - await _auditingStore.SaveAsync(auditLog); + //Act + await _auditingStore.SaveAsync(auditLog); - //Assert + //Assert - var insertedLog = (await _auditLogRepository.GetListAsync(true)) - .FirstOrDefault(al => al.UserId == userId); + var insertedLog = (await _auditLogRepository.GetListAsync(true)) + .FirstOrDefault(al => al.UserId == userId); - insertedLog.ShouldNotBeNull(); - insertedLog.ClientIpAddress.ShouldBe(ipAddress); - insertedLog.Comments.ShouldStartWith(firstComment); - insertedLog.EntityChanges.Count.ShouldBeGreaterThan(0); - insertedLog.EntityChanges.First().PropertyChanges.Count.ShouldBeGreaterThan(0); - } + insertedLog.ShouldNotBeNull(); + insertedLog.ClientIpAddress.ShouldBe(ipAddress); + insertedLog.Comments.ShouldStartWith(firstComment); + insertedLog.EntityChanges.Count.ShouldBeGreaterThan(0); + insertedLog.EntityChanges.First().PropertyChanges.Count.ShouldBeGreaterThan(0); + } + + [Fact] + public async Task Should_Get_List_Of_Audit_Logs() + { + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; - [Fact] - public async Task Should_Get_List_Of_Audit_Logs() + var log1 = new AuditLogInfo { - var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); - var ipAddress = "153.1.7.61"; - var firstComment = "first Comment"; - - var log1 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - UserName = "Douglas", - EntityChanges = { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -134,21 +134,21 @@ namespace Volo.Abp.AuditLogging } } - }; - - var log2 = new AuditLogInfo - { - UserId = userId, - ImpersonatorUserId = Guid.NewGuid(), - ImpersonatorTenantId = Guid.NewGuid(), - ExecutionTime = DateTime.Today, - ExecutionDuration = 42, - ClientIpAddress = ipAddress, - ClientName = "MyDesktop", - BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment" }, - HttpStatusCode = (int?)HttpStatusCode.BadGateway, - EntityChanges = { + }; + + var log2 = new AuditLogInfo + { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { new EntityChangeInfo { EntityId = Guid.NewGuid().ToString(), @@ -168,27 +168,26 @@ namespace Volo.Abp.AuditLogging } } - }; + }; - await _auditingStore.SaveAsync(log1); - await _auditingStore.SaveAsync(log2); + await _auditingStore.SaveAsync(log1); + await _auditingStore.SaveAsync(log2); - var allLogsCount = await _auditLogRepository.GetCountAsync(); + var allLogsCount = await _auditLogRepository.GetCountAsync(); - var onlyLog1QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, userName: "Douglas"); + var onlyLog1QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, userName: "Douglas"); - var onlyLog2QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, httpStatusCode: HttpStatusCode.BadGateway); + var onlyLog2QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, httpStatusCode: HttpStatusCode.BadGateway); - allLogsCount.ShouldBe(2); + allLogsCount.ShouldBe(2); - onlyLog1QueryResult.Count.ShouldBe(1); - onlyLog1QueryResult.FirstOrDefault().UserName.ShouldBe("Douglas"); - onlyLog1QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(2); + onlyLog1QueryResult.Count.ShouldBe(1); + onlyLog1QueryResult.FirstOrDefault().UserName.ShouldBe("Douglas"); + onlyLog1QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(2); - onlyLog2QueryResult.Count.ShouldBe(1); - onlyLog2QueryResult.FirstOrDefault().HttpStatusCode.ShouldBe((int?)HttpStatusCode.BadGateway); - onlyLog2QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(1); - } + onlyLog2QueryResult.Count.ShouldBe(1); + onlyLog2QueryResult.FirstOrDefault().HttpStatusCode.ShouldBe((int?)HttpStatusCode.BadGateway); + onlyLog2QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(1); } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs index 6ee8499567..f39de23cc9 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs @@ -1,19 +1,18 @@ using Volo.Abp.DependencyInjection; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AuditingTestDataBuilder : ITransientDependency { - public class AuditingTestDataBuilder : ITransientDependency + private readonly IAuditLogRepository _auditLogRepository; + + public AuditingTestDataBuilder(IAuditLogRepository auditLogRepository) { - private readonly IAuditLogRepository _auditLogRepository; + _auditLogRepository = auditLogRepository; + } - public AuditingTestDataBuilder(IAuditLogRepository auditLogRepository ) - { - _auditLogRepository = auditLogRepository; - } + public void Build() + { - public void Build() - { - - } } -} \ No newline at end of file +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs index 1f85576777..e62fec4e5e 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs @@ -1,13 +1,12 @@ using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.Modularity; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +[DependsOn( + typeof(AbpAuditLoggingEntityFrameworkCoreTestModule) + )] +public class AbpAuditLoggingTestModule : AbpModule { - [DependsOn( - typeof(AbpAuditLoggingEntityFrameworkCoreTestModule) - )] - public class AbpAuditLoggingTestModule : AbpModule - { - } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs index d505e838d7..551d5ff691 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs @@ -3,31 +3,30 @@ using System.Collections.Generic; using System.Linq; using Volo.Abp.AuditLogging.EntityFrameworkCore; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class AuditLogsTestBase : AuditLoggingTestBase { - public class AuditLogsTestBase : AuditLoggingTestBase + protected virtual void UsingDbContext(Action action) { - protected virtual void UsingDbContext(Action action) + using (var dbContext = GetRequiredService()) { - using (var dbContext = GetRequiredService()) - { - action.Invoke(dbContext); - } + action.Invoke(dbContext); } + } - protected virtual T UsingDbContext(Func action) + protected virtual T UsingDbContext(Func action) + { + using (var dbContext = GetRequiredService()) { - using (var dbContext = GetRequiredService()) - { - return action.Invoke(dbContext); - } + return action.Invoke(dbContext); } + } - protected List GetAuditLogsFromDbContext() - { - return UsingDbContext(context => - context.AuditLogs.IncludeDetails().ToList() - ); - } + protected List GetAuditLogsFromDbContext() + { + return UsingDbContext(context => + context.AuditLogs.IncludeDetails().ToList() + ); } -} \ No newline at end of file +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/MultiTenantAuditLog_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/MultiTenantAuditLog_Tests.cs index 6e92bc6f7f..990b3d75a5 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/MultiTenantAuditLog_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/MultiTenantAuditLog_Tests.cs @@ -5,72 +5,71 @@ using Shouldly; using Volo.Abp.Auditing; using Xunit; -namespace Volo.Abp.AuditLogging +namespace Volo.Abp.AuditLogging; + +public class MultiTenantAuditLog_Tests : AuditLogsTestBase { - public class MultiTenantAuditLog_Tests : AuditLogsTestBase - { - private readonly IAuditingManager _auditingManager; - private readonly IAuditLogRepository _auditLogRepository; + private readonly IAuditingManager _auditingManager; + private readonly IAuditLogRepository _auditLogRepository; - public MultiTenantAuditLog_Tests() - { - _auditingManager = GetRequiredService(); - _auditLogRepository = GetRequiredService(); - } + public MultiTenantAuditLog_Tests() + { + _auditingManager = GetRequiredService(); + _auditLogRepository = GetRequiredService(); + } - [Fact] - public async Task Should_Save_Audit_Logs_To_The_Tenant_Begins_The_Scope() - { - //Arrange + [Fact] + public async Task Should_Save_Audit_Logs_To_The_Tenant_Begins_The_Scope() + { + //Arrange - var applicationName = Guid.NewGuid().ToString(); - var tenantId = Guid.NewGuid(); - var entityId1 = Guid.NewGuid(); - var entityId2 = Guid.NewGuid(); + var applicationName = Guid.NewGuid().ToString(); + var tenantId = Guid.NewGuid(); + var entityId1 = Guid.NewGuid(); + var entityId2 = Guid.NewGuid(); - //Act + //Act - using (var scope = _auditingManager.BeginScope()) - { - _auditingManager.Current.Log.ApplicationName = applicationName; + using (var scope = _auditingManager.BeginScope()) + { + _auditingManager.Current.Log.ApplicationName = applicationName; - //Creating a host entity - _auditingManager.Current.Log.EntityChanges.Add( - new EntityChangeInfo - { - ChangeTime = DateTime.Now, - ChangeType = EntityChangeType.Created, - EntityEntry = new object(), - EntityId = entityId1.ToString(), - EntityTypeFullName = "TestEntity" - } - ); + //Creating a host entity + _auditingManager.Current.Log.EntityChanges.Add( + new EntityChangeInfo + { + ChangeTime = DateTime.Now, + ChangeType = EntityChangeType.Created, + EntityEntry = new object(), + EntityId = entityId1.ToString(), + EntityTypeFullName = "TestEntity" + } + ); - //Creating a tenant entity - _auditingManager.Current.Log.EntityChanges.Add( - new EntityChangeInfo - { - ChangeTime = DateTime.Now, - ChangeType = EntityChangeType.Created, - EntityEntry = new object(), - EntityId = entityId2.ToString(), - EntityTypeFullName = "TestEntity", - EntityTenantId = tenantId - } - ); + //Creating a tenant entity + _auditingManager.Current.Log.EntityChanges.Add( + new EntityChangeInfo + { + ChangeTime = DateTime.Now, + ChangeType = EntityChangeType.Created, + EntityEntry = new object(), + EntityId = entityId2.ToString(), + EntityTypeFullName = "TestEntity", + EntityTenantId = tenantId + } + ); - await scope.SaveAsync(); - } + await scope.SaveAsync(); + } - //Assert + //Assert - var auditLogs = await _auditLogRepository.GetListAsync(applicationName: applicationName, includeDetails: true); - auditLogs.Count.ShouldBe(1); - var auditLog = auditLogs.First(); - auditLog.EntityChanges.ShouldNotBeNull(); - auditLog.EntityChanges.Count.ShouldBe(2); - auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId1.ToString()); - auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId2.ToString()); - } + var auditLogs = await _auditLogRepository.GetListAsync(applicationName: applicationName, includeDetails: true); + auditLogs.Count.ShouldBe(1); + var auditLog = auditLogs.First(); + auditLog.EntityChanges.ShouldNotBeNull(); + auditLog.EntityChanges.Count.ShouldBe(2); + auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId1.ToString()); + auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId2.ToString()); } }