public void AcceptAndRejectChangesInObjectsWithNavigationProperty() { TestHusband husband = new TestHusband(); TestWife wife1 = new TestWife(); wife1.Husband = husband; husband.Wife = wife1; TestHusbandWrapper husbandWrapper = new TestHusbandWrapper(husband); Assert.IsFalse(husbandWrapper.IsChanged); husbandWrapper.Wife.N++; Assert.IsTrue(husbandWrapper.IsChanged); husbandWrapper.AcceptChanges(); Assert.IsFalse(husbandWrapper.IsChanged); var oldId = husbandWrapper.Wife.Id; husbandWrapper.Wife.Id = Guid.NewGuid(); Assert.IsTrue(husbandWrapper.IsChanged); husbandWrapper.RejectChanges(); Assert.IsFalse(husbandWrapper.IsChanged); Assert.AreEqual(oldId, husbandWrapper.Wife.Id); TestChildWrapper childWrapper = new TestChildWrapper(new TestChild { Husband = husband }); husbandWrapper.Children.Add(childWrapper); Assert.IsTrue(husbandWrapper.IsChanged); }
public void IsChangedNavigationProperty() { TestHusband husband = new TestHusband { Id = 1 }; TestWife wife1 = new TestWife { Id = 2 }; wife1.Husband = husband; husband.Wife = wife1; TestHusbandWrapper husbandWrapper = new TestHusbandWrapper(husband); Assert.IsFalse(husbandWrapper.IsChanged); var wife1Wrapper = husbandWrapper.Wife; husbandWrapper.Wife = new TestWifeWrapper(new TestWife { Id = 3 }); Assert.IsTrue(husbandWrapper.IsChanged); husbandWrapper.Wife = wife1Wrapper; Assert.IsFalse(husbandWrapper.IsChanged); }
public void ComplexWrapperAcceptAndReject() { TestWrappersFactory testWrappersFactory = new TestWrappersFactory(); TestHusband husband = new TestHusband(); TestWife wife1 = new TestWife(); TestChild child1 = new TestChild { Husband = husband, Wife = wife1 }; TestChild child2 = new TestChild { Husband = husband, Wife = wife1 }; wife1.Husband = husband; husband.Wife = wife1; husband.Children.Add(child1); husband.Children.Add(child2); TestHusbandWrapper husbandWrapper = testWrappersFactory.GetWrapper <TestHusbandWrapper>(husband); Assert.IsFalse(husbandWrapper.IsChanged); TestChildWrapper childWrapper1 = husbandWrapper.Children.First(x => Equals(x.Model, child1)); string oldChildsName = childWrapper1.Name; childWrapper1.Name = oldChildsName + "NEW"; husbandWrapper.RejectChanges(); Assert.AreEqual(childWrapper1.Name, oldChildsName); childWrapper1.Name = oldChildsName + "NEW"; husbandWrapper.AcceptChanges(); Assert.AreEqual(childWrapper1.Name, oldChildsName + "NEW"); Assert.AreEqual(childWrapper1.NameOriginalValue, oldChildsName + "NEW"); TestWifeWrapper wifeWrapper = husbandWrapper.Wife; husbandWrapper.Wife = null; Assert.AreEqual(husbandWrapper.Wife, null); husbandWrapper.RejectChanges(); Assert.AreEqual(husbandWrapper.Wife, wifeWrapper); TestWifeWrapper wifeWrapper2 = testWrappersFactory.GetWrapper <TestWifeWrapper>(new TestWife()); husbandWrapper.Wife = wifeWrapper2; husbandWrapper.AcceptChanges(); Assert.AreEqual(wifeWrapper2.Model, husbandWrapper.Model.Wife); husbandWrapper.Children.Remove(childWrapper1); husbandWrapper.RejectChanges(); Assert.IsTrue(husbandWrapper.Children.Contains(childWrapper1)); Assert.IsFalse(husbandWrapper.IsChanged); }
public void ComplexWrapperTest() { TestHusband husband = new TestHusband(); TestWife wife = new TestWife(); TestChild child1 = new TestChild { Husband = husband, Wife = wife }; TestChild child2 = new TestChild { Husband = husband, Wife = wife }; wife.Husband = husband; husband.Wife = wife; husband.Children.AddRange(new[] { child1, child2 }); TestHusbandWrapper husbandWrapper = new TestHusbandWrapper(husband); Assert.IsFalse(husbandWrapper.IsChanged); string oldWifesName = husbandWrapper.Wife.Name; husbandWrapper.Wife.Name = oldWifesName + "New"; Assert.IsTrue(husbandWrapper.IsChanged); husbandWrapper.Wife.Name = oldWifesName; Assert.IsFalse(husbandWrapper.IsChanged); TestChildWrapper childWrapper1 = husbandWrapper.Children.Single(x => Equals(x.Model, child1)); string oldChildsName = childWrapper1.Name; childWrapper1.Name = oldChildsName + "NEW"; Assert.AreEqual(childWrapper1.NameOriginalValue, oldChildsName); Assert.IsTrue(husbandWrapper.IsChanged); childWrapper1.Name = oldChildsName; Assert.IsFalse(husbandWrapper.IsChanged); husbandWrapper.Children.Remove(childWrapper1); Assert.IsTrue(husbandWrapper.IsChanged); husbandWrapper.Children.Add(childWrapper1); Assert.IsFalse(husbandWrapper.IsChanged); }
public void IsChangedNavigationProperty() { TestWrappersFactory testWrappersFactory = new TestWrappersFactory(); TestHusband husband = new TestHusband(); TestWife wife1 = new TestWife(); wife1.Husband = husband; husband.Wife = wife1; TestHusbandWrapper husbandWrapper = testWrappersFactory.GetWrapper <TestHusbandWrapper>(husband); Assert.IsFalse(husbandWrapper.IsChanged); var wife1Wrapper = husbandWrapper.Wife; husbandWrapper.Wife = testWrappersFactory.GetWrapper <TestWifeWrapper>(new TestWife()); Assert.IsTrue(husbandWrapper.IsChanged); husbandWrapper.Wife = wife1Wrapper; Assert.IsFalse(husbandWrapper.IsChanged); }
public void ComplexWrapperTest() { TestHusband husband = new TestHusband(); TestWife wife = new TestWife(); TestChild child1 = new TestChild { Id = 1, Husband = husband, Wife = wife }; TestChild child2 = new TestChild { Id = 2, Husband = husband, Wife = wife }; wife.Husband = husband; husband.Wife = wife; husband.Children.Add(child1); husband.Children.Add(child2); TestHusbandWrapper husbandWrapper = new TestHusbandWrapper(husband); Assert.IsFalse(husbandWrapper.IsChanged); TestChildWrapper childWrapper1 = husbandWrapper.Children.First(x => Equals(x.Model, child1)); string oldChildsName = childWrapper1.Name; childWrapper1.Name = oldChildsName + "NEW"; Assert.IsTrue(husbandWrapper.IsChanged); childWrapper1.Name = oldChildsName; Assert.IsFalse(husbandWrapper.IsChanged); husbandWrapper.Children.Remove(childWrapper1); Assert.IsTrue(husbandWrapper.IsChanged); husbandWrapper.Children.Add(childWrapper1); Assert.IsFalse(husbandWrapper.IsChanged); }
public void NavigationPropertiesTest() { TestHusband husband = new TestHusband { Id = 1 }; TestWife wife = new TestWife { Id = 2 }; wife.Husband = husband; husband.Wife = wife; TestHusbandWrapper husbandWrapper = new TestHusbandWrapper(husband); bool fired = false; husbandWrapper.PropertyChanged += (sender, args) => { fired = true; }; Assert.IsFalse(husbandWrapper.IsChanged); var wifeWrapper = husbandWrapper.Wife; wifeWrapper.N = 10; Assert.IsTrue(husbandWrapper.IsChanged); Assert.IsTrue(fired); TestWife otherTestWife = new TestWife { Id = 22 }; TestWifeWrapper otherTestWifeWrapper = new TestWifeWrapper(otherTestWife); Assert.IsFalse(husbandWrapper.WifeIsChanged); husbandWrapper.Wife = otherTestWifeWrapper; Assert.IsTrue(husbandWrapper.WifeIsChanged); Assert.IsTrue(husbandWrapper.IsChanged); Assert.AreEqual(wifeWrapper, husbandWrapper.WifeOriginalValue); fired = false; wifeWrapper.N = 33; Assert.IsFalse(fired); fired = false; husbandWrapper.Wife = null; Assert.AreEqual(husbandWrapper.Wife, null); Assert.IsTrue(fired); Assert.IsTrue(husbandWrapper.WifeIsChanged); Assert.IsTrue(husbandWrapper.IsChanged); Assert.AreEqual(wifeWrapper, husbandWrapper.WifeOriginalValue); fired = false; TestChildWrapper childWrapper = new TestChildWrapper(new TestChild { Husband = husband }); husbandWrapper.Children.Add(childWrapper); Assert.IsTrue(fired); var husbandWrp = new TestHusbandWrapper(husbandWrapper.Model); fired = false; childWrapper.Id = 1; Assert.IsTrue(fired); husbandWrapper.Children.Remove(childWrapper); fired = false; childWrapper.Id++; Assert.IsFalse(fired); }
public void NavigationPropertiesTest() { TestWrappersFactory testWrappersFactory = new TestWrappersFactory(); TestHusband husband = new TestHusband(); TestWife wife = new TestWife(); wife.Husband = husband; husband.Wife = wife; TestHusbandWrapper husbandWrapper = testWrappersFactory.GetWrapper <TestHusbandWrapper>(husband); bool fired = false; husbandWrapper.PropertyChanged += (sender, args) => { fired = true; }; Assert.IsFalse(husbandWrapper.IsChanged); var wifeWrapper = husbandWrapper.Wife; wifeWrapper.N = 10; Assert.IsTrue(husbandWrapper.IsChanged); Assert.IsTrue(fired); TestWife otherTestWife = new TestWife(); TestWifeWrapper otherTestWifeWrapper = testWrappersFactory.GetWrapper <TestWifeWrapper>(otherTestWife); Assert.IsFalse(husbandWrapper.WifeIsChanged); husbandWrapper.Wife = otherTestWifeWrapper; Assert.IsTrue(husbandWrapper.WifeIsChanged); Assert.IsTrue(husbandWrapper.IsChanged); Assert.AreEqual(wifeWrapper, husbandWrapper.WifeOriginalValue); fired = false; wifeWrapper.N = 33; Assert.IsFalse(fired); fired = false; husbandWrapper.Wife = null; Assert.AreEqual(husbandWrapper.Wife, null); Assert.IsTrue(fired); Assert.IsTrue(husbandWrapper.WifeIsChanged); Assert.IsTrue(husbandWrapper.IsChanged); Assert.AreEqual(wifeWrapper, husbandWrapper.WifeOriginalValue); fired = false; TestChildWrapper childWrapper = testWrappersFactory.GetWrapper <TestChildWrapper>(new TestChild { Husband = husband }); husbandWrapper.Children.Add(childWrapper); Assert.IsTrue(fired); //var husbandWrp = TestWrappersFactory.GetWrapper <TestHusband, TestHusbandWrapper>(husbandWrapper.Model); fired = false; childWrapper.Name += "new"; Assert.IsTrue(fired); husbandWrapper.Children.Remove(childWrapper); fired = false; childWrapper.Name += "new2"; Assert.IsFalse(fired); }