Is this a bug? Calling BeginEdit() followed by CancelEdit() results in IsDirty being true

Is this a bug? Calling BeginEdit() followed by CancelEdit() results in IsDirty being true

Old forum URL: forums.lhotka.net/forums/t/10623.aspx


Jaans posted on Wednesday, August 17, 2011

Hi Gang

I've just ran into an issue under Silverlight where I found that calling .BeginEdit() followed by a CancelEdit() results a clean object (IsDirty = false) becoming dirty (IsDirty = true)?

I'm not sure, it could be by design (not sure why though), but this feels like a bug to me.

Using Silverlight 4 with CSLA 4.1.0

Thanks,
Jaans

RockfordLhotka replied on Wednesday, August 17, 2011

I don't see the problem with this code:

    [TestMethod]
    public void CancelEditRoundTripsIsDirty()
    {
      var obj = new Root();
      obj.Clean();
      Assert.IsFalse(obj.IsDirty, "Before edit");
      obj.BeginEdit();
      Assert.IsFalse(obj.IsDirty, "After begin edit");
      obj.CancelEdit();
      Assert.IsFalse(obj.IsDirty, "After cancel edit");
    }

The Root class is this:

  [Serializable]
  public class Root : BusinessBase<Root>
  {
    public static readonly PropertyInfo<string> DataProperty = RegisterProperty<string>(c => c.Data);
    public string Data
    {
      get { return GetProperty(DataProperty); }
      set { SetProperty(DataProperty, value); }
    }

    public void Clean()
    {
      MarkClean();
    }
  }

Jaans replied on Wednesday, August 17, 2011

Apologies Rocky

It would seem that an overrides of OnChildChanged method is calling PropertyHasChanged (which I do to enable triggering of business rules on parent objects in response to changes in grand-child objects).

Again, my bad!

CSLA is cancelling the edit correctly.

Copyright (c) Marimer LLC