public void Add_and_update_entities_preGenerated_and_onAddGeneratedProperties_Generates_two_audit_and_one_audit_metaDataEntity()
        {
            using (var transaction = Connection.BeginTransaction())
            {
                PersonEntity           personEntity;
                AddressEntity          addressEntity1;
                AddressEntity          addressEntity2;
                PersonAttributesEntity personAttributesEntity1;
                PersonAttributesEntity personAttributesEntity2;
                //Arrange and Act
                using (var context = CreateContext(transaction))
                {
                    personEntity = PersonTestData.FirstOrDefault();
                    context.Persons.Add(personEntity);
                    context.SaveChanges();
                    personEntity           = context.Persons.FirstOrDefault();
                    personEntity.FirstName = $"{personEntity.FirstName}Modified";
                    context.SaveChanges();

                    addressEntity1 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.Addresses.Add(addressEntity1);
                    addressEntity2 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.Addresses.Add(addressEntity2);
                    context.SaveChanges();
                    addressEntity1            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity1.Type);
                    addressEntity1.PostalCode = 12345;
                    addressEntity2            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity2.Type);
                    addressEntity2.PostalCode = 54321;
                    context.SaveChanges();

                    personAttributesEntity1 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.PersonAttributes.Add(personAttributesEntity1);
                    personAttributesEntity2 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.PersonAttributes.Add(personAttributesEntity2);
                    context.SaveChanges();
                    personAttributesEntity1                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity1.Id);
                    personAttributesEntity2                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity2.Id);
                    personAttributesEntity1.DummyString    = "cahangingDummyString";
                    personAttributesEntity1.Attribute      = AttributeType.Profession;
                    personAttributesEntity1.AttributeValue = "Graphic Designer";
                    context.Remove(personAttributesEntity2);
                    context.SaveChanges();
                }

                using (var context = CreateContext(transaction))
                {
                    //Assert
                    List <AuditMetaDataEntity> auditMetaDatas = context.AuditMetaDatas.Include(amd => amd.AuditChanges).ToList();
                    List <AuditEntity>         audits         = context.Audits.Include(a => a.AuditMetaData).ToList();

                    Assert.Equal(5, auditMetaDatas.Count);
                    Assert.Equal(10, audits.Count);

                    /************************************************************************************************************************/

                    Assert.Single(auditMetaDatas,
                                  (x => x.DisplayName == "PersonEntity" && x.Schema == default && x.Table == "Persons" && x.SchemaTable == "Persons" &&
                                   x.ReadablePrimaryKey == "Id=caf3feb5-730e-40a3-9610-404a17b0deba" &&
                                   x.HashPrimaryKey == "Id=caf3feb5-730e-40a3-9610-404a17b0deba".ToGuidHash() &&
                                   x.AuditChanges.Count == 2));

                    Assert.Equal(2, auditMetaDatas.Count(x => x.DisplayName == "PersonAttributesEntity" && x.Schema == default && x.Table == "PersonAttributes" && x.SchemaTable == "PersonAttributes" &&
                                                         x.AuditChanges.Count == 2));

                    Assert.Single(auditMetaDatas,
                                  (x => x.DisplayName == "AddressEntity" && x.Schema == default && x.Table == "Addresses" && x.SchemaTable == "Addresses" &&
                                   x.ReadablePrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home" &&
                                   x.HashPrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home".ToGuidHash() &&
                                   x.AuditChanges.Count == 2));

                    Assert.Single(auditMetaDatas,
                                  (x => x.DisplayName == "AddressEntity" && x.Schema == default && x.Table == "Addresses" && x.SchemaTable == "Addresses" &&
                                   x.ReadablePrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work" &&
                                   x.HashPrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work".ToGuidHash() &&
                                   x.AuditChanges.Count == 2));

                    /************************************************************************************************************************/

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Added &&
                                   x.NewValues == "{\"Id\":\"caf3feb5-730e-40a3-9610-404a17b0deba\",\"FirstName\":\"Ofella\",\"Gender\":1,\"LastName\":\"Andrichuk\"}" &&
                                   x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"FirstName\":\"OfellaModified\"}" &&
                                   x.OldValues == "{\"FirstName\":\"Ofella\"}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Added &&
                                   x.NewValues == "{\"PersonId\":\"caf3feb5-730e-40a3-9610-404a17b0deba\",\"Type\":1,\"City\":\"Azteca\",\"HouseNumber\":\"844\",\"PostalCode\":50188,\"Street\":\"Vahlen\"}" &&
                                   x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Added &&
                                   x.NewValues == "{\"PersonId\":\"caf3feb5-730e-40a3-9610-404a17b0deba\",\"Type\":2,\"City\":\"Tawun\",\"HouseNumber\":\"7\",\"PostalCode\":32921,\"Street\":\"Welch\"}" &&
                                   x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"PostalCode\":54321}" &&
                                   x.OldValues == "{\"PostalCode\":50188}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"PostalCode\":12345}" &&
                                   x.OldValues == "{\"PostalCode\":32921}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Equal(2, audits.Count(x => x.AuditMetaData.DisplayName == "PersonAttributesEntity" && x.Id != default && x.EntityState == EntityState.Added &&
                                                 x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"Attribute\":2,\"AttributeValue\":\"Graphic Designer\"}" &&
                                   x.OldValues == "{\"Attribute\":1,\"AttributeValue\":\"Married\"}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Deleted &&
                                   x.NewValues == default && x.ByUser != default && x.DateTimeOffset != default));
                }
            }
        }
        public void Add_and_update_entities_preGenerated_and_onAddGeneratedProperties_Generates_two_audit_and_one_audit_metaDataEntity()
        {
            using (var transaction = Connection.BeginTransaction())
            {
                PersonEntity           personEntity;
                AddressEntity          addressEntity1;
                AddressEntity          addressEntity2;
                PersonAttributesEntity personAttributesEntity1;
                PersonAttributesEntity personAttributesEntity2;
                //Arrange and Act
                using (var context = CreateContext(transaction))
                {
                    personEntity = PersonTestData.FirstOrDefault();
                    context.Persons.Add(personEntity);
                    context.SaveChanges();
                    personEntity           = context.Persons.FirstOrDefault();
                    personEntity.FirstName = $"{personEntity.FirstName}Modified";
                    context.SaveChanges();

                    addressEntity1 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.Addresses.Add(addressEntity1);
                    addressEntity2 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.Addresses.Add(addressEntity2);
                    context.SaveChanges();
                    addressEntity1            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity1.Type);
                    addressEntity1.PostalCode = 12345;
                    addressEntity2            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity2.Type);
                    addressEntity2.PostalCode = 54321;
                    context.SaveChanges();

                    personAttributesEntity1 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.PersonAttributes.Add(personAttributesEntity1);
                    personAttributesEntity2 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.PersonAttributes.Add(personAttributesEntity2);
                    context.SaveChanges();
                    personAttributesEntity1                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity1.Id);
                    personAttributesEntity2                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity2.Id);
                    personAttributesEntity1.DummyString    = "cahangingDummyString";
                    personAttributesEntity1.Attribute      = AttributeType.Profession;
                    personAttributesEntity1.AttributeValue = "Graphic Designer";
                    context.Remove(personAttributesEntity2);
                    context.SaveChanges();
                }

                using (var context = CreateContext(transaction))
                {
                    //Assert
                    List <AuditMetaDataEntity> auditMetaDatas = context.AuditMetaDatas.Include(amd => amd.AuditChanges).ToList();
                    List <AuditEntity>         audits         = context.Audits.Include(a => a.AuditMetaData).ToList();

                    Assert.Equal(5, auditMetaDatas.Count);
                    Assert.Equal(10, audits.Count);

                    /************************************************************************************************************************/

                    Assert.Equal(2, auditMetaDatas[0].AuditChanges.Count);
                    Assert.Equal("AddressEntity", auditMetaDatas[0].DisplayName);
                    Assert.Null(auditMetaDatas[0].Schema);
                    Assert.Equal("Addresses", auditMetaDatas[0].Table);
                    Assert.Equal("Addresses", auditMetaDatas[0].SchemaTable);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home", auditMetaDatas[0].ReadablePrimaryKey);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home".ToGuidHash(), auditMetaDatas[0].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[1].AuditChanges.Count);
                    Assert.Equal("PersonEntity", auditMetaDatas[1].DisplayName);
                    Assert.Null(auditMetaDatas[1].Schema);
                    Assert.Equal("Persons", auditMetaDatas[1].Table);
                    Assert.Equal("Persons", auditMetaDatas[1].SchemaTable);
                    Assert.Equal("Id=caf3feb5-730e-40a3-9610-404a17b0deba", auditMetaDatas[1].ReadablePrimaryKey);
                    Assert.Equal("Id=caf3feb5-730e-40a3-9610-404a17b0deba".ToGuidHash(), auditMetaDatas[1].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[2].AuditChanges.Count);
                    Assert.Equal("AddressEntity", auditMetaDatas[2].DisplayName);
                    Assert.Null(auditMetaDatas[2].Schema);
                    Assert.Equal("Addresses", auditMetaDatas[2].Table);
                    Assert.Equal("Addresses", auditMetaDatas[2].SchemaTable);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work", auditMetaDatas[2].ReadablePrimaryKey);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work".ToGuidHash(), auditMetaDatas[2].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[3].AuditChanges.Count);
                    Assert.Equal("PersonAttributesEntity", auditMetaDatas[3].DisplayName);
                    Assert.Null(auditMetaDatas[3].Schema);
                    Assert.Equal("PersonAttributes", auditMetaDatas[3].Table);
                    Assert.Equal("PersonAttributes", auditMetaDatas[3].SchemaTable);
                    Assert.Equal("Id=2", auditMetaDatas[3].ReadablePrimaryKey);
                    Assert.Equal("Id=2".ToGuidHash(), auditMetaDatas[3].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[4].AuditChanges.Count);
                    Assert.Equal("PersonAttributesEntity", auditMetaDatas[4].DisplayName);
                    Assert.Null(auditMetaDatas[4].Schema);
                    Assert.Equal("PersonAttributes", auditMetaDatas[4].Table);
                    Assert.Equal("PersonAttributes", auditMetaDatas[4].SchemaTable);
                    Assert.Equal("Id=1", auditMetaDatas[4].ReadablePrimaryKey);
                    Assert.Equal("Id=1".ToGuidHash(), auditMetaDatas[4].HashPrimaryKey);

                    /************************************************************************************************************************/

                    Assert.NotNull(audits[0].AuditMetaData);
                    Assert.NotEqual(default, audits[0].Id);