public void TestRestore() { var obj = new object(); var child1 = new Mock <ICompositeMemento>(); var child2 = new Mock <ICompositeMemento>(); var children = new List <ICompositeMemento> { child1.Object, child2.Object }; var factoryMock = new Mock <IMementoFactory>(); var propertyMock = new Mock <IPropertyAdapter>(); propertyMock.Setup(p => p.IsStatic).Returns(false); propertyMock.Setup(p => p.GetValue(obj)).Returns(InitialVal); propertyMock.Setup(p => p.SetValue(obj, InitialVal)); var propertyMemento = new PropertyMemento(obj, false, propertyMock.Object, factoryMock.Object); propertyMemento.Children = children; //Act propertyMemento.Rollback(); //Assert propertyMock.Verify(p => p.SetValue(obj, InitialVal), Times.Once()); child1.Verify(c => c.Rollback(), Times.Once()); child2.Verify(c => c.Rollback(), Times.Once()); }
public void TestGenerateChildren() { //Arrange var obj = new object(); var children = new List <ICompositeMemento> { new Mock <ICompositeMemento>().Object, new Mock <ICompositeMemento>().Object }; var factoryMock = new Mock <IMementoFactory>(); factoryMock.Setup(f => f.CreateMementos(InitialVal)) .Returns(children); var propertyMock = new Mock <IPropertyAdapter>(); propertyMock.Setup(p => p.IsStatic).Returns(false); propertyMock.Setup(p => p.GetValue(obj)).Returns(InitialVal); //Act var propertyMemento = new PropertyMemento(obj, true, propertyMock.Object, factoryMock.Object); //Assert Assert.AreEqual(2, propertyMemento.Children.Count()); CollectionAssert.AreEquivalent(children, propertyMemento.Children); }
public GuidePropertyChangeCommand(object target, string propertyName, object oldValue, object newValue) { _listEventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>(); _target = target; _memento = new PropertyMemento(propertyName, oldValue, newValue); }
public void NotifyActionPropertyChagned(string propertyName, object oldValue, object newValue) { var property = GetType().GetProperty(propertyName); if (oldValue == null || property.PropertyType == oldValue.GetType()) { _lastProperty = new PropertyMemento(oldValue, propertyName); } NotifyActionPropertyChagned(propertyName, newValue); }
public void RememberProperty(string propertyName) { var property = GetType().GetProperty(propertyName); if (property != null) { object value = property.GetValue(this); _lastProperty = new PropertyMemento(value, propertyName); } else { throw new ArgumentException($"Property {propertyName} not found"); } }