Exemplo n.º 1
0
 public Task <bool> CreationEvent <TDataType>(TDataType data) where TDataType : DataEntity
 {
     using (_logger.BeginScope("{Operation} is logging a {Action} for {DataType}", nameof(FileAuditWorker),
                               "create event", typeof(TDataType).Name))
     {
         return(WriteEvent(GetFileName <TDataType>(data.Id), MaxAttempts <TDataType>(),
                           () => AuditGenerator.NewLog(data)));
     }
 }
Exemplo n.º 2
0
        public async Task <bool> RollbackEvent <TDataType>(TDataType data) where TDataType : DataEntity
        {
            using (_logger.BeginScope("{Operation} is logging a {Action} for {DataType}", nameof(FileAuditWorker),
                                      "rollback event", typeof(TDataType).Name))
            {
                var currentLog = await ReadAllEvents <TDataType>(data.Id);

                return(await WriteEvent(GetFileName <TDataType>(data.Id), MaxAttempts <TDataType>(),
                                        () => AuditGenerator.RollbackLog(data, currentLog)));
            }
        }
Exemplo n.º 3
0
        public void UndeleteLog()
        {
            var data = new AuditedEntity
            {
                Id     = Randomizer.Next(),
                Value1 = Randomizer.GetString()
            };
            var auditLog = AuditGenerator.UndeleteLog(data, AuditGenerator.NewLog(data));

            Assert.AreEqual(2, auditLog.Entries.Count());
            Assert.AreEqual(AuditType.Undelete, auditLog.Entries.ElementAt(1).Type);
            Assert.AreEqual(2, auditLog.Entries.ElementAt(1).Changes.Count());
            Assert.IsTrue(auditLog.Entries.ElementAt(1).Changes.Any(x =>
                                                                    x.PropertyName == "Id" && x.NewValue.Equals(data.Id) && x.OldValue == null));
            Assert.IsTrue(auditLog.Entries.ElementAt(1).Changes.Any(x =>
                                                                    x.PropertyName == "Value1" && x.NewValue.Equals(data.Value1) && x.OldValue == null));
        }
Exemplo n.º 4
0
 public void Setup()
 {
     AuditGenerator = new AuditGenerator();
     Randomizer     = Randomizer.CreateRandomizer();
 }