public static void Init(TestContext context)
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackThisType <IWhatever>();

            TrackableObjectFactory = config.CreateTrackableObjectFactory();
        }
Exemplo n.º 2
0
        public static void Init(TestContext context)
        {
            Configuration = ObjectChangeTracking.CreateConfiguration()
                            .TrackThisType <A>()
                            .TrackThisType <TestDynamicObject>();

            TrackableObjectFactory = Configuration.CreateTrackableObjectFactory();
        }
Exemplo n.º 3
0
        public void Initialize()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackThisTypeRecursive <Class0>();

            _trackableObjectFactory = config.CreateTrackableObjectFactory();
        }
Exemplo n.º 4
0
        public EinstellungenViewModel()
        {
            var trackerConfig = ObjectChangeTracking.CreateConfiguration();

            trackerConfig.TrackThisType <Settings>();

            var trackableObjectFactory = trackerConfig.CreateTrackableObjectFactory();

            _settings = trackableObjectFactory.CreateFrom(Settings.GetSettings());
        }
Exemplo n.º 5
0
        public void CanConfigureAbstractClass()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).GetTypeInfo().Assembly, searchSettings: new TypeSearchSettings
            {
                Mode = TypeSearchMode.AttributeConfigurationOnly,
                /*Filter = t => t == typeof(AbstractClass) || t == typeof(DerivesAbstractClass),*/
                Recursive = true
            });

            ITrackableObjectFactory factory = config.CreateTrackableObjectFactory();
            var x = factory.CreateFrom(new DerivesAbstractClass());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Return list of changed properties.
        /// </summary>
        /// <returns></returns>
        public IList <PropertyDefinition> GetChangedProperies()
        {
            List <PropertyDefinition> changedProperties = new List <PropertyDefinition>();

            foreach (PropertyDefinition propDefinition in this.propertyValue.Keys)
            {
                ObjectChangeTracking objectChangeTracking = this.propertyValue[propDefinition];
                if (objectChangeTracking.Changed)
                {
                    changedProperties.Add(propDefinition);
                }
            }

            return(changedProperties);
        }
Exemplo n.º 7
0
        public void ConfiguresClassWithAllPropertiesExceptingNonTrackable()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).GetTypeInfo().Assembly, searchSettings: new TypeSearchSettings
            {
                Mode   = TypeSearchMode.AttributeConfigurationOnly,
                Filter = t => t == typeof(TwoPropertiesOneTrackable)
            });

            ITrackableType trackableType = config.TrackableTypes.Single();

            Assert.AreEqual(1, trackableType.IncludedProperties.Count);
            Assert.AreEqual("Text", trackableType.IncludedProperties.Single().Name);
        }
Exemplo n.º 8
0
        public static void Init(TestContext context)
        {
            Configuration = ObjectChangeTracking.CreateConfiguration()
                            .TrackThisType <A>(t => t.IncludeProperty(a => a.Items))
                            .TrackThisType <B>(t => t.IncludeProperty(b => b.Dogs))
                            .TrackThisType <C>(t => t.IncludeProperty(c => c.Dogs))
                            .TrackThisType <Dog>(t => t.IncludeProperty(d => d.Name))
                            .TrackThisType <D>()
                            .TrackThisType <E>(t => t.IncludeProperty(e => e.Dictionary))
                            .TrackThisType <F>(t => t.IncludeProperty(f => f.ListOfF))
                            .TrackThisType <G>(t => t.IncludeProperty(g => g.Buffer))
                            .TrackThisType <WhateverBase>(t => t.IncludeProperty(w => w.List2))
                            .TrackThisType <WhateverParent>(t => t.IncludeProperty(w => w.List));

            TrackableObjectFactory = Configuration.CreateTrackableObjectFactory();
        }
Exemplo n.º 9
0
        public void CanConfigureClassWithMultipleConstructors()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).GetTypeInfo().Assembly, searchSettings: new TypeSearchSettings
            {
                Mode   = TypeSearchMode.AttributeConfigurationOnly,
                Filter = t => t == typeof(WithMultipleConstructors)
            });

            ITrackableObjectFactory factory = config.CreateTrackableObjectFactory();

            WithMultipleConstructors instance = factory.CreateFrom(new WithMultipleConstructors());

            Assert.IsNotNull(instance);
        }
Exemplo n.º 10
0
        public void CanConfigureWithNestedTypes()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).GetTypeInfo().Assembly, searchSettings: new TypeSearchSettings
            {
                Mode   = TypeSearchMode.AttributeConfigurationOnly,
                Filter = t => t == typeof(ClassWithNestedEnum) || t == typeof(DerivedClassWithNestedEnum)
            });

            ITrackableObjectFactory factory = config.CreateTrackableObjectFactory();

            DerivedClassWithNestedEnum instance = factory.CreateOf <DerivedClassWithNestedEnum>();

            Assert.IsNotNull(instance);
        }
Exemplo n.º 11
0
        public void ConfiguresClassWithAllProperties()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).GetTypeInfo().Assembly, searchSettings: new TypeSearchSettings
            {
                Mode   = TypeSearchMode.AttributeConfigurationOnly,
                Filter = t => t == typeof(AllProperties)
            });

            ITrackableType trackableType = config.TrackableTypes.Single();

            Assert.AreEqual(2, trackableType.IncludedProperties.Count);
            Assert.IsTrue(trackableType.IncludedProperties.Any(p => p.Name == "Text"));
            Assert.IsTrue(trackableType.IncludedProperties.Any(p => p.Name == "Text2"));
        }
Exemplo n.º 12
0
        public static void Init(TestContext context)
        {
            Configuration = ObjectChangeTracking.CreateConfiguration()
                            .TrackThisType <A>(t => t.IncludeProperties(a => a.Text, a => a.B))
                            .TrackThisType <B>(t => t.IncludeProperties(b => b.Text, b => b.C))
                            .TrackThisType <C>(t => t.IncludeProperties(c => c.Text, c => c.ListOfD))
                            .TrackThisType <D>(t => t.IncludeProperty(d => d.Text))
                            .TrackThisType <E>(t => t.IncludeProperties(e => e.Text, e => e.Number))
                            .TrackThisType <Customer>(t => t.IncludeProperty(c => c.ContactInfo))
                            .TrackThisType <Contact>(t => t.IncludeProperty(c => c.Name))
                            .TrackThisType <EnhancedContact>(t => t.IncludeProperty(c => c.Default))
                            .TrackThisType <ClassWithReadOnlyPropertyThrowingException>()
                            .TrackThisType <ClassSettingPropertiesDuringConstructionTime>(t => t.IncludeProperty(c => c.Text));

            TrackableObjectFactory = Configuration.CreateTrackableObjectFactory();
        }
Exemplo n.º 13
0
        public void ConfiguresWithAttributesOnly()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).Assembly, searchSettings: new TypeSearchSettings
            {
                Mode   = TypeSearchMode.AttributeConfigurationOnly,
                Filter = t => t.ReflectedType == typeof(ConfigurationTest)
            });

            IList <Type> trackables = config.TrackableTypes.Select(t => t.Type).ToList();

            Assert.IsTrue(config.TrackableTypes.Count > 0);
            Assert.IsTrue(trackables.Contains(typeof(AllProperties)));
            Assert.IsTrue(trackables.Contains(typeof(AllPropertiesExceptingNonTrackable)));
            Assert.IsTrue(trackables.Contains(typeof(TwoPropertiesOneTrackable)));
            Assert.IsFalse(trackables.Contains(typeof(NoAttributes)));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Reset change tracking.
 /// </summary>
 internal void ResetChangeTracking()
 {
     foreach (PropertyDefinition key in this.propertyValue.Keys)
     {
         ObjectChangeTracking changeTrackingProperty = this.propertyValue[key];
         changeTrackingProperty.Changed = false;
         if (key.ChangeTrackable)
         {
             key.InvokeResetChangeTrackingOnProperty(changeTrackingProperty.Value);
         }
         else if (key.IsList && key.ListChangeTrackable)
         {
             IList <object> list = key.ActivateIList(changeTrackingProperty.Value);
             foreach (object obj in list)
             {
                 key.InvokeResetChangeTrackingOnProperty(obj);
             }
         }
     }
 }
Exemplo n.º 15
0
        public void CanConfigureClassWithReadOnlyProperties()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).GetTypeInfo().Assembly, searchSettings: new TypeSearchSettings
            {
                Mode   = TypeSearchMode.AttributeConfigurationOnly,
                Filter = t => t == typeof(ClassWithReadOnlyProperties)
            });

            ITrackableObjectFactory factory = config.CreateTrackableObjectFactory();

            ClassWithReadOnlyProperties instance = factory.CreateFrom(new ClassWithReadOnlyProperties());

            instance.Text = "hey";

            IObjectChangeTracker tracker = instance.GetChangeTracker();

            Assert.AreEqual(1, tracker.ChangedProperties.Count);
            Assert.AreEqual(1, ((ObjectChangeTracker)tracker).PropertyTrackings.Count);
        }
Exemplo n.º 16
0
        public void CanConfigureNonTrackablePropertiesFromBaseClasses()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.TrackTypesFromAssembly(typeof(ConfigurationTest).GetTypeInfo().Assembly, searchSettings: new TypeSearchSettings
            {
                Mode      = TypeSearchMode.AttributeConfigurationOnly,
                Recursive = true,
                Filter    = t =>
                {
                    return(t.DeclaringType == typeof(ConfigurationTest));
                }
            });

            ITrackableObjectFactory trackableObjectFactory      = config.CreateTrackableObjectFactory();
            DerivedClassOfBaseClassWithNonTrackableProperty obj = trackableObjectFactory.CreateOf <DerivedClassOfBaseClassWithNonTrackableProperty>();

            IObjectChangeTracker changeTracker = obj.GetChangeTracker();

            Assert.AreEqual(1, changeTracker.Count());
            Assert.IsTrue(changeTracker.First().PropertyName == "Text2");
        }
Exemplo n.º 17
0
        public void CanReplaceCollectionChangeTrackingImplementation()
        {
            IObjectChangeTrackingConfiguration config = ObjectChangeTracking.CreateConfiguration();

            config.Collections.AddOrUpdateImplementation <ICollection <string>, List <string>, DefaultCollectionChangeInterceptor <string> >();
        }