Beispiel #1
0
        public void DeleteWithoutVersionNo()
        {
            Fixture.CleanupAuditTable();

            City city = new City
            {
                Name      = "Ahmedabad",
                State     = "GU",
                Latitude  = 10.65m,
                Longitude = 11.50m,
                CreatedBy = Fixture.CurrentUserId
            };

            Repository <City> cityRepo = new Repository <City>(Fixture.Connection);
            var id = cityRepo.Add(city);

            Assert.True(cityRepo.Delete(id, Fixture.CurrentUserId));

            city = new City();
            city = cityRepo.ReadOne(id);
            Assert.Equal(2, city.VersionNo);

            //read version no from history
            AuditTrailRepository <City> atRepo   = new AuditTrailRepository <City>(Fixture.Connection);
            List <AuditTrail>           lstAudit = atRepo.ReadAllAuditTrail(id).Cast <AuditTrail>().ToList();

            Assert.Equal(1, lstAudit[0].RecordVersionNo);
            Assert.Equal(2, lstAudit[1].RecordVersionNo);
        }
Beispiel #2
0
        public void AuditTrailNoEntityBase()
        {
            Employee emp = new Employee
            {
                EmployeeName = "Rajesh",
                Department   = "AC",
                DOB          = null,
            };

            Fixture.CleanupAuditTable();

            Repository <Employee> empRepo = new Repository <Employee>(Fixture.Connection);

            //add record
            var id = empRepo.Add(emp);

            //read history
            var empHistory = empRepo.ReadHistory(id);

            Assert.Single(empHistory);
            Assert.Equal("Rajesh", empHistory.First().EmployeeName);
            Assert.Equal("AC", empHistory.First().Department);
            Assert.Null(empHistory.First().DOB);

            AuditTrailRepository <Employee> auditRepo = new AuditTrailRepository <Employee>(Fixture.Connection);

            //read history
            var history = auditRepo.ReadAllAuditTrail(id);

            Assert.Single(history);
            Assert.Equal("Rajesh", history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "EmployeeName").NewValue);
            Assert.Equal("AC", history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "Department").NewValue);
            Assert.Null(history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "DOB"));
        }
Beispiel #3
0
        public void InsertUpdateDeleteUpdateDelete()
        {
            //cleanup audit table

            Fixture.CleanupAuditTable();

            Country cnt = new Country()
            {
                Name         = "India",
                ShortCode    = "IN",
                Independence = new DateTime(1947, 8, 15),
                Continent    = EnumContinent.Asia,
                CreatedBy    = Fixture.CurrentUserId
            };

            Repository <Country> contryRepo = new Repository <Country>(Fixture.Connection);
            var id = contryRepo.Add(cnt);

            cnt = contryRepo.ReadOne(id);
            Assert.Equal(EnumContinent.Asia, cnt.Continent);

            cnt.UpdatedBy = 2;
            //should not update as no changes were made
            Assert.True(contryRepo.Update(cnt));

            //try to delete without UpdatedBy column
            Exception ex = Assert.Throws <MissingFieldException>(() => contryRepo.Delete(id));

            Assert.True(contryRepo.Delete(id, 2));
            cnt.VersionNo++;
            Assert.True(contryRepo.Update(cnt)); //this will not be updated as isactive will not be updated
            Assert.True(contryRepo.Delete(id, 2));

            AuditTrailRepository <Country> adtRepo = new AuditTrailRepository <Country>(Fixture.Connection);

            Assert.Equal(3, adtRepo.Count());

            List <AuditTrail> lstAudit = adtRepo.ReadAll().Cast <AuditTrail>().ToList();

            Assert.Equal(1, lstAudit[0].RecordVersionNo);
            Assert.Equal(1, lstAudit[0].CreatedBy);

            Assert.Equal(2, lstAudit[1].RecordVersionNo);
            Assert.Equal(2, lstAudit[1].CreatedBy);

            Assert.Equal(3, lstAudit[2].RecordVersionNo);
            Assert.Equal(2, lstAudit[2].CreatedBy);
        }
Beispiel #4
0
        public void AuditTrailPipeInText()
        {
            Fixture.CleanupAuditTable();

            Repository <Employee> empRepo = new Repository <Employee>(Fixture.Connection);
            Employee emp = new Employee
            {
                EmployeeName = "Rajesh",
                Department   = "AC|IT",
                DOB          = new DateTime(1980, 7, 22),
            };

            //add record
            var id = empRepo.Add(emp);

            //update record
            emp.Department = "IT";
            emp.DOB        = new DateTime(1983, 7, 22);
            empRepo.Update(emp);

            //read history
            var empHistory = empRepo.ReadHistory(id);

            Assert.Equal(2, empHistory.Count());
            Assert.Equal("Rajesh", empHistory.First().EmployeeName);
            Assert.Equal("AC|IT", empHistory.First().Department);
            Assert.Equal(new DateTime(1980, 7, 22), empHistory.First().DOB);

            Assert.Equal("IT", empHistory.ElementAt(1).Department);
            Assert.Equal(new DateTime(1983, 7, 22), empHistory.ElementAt(1).DOB);

            AuditTrailRepository <Employee> auditRepo = new AuditTrailRepository <Employee>(Fixture.Connection);
            //read audittrail
            var history = auditRepo.ReadAllAuditTrail(id);

            Assert.Equal(2, history.Count);

            Assert.Equal("Rajesh", history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "EmployeeName").NewValue);
            Assert.Equal("AC|IT", history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "Department").NewValue);
            Assert.Equal(new DateTime(1980, 7, 22), DateTime.Parse(history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "DOB").NewValue));

            Assert.Equal("IT", history.ElementAt(1).lstAuditTrailDetail.Find(p => p.ColumnName == "Department").NewValue);
            Assert.Equal("AC|IT", history.ElementAt(1).lstAuditTrailDetail.Find(p => p.ColumnName == "Department").OldValue);

            Assert.Equal(new DateTime(1983, 7, 22), DateTime.Parse(history.ElementAt(1).lstAuditTrailDetail.Find(p => p.ColumnName == "DOB").NewValue));
            Assert.Equal(new DateTime(1980, 7, 22), DateTime.Parse(history.ElementAt(1).lstAuditTrailDetail.Find(p => p.ColumnName == "DOB").OldValue));
        }
Beispiel #5
0
        public void AuditTrailOldNewforExistingRecords()
        {
            Fixture.CleanupAuditTable();

            Employee emp = new Employee
            {
                EmployeeId   = 1,
                EmployeeName = "Rajesh",
                Department   = "AC",
                DOB          = null,
            };

            //add values as it was earlier
            AuditTrail audit = new AuditTrail
            {
                lstAuditTrailDetail = new System.Collections.Generic.List <IAuditTrailDetail>()
                {
                    new AuditTrailDetail()
                    {
                        ColumnName = "EmployeeName",
                        NewValue   = "\"Rajesh\"",
                    },
                    new AuditTrailDetail()
                    {
                        ColumnName = "Department",
                        NewValue   = "\"AC\"",
                    }
                }
            };

            AuditTrailRepository <Employee> auditRepo = new AuditTrailRepository <Employee>(Fixture.Connection);

            auditRepo.Add(emp, RecordOperationEnum.Insert, audit);

            audit = new AuditTrail
            {
                lstAuditTrailDetail = new System.Collections.Generic.List <IAuditTrailDetail>()
                {
                    new AuditTrailDetail()
                    {
                        ColumnName = "EmployeeName",
                        NewValue   = "\"Rakesh\"",
                        OldValue   = "\"Rajesh\"",
                    },
                    new AuditTrailDetail()
                    {
                        ColumnName = "Department",
                        NewValue   = "\"IT\"",
                        OldValue   = "\"AC\"",
                    },
                    new AuditTrailDetail()
                    {
                        ColumnName = "DOB",
                        NewValue   = "1980-7-22"
                    }
                }
            };
            auditRepo.Add(emp, RecordOperationEnum.Update, audit);

            //read history
            var history = auditRepo.ReadAllAuditTrail(1);

            Assert.Equal(2, history.Count);
            Assert.Equal("Rajesh", history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "EmployeeName").NewValue);
            Assert.Equal("AC", history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "Department").NewValue);
            Assert.Null(history.First().lstAuditTrailDetail.Find(p => p.ColumnName == "DOB"));
        }