Skip to content

Commit 3d5a665

Browse files
authored
chore: Modify the current time to Utc time
* chore: Modify the current time to Utc time * chore: fix warning * chore: Add GetCurrentTime method * chore: Adjust assignment
1 parent b5050cf commit 3d5a665

5 files changed

Lines changed: 50 additions & 21 deletions

File tree

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
namespace MASA.BuildingBlocks.DDD.Domain.Entities.Auditing;
1+
namespace MASA.BuildingBlocks.DDD.Domain.Entities.Auditing;
2+
23
public abstract class AuditEntity<TUserId> : Entity, IAuditEntity<TUserId>
34
{
45
public bool IsDeleted { get; set; }
56

67
public TUserId Creator { get; set; } = default!;
78

8-
public DateTime CreationTime { get; set; } = DateTime.Now;
9+
public DateTime CreationTime { get; set; }
910

1011
public TUserId Modifier { get; set; } = default!;
1112

12-
public DateTime ModificationTime { get; set; } = DateTime.Now;
13+
public DateTime ModificationTime { get; set; }
14+
15+
public AuditEntity() => Initialize();
16+
17+
public void Initialize()
18+
{
19+
this.CreationTime = this.GetCurrentTime();
20+
this.ModificationTime = this.GetCurrentTime();
21+
}
22+
23+
public virtual DateTime GetCurrentTime() => DateTime.UtcNow;
1324
}
1425

1526
public class AuditEntity<TKey, TUserId> : Entity<TKey>, IAuditEntity<TUserId>
@@ -18,9 +29,19 @@ public class AuditEntity<TKey, TUserId> : Entity<TKey>, IAuditEntity<TUserId>
1829

1930
public TUserId Creator { get; set; } = default!;
2031

21-
public DateTime CreationTime { get; set; } = DateTime.Now;
32+
public DateTime CreationTime { get; set; }
2233

2334
public TUserId Modifier { get; set; } = default!;
2435

25-
public DateTime ModificationTime { get; set; } = DateTime.Now;
36+
public DateTime ModificationTime { get; set; }
37+
38+
public AuditEntity() => Initialize();
39+
40+
public void Initialize()
41+
{
42+
this.CreationTime = this.GetCurrentTime();
43+
this.ModificationTime = this.GetCurrentTime();
44+
}
45+
46+
public virtual DateTime GetCurrentTime() => DateTime.UtcNow;
2647
}

‎src/Dispatcher/MASA.BuildingBlocks.Dispatcher.IntegrationEvents/Logs/IntegrationEventLog.cs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MASA.BuildingBlocks.Dispatcher.IntegrationEvents.Logs;
1+
namespace MASA.BuildingBlocks.Dispatcher.IntegrationEvents.Logs;
22
public class IntegrationEventLog
33
{
44
public Guid Id { get; private set; }
@@ -17,7 +17,7 @@ public class IntegrationEventLog
1717

1818
public int TimesSent { get; set; } = 0;
1919

20-
public DateTime CreationTime { get; private set; } = DateTime.Now;
20+
public DateTime CreationTime { get; private set; }
2121

2222
public string Content { get; private set; } = null!;
2323

@@ -26,6 +26,7 @@ public class IntegrationEventLog
2626
private IntegrationEventLog()
2727
{
2828
Id = Guid.NewGuid();
29+
Initialize();
2930
}
3031

3132
public IntegrationEventLog(IIntegrationEvent @event, Guid transactionId) : this()
@@ -39,6 +40,13 @@ public IntegrationEventLog(IIntegrationEvent @event, Guid transactionId) : this(
3940
TransactionId = transactionId;
4041
}
4142

43+
public void Initialize()
44+
{
45+
this.CreationTime = this.GetCurrentTime();
46+
}
47+
48+
public virtual DateTime GetCurrentTime() => DateTime.UtcNow;
49+
4250

4351
public IntegrationEventLog DeserializeJsonContent(Type type)
4452
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace MASA.BuildingBlocks.ReadWriteSpliting.CQRS.Queries;
22
public interface IQueryHandler<TCommand, TResult> : IEventHandler<TCommand>
3-
where TCommand : IQuery<TResult>
3+
where TCommand : IQuery<TResult> where TResult : notnull
44
{
5-
}
5+
}

‎test/MASA.BuildingBlocks.Configuration.Tests/TestProperties.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void TestEquals()
2222
});
2323
Assert.IsTrue(x.Equals(y));
2424
Assert.IsTrue(!x.Equals(null));
25-
Assert.IsTrue(!x.Equals(z));
25+
Assert.IsTrue(!x!.Equals(z));
2626
Assert.IsTrue(!z.Equals(x));
2727

2828
var w = new Properties(new Dictionary<string, string>()
@@ -54,7 +54,7 @@ public void TestOperator()
5454
Assert.IsTrue(x == y);
5555
Assert.IsTrue(x != z);
5656

57-
Properties m = null;
57+
Properties? m = null;
5858
Assert.IsTrue(m == null);
5959
Assert.IsTrue(null == m);
6060
Assert.IsFalse(null != m);

‎test/MASA.BuildingBlocks.DDD.Domain.Tests/TestEntity.cs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ public class TestEntity
66
[TestMethod]
77
public void TestToString()
88
{
9-
MasaEntity entity = new() { Id = Guid.Empty };
9+
MASAEntity entity = new() { Id = Guid.Empty };
1010
Assert.AreEqual("MasaEntity:Id=00000000-0000-0000-0000-000000000000", entity.ToString());
1111
}
1212

1313
[TestMethod]
1414
public void TestEquals()
1515
{
1616
var id = Guid.NewGuid();
17-
MasaEntity x = new() { Id = id };
18-
MasaEntity y = new() { Id = id };
17+
MASAEntity x = new() { Id = id };
18+
MASAEntity y = new() { Id = id };
1919

2020
Assert.IsTrue(x.Equals(y));
2121
Assert.IsTrue(x.Equals((object)y));
@@ -25,8 +25,8 @@ public void TestEquals()
2525
public void TestGetHashCode()
2626
{
2727
var id = Guid.NewGuid();
28-
MasaEntity x = new() { Id = id };
29-
MasaEntity y = new() { Id = id };
28+
MASAEntity x = new() { Id = id };
29+
MASAEntity y = new() { Id = id };
3030

3131
Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
3232
}
@@ -35,14 +35,14 @@ public void TestGetHashCode()
3535
public void TestOperator()
3636
{
3737
var id = Guid.NewGuid();
38-
MasaEntity x = new() { Id = id };
39-
MasaEntity y = new() { Id = id };
40-
MasaEntity z = new() { Id = Guid.NewGuid() };
38+
MASAEntity x = new() { Id = id };
39+
MASAEntity y = new() { Id = id };
40+
MASAEntity z = new() { Id = Guid.NewGuid() };
4141

4242
Assert.IsTrue(x == y);
4343
Assert.IsTrue(x != z);
4444

45-
MasaEntity m = null;
45+
MASAEntity? m = null;
4646
Assert.IsTrue(m == null);
4747
Assert.IsTrue(null == m);
4848
Assert.IsFalse(null != m);
@@ -51,7 +51,7 @@ public void TestOperator()
5151
Assert.IsTrue(null != x);
5252
}
5353

54-
public class MasaEntity : Entity<Guid>
54+
public class MASAEntity : Entity<Guid>
5555
{
5656
}
5757
}

0 commit comments

Comments
 (0)