Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,18 @@ private bool ShouldSaveEntityHistory(EntityEntry entityEntry, bool defaultValue
return true;
}

if (entityType.IsDefined(typeof(DisableAuditingAttribute), true))
if (entityEntry.Metadata.GetProperties()
.Any(p => p.PropertyInfo?.IsDefined(typeof(AuditedAttribute)) ?? false))
{
return false;
return true;
}

if (Options.EntityHistorySelectors.Any(selector => selector.Predicate(entityType)))
if (entityType.IsDefined(typeof(DisableAuditingAttribute), true))
{
return true;
return false;
}

var properties = entityEntry.Metadata.GetProperties();
if (properties.Any(p => p.PropertyInfo?.IsDefined(typeof(AuditedAttribute)) ?? false))
if (Options.EntityHistorySelectors.Any(selector => selector.Predicate(entityType)))
{
return true;
}
Expand Down Expand Up @@ -265,8 +265,7 @@ private bool ShouldSavePropertyHistory(PropertyEntry propertyEntry, bool default
}
}

var isModified = !(propertyEntry.OriginalValue?.Equals(propertyEntry.CurrentValue) ?? propertyEntry.CurrentValue == null);
if (isModified)
if (propertyEntry.IsModified)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<ProjectReference Include="..\..\src\Volo.Abp.Auditing\Volo.Abp.Auditing.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Volo.Abp.Testing;

namespace Volo.Abp.Auditing
{
public class AbpAuditingTestBase : AbpIntegratedTest<AbpAuditingTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Auditing.App.Entities;
using Volo.Abp.Auditing.App.EntityFrameworkCore;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;

namespace Volo.Abp.Auditing
{
[DependsOn(
typeof(AbpTestBaseModule),
typeof(AbpAutofacModule),
typeof(AbpEntityFrameworkCoreModule)
)]
public class AbpAuditingTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<AbpAuditingTestDbContext>(options =>
{
options.AddDefaultRepositories(true);
});

var sqliteConnection = CreateDatabaseAndGetConnection();

Configure<AbpDbContextOptions>(options =>
{
options.Configure(abpDbContextConfigurationContext =>
{
abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection);
});
});

Configure<AbpAuditingOptions>(options =>
{
options.EntityHistorySelectors.Add(
new NamedTypeSelector(
"AppEntityWithSelector",
type => type == typeof(AppEntityWithSelector))
);
});

context.Services.AddType<Auditing_Tests.MyAuditedObject1>();
}

private static SqliteConnection CreateDatabaseAndGetConnection()
{
var connection = new SqliteConnection("Data Source=:memory:");
connection.Open();

using (var context = new AbpAuditingTestDbContext(new DbContextOptionsBuilder<AbpAuditingTestDbContext>()
.UseSqlite(connection).Options))
{
context.GetService<IRelationalDatabaseCreator>().CreateTables();
}

return connection;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;

namespace Volo.Abp.Auditing.App.Entities
{
[Audited]
public class AppEntityWithAudited : AggregateRoot<Guid>
{
protected AppEntityWithAudited()
{

}

public AppEntityWithAudited(Guid id, string name)
: base(id)
{
Name = name;
}

public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Volo.Abp.Domain.Entities;

namespace Volo.Abp.Auditing.App.Entities
{
[Audited]
public class AppEntityWithAuditedAndPropertyHasDisableAuditing : AggregateRoot<Guid>
{
protected AppEntityWithAuditedAndPropertyHasDisableAuditing()
{

}

public AppEntityWithAuditedAndPropertyHasDisableAuditing(Guid id, string name, string name2)
: base(id)
{
Name = name;
Name2 = name2;
}

public string Name { get; set; }

[DisableAuditing]
public string Name2 { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;

namespace Volo.Abp.Auditing.App.Entities
{
[DisableAuditing]
public class AppEntityWithDisableAuditing : AggregateRoot<Guid>
{
protected AppEntityWithDisableAuditing()
{

}

public AppEntityWithDisableAuditing(Guid id, string name)
: base(id)
{
Name = name;
}

public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Volo.Abp.Domain.Entities;

namespace Volo.Abp.Auditing.App.Entities
{
[DisableAuditing]
public class AppEntityWithDisableAuditingAndPropertyHasAudited : AggregateRoot<Guid>
{
protected AppEntityWithDisableAuditingAndPropertyHasAudited()
{

}

public AppEntityWithDisableAuditingAndPropertyHasAudited(Guid id, string name, string name2)
: base(id)
{
Name = name;
Name2 = name2;
}

[Audited]
public string Name { get; set; }

public string Name2 { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;

namespace Volo.Abp.Auditing.App.Entities
{
public class AppEntityWithPropertyHasAudited : AggregateRoot<Guid>
{
protected AppEntityWithPropertyHasAudited()
{

}

public AppEntityWithPropertyHasAudited(Guid id, string name)
: base(id)
{
Name = name;
}

[Audited]
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Volo.Abp.Domain.Entities;

namespace Volo.Abp.Auditing.App.Entities
{
public class AppEntityWithSelector : AggregateRoot<Guid>
{
public AppEntityWithSelector(Guid id, string name)
: base(id)
{
Name = name;
}

public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Auditing.App.Entities;
using Volo.Abp.EntityFrameworkCore;

namespace Volo.Abp.Auditing.App.EntityFrameworkCore
{
public class AbpAuditingTestDbContext : AbpDbContext<AbpAuditingTestDbContext>
{
public DbSet<AppEntityWithAudited> AppEntityWithAudited { get; set; }

public DbSet<AppEntityWithAuditedAndPropertyHasDisableAuditing> AppEntityWithAuditedAndPropertyHasDisableAuditing { get; set; }

public DbSet<AppEntityWithDisableAuditing> AppEntityWithDisableAuditing { get; set; }

public DbSet<AppEntityWithDisableAuditingAndPropertyHasAudited> AppEntityWithDisableAuditingAndPropertyHasAudited { get; set; }

public DbSet<AppEntityWithPropertyHasAudited> AppEntityWithPropertyHasAudited { get; set; }

public DbSet<AppEntityWithSelector> AppEntityWithSelector { get; set; }

public AbpAuditingTestDbContext(DbContextOptions<AbpAuditingTestDbContext> options)
: base(options)
{

}
}
}

This file was deleted.

Loading