I try to create a base class, which inherits from ReactiveObject. This class needs to check if any property, including properties of further inheritations, has changed.
My main problem is, that I can't get any reliable testresults! The provided test MAY be green. Running it with VS Live Unit Testing, brings it in red. Moving the classes out of the testproject into a library may or may not get this test green.
So far, the only way to keep it green, is to uncomment this line in the inherited class.
// Changed.Subscribe(Console.WriteLine);
[TestClass]
public class StateBaseTests
{
#region Tests
[TestMethod]
public void State_ChangesToChanged_PropertyChanged()
{
var _item = new MyTest();
_item.Surname = "Testname";
Assert.AreEqual(Statetype.Changed, _item.State);
}
#endregion
#region SubClasses
public enum Statetype
{
Added,
Changed,
Deleted,
Detached,
Unchanged
}
public abstract class StateBase : ReactiveObject
{
protected StateBase()
{
State = Statetype.Unchanged;
Changed.Select(prop => prop.PropertyName)
.Subscribe(UpdateZustand);
}
protected void UpdateZustand(string propertyName)
{
if(State == Statetype.Unchanged)
State = Statetype.Changed;
}
[Reactive]
public Statetype State { get; set; }
}
private class MyTest : StateBase
{
public MyTest()
{
// Changed.Subscribe(Console.WriteLine);
}
[Reactive]
public string Name { get; set; }
[Reactive]
public string Surname { get; set; }
}
}
Aucun commentaire:
Enregistrer un commentaire