Added Audit logging module

pull/395/head
Yunus Emre Kalkan 7 years ago
parent 858f57f7f4
commit 16b0bbbc05

@ -0,0 +1,74 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2035
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AuditLogging.Domain.Shared", "src\Volo.Abp.AuditLogging.Domain.Shared\Volo.Abp.AuditLogging.Domain.Shared.csproj", "{6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.Domain", "src\Volo.Abp.AuditLogging.Domain\Volo.Abp.AuditLogging.Domain.csproj", "{1878DA13-BFA0-4EEA-A268-272DC1C34B43}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.EntityFrameworkCore", "src\Volo.Abp.AuditLogging.EntityFrameworkCore\Volo.Abp.AuditLogging.EntityFrameworkCore.csproj", "{E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.MongoDB", "src\Volo.Abp.AuditLogging.MongoDB\Volo.Abp.AuditLogging.MongoDB.csproj", "{FA5154D2-26B2-4DBC-8A12-536A7323F3CD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CFAB155F-5255-4D99-94E2-3361D8EA4B15}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{971E31E2-FC37-41D3-8B6E-96848105C446}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.Tests", "test\Volo.Abp.AuditLogging.Tests\Volo.Abp.AuditLogging.Tests.csproj", "{9946C645-1234-49D9-98C1-152311FBBAB5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.TestBase", "test\Volo.Abp.AuditLogging.TestBase\Volo.Abp.AuditLogging.TestBase.csproj", "{6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.EntityFrameworkCore.Tests", "test\Volo.Abp.AuditLogging.EntityFrameworkCore.Tests\Volo.Abp.AuditLogging.EntityFrameworkCore.Tests.csproj", "{CBED3E11-0A33-4B56-A75C-A57D25C98C38}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Release|Any CPU.Build.0 = Release|Any CPU
{1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Release|Any CPU.Build.0 = Release|Any CPU
{E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Release|Any CPU.Build.0 = Release|Any CPU
{FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Release|Any CPU.Build.0 = Release|Any CPU
{9946C645-1234-49D9-98C1-152311FBBAB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9946C645-1234-49D9-98C1-152311FBBAB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9946C645-1234-49D9-98C1-152311FBBAB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9946C645-1234-49D9-98C1-152311FBBAB5}.Release|Any CPU.Build.0 = Release|Any CPU
{6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Release|Any CPU.Build.0 = Release|Any CPU
{CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6BFAB2F3-230A-45C2-8C94-4955CE3FF93E} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15}
{1878DA13-BFA0-4EEA-A268-272DC1C34B43} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15}
{E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15}
{FA5154D2-26B2-4DBC-8A12-536A7323F3CD} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15}
{9946C645-1234-49D9-98C1-152311FBBAB5} = {971E31E2-FC37-41D3-8B6E-96848105C446}
{6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83} = {971E31E2-FC37-41D3-8B6E-96848105C446}
{CBED3E11-0A33-4B56-A75C-A57D25C98C38} = {971E31E2-FC37-41D3-8B6E-96848105C446}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F36BAE5-A9CF-460C-8E7E-4580347F71F6}
EndGlobalSection
EndGlobal

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AuditLogging.Domain.Shared</AssemblyName>
<PackageId>Volo.Abp.AuditLogging.Domain.Shared</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Core\Volo.Abp.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,13 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
namespace Volo.Abp.AuditLogging
{
public class AbpAuditLoggingDomainSharedModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAssemblyOf<AbpAuditLoggingDomainSharedModule>();
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.AuditLogging
{
public class AuditLogActionConsts
{
public static int MaxServiceNameLength = 256;
public static int MaxMethodNameLength = 256;
public static int MaxParametersLength = 1024;
}
}

@ -0,0 +1,10 @@
namespace Volo.Abp.AuditLogging
{
public static class AuditLogConsts
{
public static int MaxClientIpAddressLength = 64;
public static int MaxClientNameLength = 128;
public static int MaxBrowserInfoLength = 512;
public static int MaxExceptionLength = 2000;
}
}

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AuditLogging.Domain</AssemblyName>
<PackageId>Volo.Abp.AuditLogging.Domain</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AuditLogging.Domain.Shared\Volo.Abp.AuditLogging.Domain.Shared.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Domain\Volo.Abp.Ddd.Domain.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Auditing\Volo.Abp.Auditing.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,10 @@

namespace Volo.Abp.AuditLogging
{
public static class AbpAuditLoggingConsts
{
public const string DefaultDbTablePrefix = "Abp";
public const string DefaultDbSchema = null;
}
}

@ -0,0 +1,18 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Auditing;
using Volo.Abp.Domain;
using Volo.Abp.Modularity;
namespace Volo.Abp.AuditLogging
{
[DependsOn(typeof(AbpAuditingModule))]
[DependsOn(typeof(AbpDddDomainModule))]
[DependsOn(typeof(AbpAuditLoggingDomainSharedModule))]
public class AbpAuditLoggingDomainModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAssemblyOf<AbpAuditLoggingDomainModule>();
}
}
}

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AuditLogging
{
public class AuditLog : Entity<Guid>, IHasExtraProperties, IMultiTenant
{
public virtual Guid? TenantId { get; set; }
public virtual Guid? UserId { get; set; }
public virtual Guid? ImpersonatorUserId { get; set; }
public virtual Guid? ImpersonatorTenantId { get; set; }
public virtual DateTime ExecutionTime { get; set; }
public virtual int ExecutionDuration { get; set; }
public virtual string ClientIpAddress { get; set; }
public virtual string ClientName { get; set; }
public virtual string BrowserInfo { get; set; }
public virtual List<string> Exceptions { get; }
public Dictionary<string, object> ExtraProperties { get; }
public ICollection<EntityChange> EntityChanges { get; }
public ICollection<AuditLogAction> Actions { get; set; }
protected AuditLog()
{
}
public AuditLog(AuditLogInfo auditInfo)
{
TenantId = auditInfo.TenantId;
UserId = auditInfo.UserId;
ExecutionTime = auditInfo.ExecutionTime;
ExecutionDuration = auditInfo.ExecutionDuration;
ClientIpAddress = auditInfo.ClientIpAddress;
ClientName = auditInfo.ClientName;
BrowserInfo = auditInfo.BrowserInfo;
ImpersonatorUserId = auditInfo.ImpersonatorUserId;
ImpersonatorTenantId = auditInfo.ImpersonatorTenantId;
ExtraProperties = auditInfo.ExtraProperties;
EntityChanges = auditInfo.EntityChanges.Select(e=> new EntityChange(e)).ToList();
Actions = auditInfo.Actions.Select(e=> new AuditLogAction(e)).ToList();
Exceptions = auditInfo.Exceptions.Select(e => e.ToString()).ToList();
}
}
}

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AuditLogging
{
public class AuditLogAction : Entity<Guid>
{
public virtual string ServiceName { get; set; }
public virtual string MethodName { get; set; }
public virtual string Parameters { get; set; }
public virtual DateTime ExecutionTime { get; set; }
public virtual int ExecutionDuration { get; set; }
public virtual Dictionary<string, object> ExtraProperties { get; }
protected AuditLogAction()
{
ExtraProperties = new Dictionary<string, object>();
}
public AuditLogAction(AuditLogActionInfo auditLogActionInfo)
{
ServiceName = auditLogActionInfo.ServiceName;
MethodName = auditLogActionInfo.MethodName;
Parameters = auditLogActionInfo.Parameters;
ExecutionTime = auditLogActionInfo.ExecutionTime;
ExecutionDuration = auditLogActionInfo.ExecutionDuration;
ExtraProperties = auditLogActionInfo.ExtraProperties;
}
}
}

@ -0,0 +1,21 @@
using System.Threading.Tasks;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AuditLogging
{
public class AuditingStore : IAuditingStore, ITransientDependency
{
private readonly IAuditLogRepository _auditLogRepository;
public AuditingStore(IAuditLogRepository auditLogRepository)
{
_auditLogRepository = auditLogRepository;
}
public async Task SaveAsync(AuditLogInfo auditInfo)
{
await _auditLogRepository.InsertAsync(new AuditLog(auditInfo));
}
}
}

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AuditLogging
{
public class EntityChange : Entity<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; set; }
public virtual DateTime ChangeTime { get; set; }
public virtual EntityChangeType ChangeType { get; set; }
public virtual string EntityId { get; set; }
public virtual string EntityTypeFullName { get; set; }
public ICollection<EntityPropertyChangeInfo> PropertyChanges { get; set; }
protected EntityChange()
{
}
public EntityChange(EntityChangeInfo entityChangeInfo)
{
TenantId = entityChangeInfo.TenantId;
ChangeTime = entityChangeInfo.ChangeTime;
ChangeType = entityChangeInfo.ChangeType;
EntityId = entityChangeInfo.EntityId;
EntityTypeFullName = entityChangeInfo.EntityTypeFullName;
PropertyChanges = entityChangeInfo.PropertyChanges;
}
}
}

@ -0,0 +1,9 @@
using System;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.AuditLogging
{
public interface IAuditLogRepository : IBasicRepository<AuditLog, Guid>
{
}
}

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AuditLogging.EntityFrameworkCore</AssemblyName>
<PackageId>Volo.Abp.AuditLogging.EntityFrameworkCore</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AuditLogging.Domain\Volo.Abp.AuditLogging.Domain.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{
[ConnectionStringName("AbpAuditLogging")]
public class AbpAuditLoggingDbContext : AbpDbContext<AbpAuditLoggingDbContext>, IAuditLoggingDbContext
{
public static string TablePrefix { get; set; } = AbpAuditLoggingConsts.DefaultDbTablePrefix;
public static string Schema { get; set; } = AbpAuditLoggingConsts.DefaultDbSchema;
public DbSet<AuditLog> AuditLogs { get; set; }
public DbSet<AuditLogAction> AuditLogAction { get; set; }
public DbSet<EntityChange> EntityChange { get; set; }
public AbpAuditLoggingDbContext(DbContextOptions<AbpAuditLoggingDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ConfigureAuditLogging(TablePrefix, Schema);
}
}
}

@ -0,0 +1,23 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{
[DependsOn(typeof(AbpAuditLoggingDomainModule))]
[DependsOn(typeof(AbpEntityFrameworkCoreModule))]
public class AbpAuditLoggingEntityFrameworkCoreModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<AbpAuditLoggingDbContext>(options =>
{
options.AddDefaultRepositories<IAuditLoggingDbContext>();
options.AddRepository<AuditLog, EfCoreAuditLogRepository>();
});
context.Services.AddAssemblyOf<AbpAuditLoggingEntityFrameworkCoreModule>();
}
}
}

@ -0,0 +1,61 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{
public static class AbpAuditLoggingtDbContextModelBuilderExtensions
{
public static void ConfigureAuditLogging(
[NotNull] this ModelBuilder builder,
[CanBeNull] string tablePrefix = AbpAuditLoggingConsts.DefaultDbTablePrefix,
[CanBeNull] string schema = AbpAuditLoggingConsts.DefaultDbSchema)
{
Check.NotNull(builder, nameof(builder));
if (tablePrefix == null)
{
tablePrefix = "";
}
builder.Entity<AuditLog>(b =>
{
b.ToTable(tablePrefix + "AuditLogs", schema);
b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength);
b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength);
b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength);
b.Property(x => x.Exceptions).HasMaxLength(AuditLogConsts.MaxExceptionLength);
b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime});
b.HasOne<EntityChange>().WithMany().HasForeignKey(x => x.EntityChanges);
b.HasOne<AuditLogAction>().WithMany().HasForeignKey(x => x.Actions);
});
builder.Entity<EntityChange>(b =>
{
b.ToTable(tablePrefix + "EntityChanges", schema);
b.Property(x => x.EntityTypeFullName).IsRequired();
b.Property(x => x.EntityId).IsRequired();
b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName});
});
builder.Entity<AuditLogAction>(b =>
{
b.ToTable(tablePrefix + "AuditLogActions", schema);
b.Property(x => x.ServiceName).HasMaxLength(AuditLogActionConsts.MaxServiceNameLength);
b.Property(x => x.MethodName).HasMaxLength(AuditLogActionConsts.MaxMethodNameLength);
b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength);
b.HasIndex(x => new { x.ServiceName, x.ExecutionTime});
});
}
}
}

@ -0,0 +1,15 @@
using System;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{
public class EfCoreAuditLogRepository : EfCoreRepository<IAuditLoggingDbContext, AuditLog, Guid>, IAuditLogRepository
{
public EfCoreAuditLogRepository(IDbContextProvider<IAuditLoggingDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
}
}

@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{
[ConnectionStringName("AbpAuditLogging")]
public interface IAuditLoggingDbContext : IEfCoreDbContext
{
DbSet<AuditLog> AuditLogs { get; set; }
DbSet<AuditLogAction> AuditLogAction { get; set; }
DbSet<EntityChange> EntityChange { get; set; }
}
}

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AuditLogging.MongoDB</AssemblyName>
<PackageId>Volo.Abp.AuditLogging.MongoDB</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AuditLogging.Domain\Volo.Abp.AuditLogging.Domain.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,21 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.Threading;
namespace Volo.Abp.AuditLogging.MongoDB
{
public static class AbpAuditLoggingBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<AuditLog>(map =>
{
map.AutoMap();
});
});
}
}
}

@ -0,0 +1,25 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB
{
[DependsOn(typeof(AbpAuditLoggingDomainModule))]
[DependsOn(typeof(AbpMongoDbModule))]
public class AbpAuditLoggingMongoDbModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpAuditLoggingBsonClassMap.Configure();
context.Services.AddMongoDbContext<AuditLoggingMongoDbContext>(options =>
{
options.AddDefaultRepositories<IAuditLoggingMongoDbContext>();
options.AddRepository<AuditLog, MongoAuditLogRepository>();
});
context.Services.AddAssemblyOf<AbpAuditLoggingMongoDbModule>();
}
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB
{
public static class AbpSettingManagementMongoDbContextExtensions
{
public static void ConfigureSettingManagement(
this IMongoModelBuilder builder,
Action<MongoModelBuilderConfigurationOptions> optionsAction = null)
{
Check.NotNull(builder, nameof(builder));
var options = new AuditLoggingMongoModelBuilderConfigurationOptions();
optionsAction?.Invoke(options);
builder.Entity<AuditLog>(b =>
{
b.CollectionName = options.CollectionPrefix + "Settings";
});
}
}
}

@ -0,0 +1,24 @@
using MongoDB.Driver;
using Volo.Abp.Data;
using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB
{
[ConnectionStringName("AbpAuditLogging")]
public class AuditLoggingMongoDbContext : AbpMongoDbContext, IAuditLoggingMongoDbContext
{
public static string CollectionPrefix { get; set; } = AbpAuditLoggingConsts.DefaultDbTablePrefix;
public IMongoCollection<AuditLog> AuditLogs => Collection<AuditLog>();
protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
base.CreateModel(modelBuilder);
modelBuilder.ConfigureSettingManagement(options =>
{
options.CollectionPrefix = CollectionPrefix;
});
}
}
}

@ -0,0 +1,13 @@
using JetBrains.Annotations;
using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB
{
public class AuditLoggingMongoModelBuilderConfigurationOptions : MongoModelBuilderConfigurationOptions
{
public AuditLoggingMongoModelBuilderConfigurationOptions([NotNull] string tablePrefix = AbpAuditLoggingConsts.DefaultDbTablePrefix)
: base(tablePrefix)
{
}
}
}

@ -0,0 +1,12 @@
using MongoDB.Driver;
using Volo.Abp.Data;
using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB
{
[ConnectionStringName("AbpAuditLogging")]
public interface IAuditLoggingMongoDbContext : IAbpMongoDbContext
{
IMongoCollection<AuditLog> AuditLogs { get; }
}
}

@ -0,0 +1,15 @@
using System;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB
{
public class MongoAuditLogRepository : MongoDbRepository<IAuditLoggingMongoDbContext, AuditLog, Guid>, IAuditLogRepository
{
public MongoAuditLogRepository(IMongoDbContextProvider<IAuditLoggingMongoDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
}
}

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AuditLogging.EntityFrameworkCore.Tests</AssemblyName>
<PackageId>Volo.Abp.AuditLogging.EntityFrameworkCore.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.AuditLogging.EntityFrameworkCore\Volo.Abp.AuditLogging.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Volo.Abp.AuditLogging.TestBase\Volo.Abp.AuditLogging.TestBase.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" />
</ItemGroup>
</Project>

@ -0,0 +1,40 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{
public class AbpAuditLoggingEntityFrameworkCoreTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();
context.Services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(abpDbContextConfigurationContext =>
{
abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection);
});
});
context.Services.AddAssemblyOf<AbpAuditLoggingEntityFrameworkCoreTestModule>();
}
private static SqliteConnection CreateDatabaseAndGetConnection()
{
var connection = new SqliteConnection("Data Source=:memory:");
connection.Open();
new AbpAuditLoggingDbContext(
new DbContextOptionsBuilder<AbpAuditLoggingDbContext>().UseSqlite(connection).Options
).GetService<IRelationalDatabaseCreator>().CreateTables();
return connection;
}
}
}

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AuditLogging.TestBase</AssemblyName>
<PackageId>Volo.Abp.AuditLogging.TestBase</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.AuditLogging.Domain\Volo.Abp.AuditLogging.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

@ -0,0 +1,33 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
namespace Volo.Abp.AuditLogging
{
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpTestBaseModule),
typeof(AbpAuditLoggingDomainModule))]
public class AbpAuditLoggingTestBaseModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAssemblyOf<AbpAuditLoggingTestBaseModule>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
.GetRequiredService <AuditingTestDataBuilder>()
.Build();
}
}
}
}

@ -0,0 +1,13 @@
using Volo.Abp.Modularity;
namespace Volo.Abp.AuditLogging
{
public class AuditLoggingTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

@ -0,0 +1,16 @@
using System;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AuditLogging
{
public class AuditingTestData : ISingletonDependency
{
public Guid UserId { get; } = Guid.NewGuid();
public Guid TenantId { get; } = Guid.NewGuid();
public Guid ImpersonatorUserId { get; } = Guid.NewGuid();
public Guid ImpersonatorTenantId { get; } = Guid.NewGuid();
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AuditLogging
{
public class AuditingTestDataBuilder : ITransientDependency
{
private readonly IAuditLogRepository _auditLogRepository;
private readonly AuditingTestData _auditingTestData;
public AuditingTestDataBuilder(IAuditLogRepository auditLogRepository, AuditingTestData auditingTestData )
{
_auditLogRepository = auditLogRepository;
_auditingTestData = auditingTestData;
}
public void Build()
{
}
}
}

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AuditLogging.Tests</AssemblyName>
<PackageId>Volo.Abp.AuditLogging.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AuditLogging.EntityFrameworkCore.Tests\Volo.Abp.AuditLogging.EntityFrameworkCore.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
</ItemGroup>
</Project>

@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Modularity;
namespace Volo.Abp.AuditLogging
{
[DependsOn(typeof(AbpAuditLoggingEntityFrameworkCoreTestModule))]
public class AbpAuditLoggingTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAssemblyOf<AbpAuditLoggingTestModule>();
}
}
}

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
namespace Volo.Abp.AuditLogging
{
public class AuditLogsTestBase : AuditLoggingTestBase<AbpAuditLoggingTestModule>
{
protected virtual void UsingDbContext(Action<IAuditLoggingDbContext> action)
{
using (var dbContext = GetRequiredService<IAuditLoggingDbContext>())
{
action.Invoke(dbContext);
}
}
protected virtual T UsingDbContext<T>(Func<IAuditLoggingDbContext, T> action)
{
using (var dbContext = GetRequiredService<IAuditLoggingDbContext>())
{
return action.Invoke(dbContext);
}
}
protected List<AuditLog> GetSAuditLogsFromDbContext()
{
return UsingDbContext(context =>
context.AuditLogs.ToList()
);
}
}
}

@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Auditing;
using Xunit;
namespace Volo.Abp.AuditLogging
{
public class AuditStore_Basic_Tests : AuditLogsTestBase
{
private readonly IAuditingStore _auditingStore;
public AuditStore_Basic_Tests()
{
_auditingStore = GetRequiredService<IAuditingStore>();
}
[Fact]
public async Task Should_Save_A_Audit_Log()
{
var auditLog = new AuditLogInfo()
{
TenantId = Guid.NewGuid(),
UserId = Guid.NewGuid(),
ImpersonatorUserId = Guid.NewGuid(),
ImpersonatorTenantId = Guid.NewGuid(),
ExecutionTime = DateTime.Today,
ExecutionDuration = 42,
ClientIpAddress = "153.1.7.61",
ClientName = "MyDesktop",
BrowserInfo = "Chrome",
//ServiceName = "SampleService2",
//MethodName = "SampleMethod2",
//Parameters = "SampleParameter",
//Exceptions = new Exceptions("something went wrong.")
};
await Assert.ThrowsAsync<AbpException>(
async () => await _auditingStore.SaveAsync(auditLog)
);
}
}
}
Loading…
Cancel
Save