Skip to content

Commit c7a0b4a

Browse files
authored
Merge pull request #16 from coderstrong/develop
Update repository remove audit in repository
2 parents cf327ee + cd2ef23 commit c7a0b4a

File tree

14 files changed

+158
-741
lines changed

14 files changed

+158
-741
lines changed

src/MakeSimple.SharedKernel.Infrastructure.Test/Entities/EntityTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace MakeSimple.SharedKernel.Infrastructure.Test.Entities
99
{
1010
public class EntityTest
1111
{
12-
private readonly IAuditRepository<MyDBContext, Address> _repositoryGeneric;
12+
private readonly IRepository<MyDBContext, Address> _repositoryGeneric;
1313

1414
public EntityTest()
1515
{
1616
var config = new MapperConfiguration(cfg => cfg.CreateMap<Address, AddressDto>().ReverseMap());
17-
_repositoryGeneric = new EfAuditRepositoryGeneric<MyDBContext, Address>(
18-
new MyDBContext(), SieveMock.Create(), new Mapper(config), DummyDataForTest.CreateHttpContext());
17+
_repositoryGeneric = new EfRepositoryGeneric<MyDBContext, Address>(
18+
new MyDBContext(), SieveMock.Create(), new Mapper(config));
1919
}
2020

2121
//[Fact]

src/MakeSimple.SharedKernel.Infrastructure.Test/Mocks/MyDBContext.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using MakeSimple.SharedKernel.Contract;
22
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.ChangeTracking;
34
using Microsoft.EntityFrameworkCore.Metadata.Builders;
45
using Sieve.Attributes;
56
using System;
@@ -10,7 +11,7 @@
1011

1112
namespace MakeSimple.SharedKernel.Infrastructure.Test.Mocks
1213
{
13-
public class Address : AuditEntity
14+
public class Address : AuditableEntity
1415
{
1516
[Sieve(CanFilter = true, CanSort = true)]
1617
[Key]
@@ -49,6 +50,28 @@ public class MyDBContext : DbContext, IUnitOfWork
4950

5051
public async Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default)
5152
{
53+
foreach (EntityEntry<Entity> entry in ChangeTracker.Entries<Entity>())
54+
{
55+
switch (entry.State)
56+
{
57+
case EntityState.Added:
58+
if (entry.Entity is AuditableEntity addAuditable)
59+
{
60+
addAuditable.CreatedBy = "test";
61+
}
62+
entry.Entity.CreatedAt = DateTime.Now;
63+
break;
64+
65+
case EntityState.Modified:
66+
if (entry.Entity is AuditableEntity modifiAuditable)
67+
{
68+
modifiAuditable.LastModifiedBy = "test";
69+
}
70+
entry.Entity.LastModifiedAt = DateTime.Now;
71+
break;
72+
}
73+
}
74+
5275
return (await SaveChangesAsync(cancellationToken)) > 0;
5376
}
5477

@@ -79,7 +102,7 @@ public class Student : Entity
79102
public string Name { get; set; }
80103
}
81104

82-
public class User : AuditEntity
105+
public class User : AuditableEntity
83106
{
84107
[Key]
85108
public Guid Id { get; set; }
@@ -118,7 +141,7 @@ public class StudentDto
118141
public string Name { get; set; }
119142
}
120143

121-
public class UserDto : AuditEntity
144+
public class UserDto : AuditableEntity
122145
{
123146
public Guid Id { get; set; }
124147
public ICollection<Address> Address { get; set; }

0 commit comments

Comments
 (0)