Consider my first attempt, a simple type in F #, for example:
type Test() = inherit BaseImplementingNotifyPropertyChangedViaOnPropertyChanged() let mutable prop: string = null member this.Prop with public get() = prop and public set value = match value with | _ when value = prop -> () | _ -> let prop = value this.OnPropertyChanged("Prop")
Now I am testing this through C # (this object undergoes a C # project, so C # semantics are obvious):
[TestMethod] public void TaskMaster_Test() { var target = new FTest(); string propName = null; target.PropertyChanged += (s, a) => propName = a.PropertyName; target.Prop = "newString"; Assert.AreEqual("Prop", propName); Assert.AreEqual("newString", target.Prop); return; }
propName correctly assigned, my F # setter is running, but the second statement does not work, because the base value of prop does not change. This makes sense to me because if I remove the mutable from the prop field, the error will not be generated (and this should be because I'm trying to change the value). I think that I am missing a fundamental concept.
What is the correct way to recompute / mutate prop in the Test class so that I can pass my unit test?
mutable f #
Greg d
source share