Ejemplo n.º 1
0
            public void SetsValuesCorrectly()
            {
                var obj = new Mocks.MockModel();
                var tag = "MyTag";

                var service = new MementoService();
                var observer = new ObjectObserver(obj, tag, service);

                Assert.AreEqual(tag, observer.Tag);
            }
Ejemplo n.º 2
0
            public void CorrectlyIgnoresDuplicatePropertyChangesWithEqualValues()
            {
                var obj = new Mocks.MockModel();
                
                var service = new MementoService();
                var observer = new ObjectObserver(obj, mementoService: service);

                Assert.AreEqual(0, service.UndoBatches.Count());

                obj.Value = "A";

                Assert.AreEqual(1, service.UndoBatches.Count());

                obj.Value = "A";

                Assert.AreEqual(1, service.UndoBatches.Count());
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Registers the object and automatically watches the object. As soon as the <see cref="INotifyPropertyChanged.PropertyChanged"/> event
        /// occurs, it will automatically create a backup of the property to support undo.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="tag">The tag.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="instance"/> is <c>null</c>.</exception>
        public void RegisterObject(INotifyPropertyChanged instance, object tag = null)
        {
            Argument.IsNotNull("instance", instance);

            Log.Debug("Registering object of type '{0}' with tag '{1}'", instance.GetType().Name, TagHelper.ToString(tag));

            if (!_observers.ContainsKey(instance))
            {
                _observers[instance] = new ObjectObserver(instance, tag, this);

                Log.Debug("Registered object");
            }
            else
            {
                Log.Debug("Object already registered, not registered");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers the object and automatically watches the object. As soon as the <see cref="INotifyPropertyChanged.PropertyChanged"/> event
        /// occurs, it will automatically create a backup of the property to support undo.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="tag">The tag.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="instance"/> is <c>null</c>.</exception>
        public void RegisterObject(INotifyPropertyChanged instance, object tag = null)
        {
            Argument.IsNotNull("instance", instance);

            Log.Debug("Registering object of type '{0}' with tag '{1}'", instance.GetType().Name, TagHelper.ToString(tag));

            if (!_observers.ContainsKey(instance))
            {
                _observers[instance] = new ObjectObserver(instance, tag, this);

                Log.Debug("Registered object");
            }
            else
            {
                Log.Debug("Object already registered, not registered");
            }
        }