Esempio n. 1
0
        private void FixupOrgUnit(OrgUnit previousValue)
        {
            if (previousValue != null && previousValue.OrgUnitSchedules.Contains(this))
            {
                previousValue.OrgUnitSchedules.Remove(this);
            }

            if (OrgUnit != null)
            {
                if (!OrgUnit.OrgUnitSchedules.Contains(this))
                {
                    OrgUnit.OrgUnitSchedules.Add(this);
                }
                if (OrgUnitId != OrgUnit.Id)
                {
                    OrgUnitId = OrgUnit.Id;
                }
            }
        }
Esempio n. 2
-2
        public void tracks_properties_with_foreign_key()
        {
            //setup
            decimal openHours = 10;
            decimal openTime = 20;
            var orgUnitSchedule = new OrgUnitSchedule();
            orgUnitSchedule.OpenHours = openHours;
            orgUnitSchedule.OpenTime = openTime;
            var orgUnitName = Guid.NewGuid().ToString();
            var orgUnit = new OrgUnit();
            orgUnit.Name = orgUnitName;
            orgUnitSchedule.OrgUnit = orgUnit;

            var context = CreateObjectContext();
            context.OrgUnitSchedules.AddObject(orgUnitSchedule);
            var objectStateEntry = context.ObjectStateManager.GetObjectStateEntry(orgUnitSchedule);
            context.SaveChanges();

            //act
            var subject = new EntityAddedAudit(objectStateEntry);
            subject.TrackPropertiesAfterAdd();

            //assert
            Assert.AreNotEqual(noId, subject.EntityIdentifier);

            var openHoursPropertyAudit = subject.AuditEntityProperties.Where(p => p.PropertyName == "OpenHours").SingleOrDefault();
            Assert.IsNotNull(openHoursPropertyAudit);
            Assert.IsNull(openHoursPropertyAudit.OriginalValue);
            Assert.AreEqual(openHours.ToString(), openHoursPropertyAudit.NewValue);

            var openTimePropertyAudit = subject.AuditEntityProperties.Where(p => p.PropertyName == "OpenTime").SingleOrDefault();
            Assert.IsNotNull(openTimePropertyAudit);
            Assert.IsNull(openTimePropertyAudit.OriginalValue);
            Assert.AreEqual(openTime.ToString(), openTimePropertyAudit.NewValue);

            var versionPropertyAudit = subject.AuditEntityProperties.Where(p => p.PropertyName == "Version").SingleOrDefault();
            Assert.IsNull(versionPropertyAudit);

            var locationIdPropertyAudit = subject.AuditEntityProperties.Where(p => p.PropertyName == "OrgUnitId").SingleOrDefault();
            Assert.IsNotNull(locationIdPropertyAudit);
            Assert.IsNull(locationIdPropertyAudit.OriginalValue);
            Assert.AreNotEqual(noId, locationIdPropertyAudit.NewValue);
        }