Exemplo n.º 1
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.º 2
0
        public void RollbackLog()
        {
            var data = new AuditedEntity
            {
                Id     = Randomizer.Next(),
                Value1 = Randomizer.GetString()
            };
            var auditLog = AuditGenerator.RollbackLog(data, AuditGenerator.NewLog(data));

            Assert.AreEqual(2, auditLog.Entries.Count());
            Assert.AreEqual(AuditType.Rollback, 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));
        }