Exemplo n.º 1
0
        public async Task <bool> DeleteEvent <TDataType>(TDataType data) where TDataType : DataEntity
        {
            using (_logger.BeginScope("{Operation} is logging a {Action} for {DataType}", nameof(FileAuditWorker),
                                      "delete event", typeof(TDataType).Name))
            {
                var currentLog = await ReadAllEvents <TDataType>(data.Id);

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

            Assert.AreEqual(2, auditLog.Entries.Count());
            Assert.AreEqual(AuditType.Delete, 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 == null && x.OldValue.Equals(data.Id)));
            Assert.IsTrue(auditLog.Entries.ElementAt(1).Changes.Any(x =>
                                                                    x.PropertyName == "Value1" && x.NewValue == null && x.OldValue.Equals(data.Value1)));
        }