Пример #1
0
        public void TestCopyAlteredNotSavedDataObjectMasterPropertiesNullMaster()
        {
            // Arrange.
            var oldValue  = "OldValue";
            var newValue  = "NewValue";
            var auditView = new View {
                DefineClassType = typeof(AuditAgregatorObject)
            };

            auditView.AddProperties(ownProperties.ToArray());
            auditView.AddProperties(masterProperties.ToArray());
            auditView.AddProperties(masterMasterProperties.ToArray());
            var auditViewPropertyNames = auditView.Properties.Select(x => x.Name).ToList();

            var testView = new View {
                DefineClassType = typeof(AuditAgregatorObject)
            };

            testView.AddProperties(testOwnProperties.ToArray());
            var testViewPropertyNames = testView.Properties.Select(x => x.Name).ToList();

            var expectedList          = auditViewPropertyNames.Union(testViewPropertyNames).Distinct().ToList();
            var expectedPropertyCount = expectedList.Count;

            var masterObject       = new AuditMasterObject();
            var masterMasterObject = new AuditMasterMasterObject();
            var oldObject          = new AuditAgregatorObject();

            oldObject.SetExistObjectPrimaryKey(Guid.NewGuid());
            oldObject.MasterObject = masterObject;
            oldObject.MasterObject.MasterObject = masterMasterObject;
            SetViewProperties(oldObject, auditView, oldValue);
            oldObject.SetLoadedProperties(ownProperties.ToArray());
            oldObject.MasterObject.SetLoadedProperties(ownProperties.ToArray());
            oldObject.MasterObject.MasterObject.SetLoadedProperties(ownProperties.ToArray());

            var newObject = new AuditAgregatorObject();

            newObject.SetExistObjectPrimaryKey(Guid.NewGuid());
            SetViewProperties(newObject, testView, newValue);
            newObject.SetLoadedProperties(testOwnProperties.ToArray());

            // Act.
            var loadedProperties = AuditService.CopyAlteredNotSavedDataObject(oldObject, newObject, auditView, null, null);

            // Assert.
            foreach (var auditProperty in auditView.Properties)
            {
                var expectedValue = testViewPropertyNames.Contains(auditProperty.Name) ? newValue : oldValue;
                var actualValue   = Information.GetPropValueByName(newObject, auditProperty.Name);

                if (!(actualValue is DataObject) && Information.IsStoredProperty(typeof(AuditAgregatorObject), auditProperty.Name))
                {
                    Assert.Equal(expectedValue, actualValue);
                }
            }

            Assert.Equal(expectedPropertyCount, loadedProperties.Count);
            Assert.Equal(expectedPropertyCount, expectedList.Union(loadedProperties).Distinct().Count());
        }
Пример #2
0
        public void TestCopyAlteredNotSavedDataObjectMasterPropertiesWithLoad()
        {
            // Arrange.
            var oldValue  = "OldValue";
            var newValue  = "NewValue";
            var auditView = new View {
                DefineClassType = typeof(AuditAgregatorObject)
            };

            auditView.AddProperties(ownProperties.ToArray());
            auditView.AddProperties(masterProperties.ToArray());
            var auditViewPropertyNames = auditView.Properties.Select(x => x.Name).ToList();

            var testView = new View {
                DefineClassType = typeof(AuditAgregatorObject)
            };

            testView.AddProperties(testOwnProperties.ToArray());
            testView.AddProperties(testMasterOwnProperties.ToArray());
            var testViewPropertyNames = testView.Properties.Select(x => x.Name).ToList();

            var expectedList          = auditViewPropertyNames.Union(testViewPropertyNames).Distinct().ToList();
            var expectedPropertyCount = expectedList.Count;

            var oldObject = new AuditAgregatorObject();

            oldObject.SetExistObjectPrimaryKey(Guid.NewGuid());
            oldObject.MasterObject = new AuditMasterObject();
            SetViewProperties(oldObject, auditView, oldValue);
            oldObject.SetLoadedProperties(ownProperties.ToArray());
            oldObject.MasterObject.SetLoadedProperties(ownProperties.ToArray());

            var newObject = new AuditAgregatorObject();

            newObject.SetExistObjectPrimaryKey(Guid.NewGuid());
            newObject.MasterObject = new AuditMasterObject();
            SetViewProperties(newObject, testView, newValue);
            newObject.SetLoadedProperties(testOwnProperties.ToArray());
            newObject.AddLoadedProperties(Information.ExtractPropertyPath <AuditAgregatorObject>(x => x.MasterObject));
            newObject.MasterObject.SetLoadedProperties(testOwnProperties.ToArray());
            var dataCopyObject = new AuditAgregatorObject();

            newObject.CopyTo(dataCopyObject, true, true, false);
            dataCopyObject.MasterObject = null;
            newObject.SetDataCopy(dataCopyObject);

            var ds = new LocalDataService();

            // Act.
            var loadedProperties = AuditService.CopyAlteredNotSavedDataObject(oldObject, newObject, auditView, ds, null);

            // Assert.
            Assert.Equal(1, ds.Counter);
            foreach (var auditProperty in auditView.Properties)
            {
                var expectedValue = testViewPropertyNames.Contains(auditProperty.Name)
                    ? newValue
                    : (auditProperty.Name.StartsWith(Information.ExtractPropertyPath <AuditAgregatorObject>(x => x.MasterObject) + ".") ? LoadedValue : oldValue);
                var actualValue = Information.GetPropValueByName(newObject, auditProperty.Name);

                if (!(actualValue is DataObject) && Information.IsStoredProperty(typeof(AuditAgregatorObject), auditProperty.Name))
                {
                    Assert.Equal(expectedValue, actualValue);
                }
            }

            Assert.Equal(expectedPropertyCount, loadedProperties.Count);
            Assert.Equal(expectedPropertyCount, expectedList.Union(loadedProperties).Distinct().Count());
        }