public void when_attempting_to_version_a_property_bag() { var originalAddress = "12345 Fake Street"; var subscriber = new SimpleMementoingClass() { Domainees = new List<DomainPropertyBag>() { new DomainPropertyBag(), new DomainPropertyBag() }, ChiefDomainee = new DomainPropertyBag(), Address = originalAddress, FirstName = "If only Customer Objects", LastName = "were ever this simple" }; var mementor = new Mementor(); var newAddress = "Changed Address!"; mementor.PropertyChange(subscriber, () => subscriber.Address); //ohhh typing is a little weak here. subscriber.Address = newAddress; //ahh, note the order matters of course. subscriber.Address.Should().Be(newAddress); mementor.Undo(); //and I cant undo specific changes, just the last one. subscriber.Address.Should().Be(originalAddress); //still, very cool. //In terms of a deployed program, this is tough to implement. //I like the pub-sub design of it, code is superbly clean. }
public void when_forcing_bad_things_via_expression() { var subscriber = new SimpleMementoingClass(); var mementor = new Mementor(); subscriber.Address = "Changed!"; Assert.Throws<InvalidCastException>(() => mementor.PropertyChange(subscriber, () => mementor.ToString())); //aww duder and the exceptions arn't handled nicely here either, Linq at the wrong thing and get a generic Expression.OhgodohgodohgodException //why not public void PropertyChange<TSubject, TTargetSite>(this TSubject subject, Func<TSubject, TTargetSite> transform...) //would be mementor.PropertyChange(subscriber, sub => sub.SomeProp), would provide some additional typiing on the expression. }