Thursday, 15 September 2011

ReactiveCommand stopped working in ReactiveUI 6 -



ReactiveCommand stopped working in ReactiveUI 6 -

i trying work on james nugent labs progressive .net 2014 , convert reactiveui 6. got stuck createasynctask, seems never run task code.

the vm code has this:

private iobservable<string> pretendtocalltheserver() { homecoming observable.return("hello world") .delay(timespan.frommilliseconds(2000), rxapp.taskpoolscheduler); } public personviewmodel() { _fullname = this.whenanyvalue(vm => vm.firstname, vm => vm.lastname, (f, l) => string.format("{0} {1}", f, l)) .toproperty(this, vm => vm.fullname); var firstandlastfilled = this.whenanyvalue(vm => vm.firstname, vm => vm.lastname, (f, l) => !string.isnullorwhitespace(f) && !string.isnullorwhitespace(l)); changename = reactivecommand.createasynctask(firstandlastfilled, async x => await pretendtocalltheserver()); changename.subscribe(x => serverresult = x); } private string _serverresult; public string serverresult { { homecoming _serverresult; } set { this.raiseandsetifchanged(ref _serverresult, value); } } public readonly reactivecommand<string> changename;

and here failing test:

[test] public void changenamepretendstocallserverbutourtestrunsfast() { (new testscheduler()).with(sched => { var sut = new personviewmodel {firstname = "jane", lastname = "appleseed"}; assert.istrue(sut.changename.canexecute(null)); sut.changename.executeasync(); sched.advancebyms(1000); assert.areequal(null, sut.serverresult); sched.advancebyms(10000); assert.areequal("hello world", sut.serverresult); }); }

basically, followed guidelines on conversion of commands rui6 seems not work. set breakpoints in task method , on subscription , debugged test - these breakpoints never hit.

this by-design:

// didn't subscribe, doesn't sut.changename.executeasync();

change like:

var result = default(string); sut.changename.executeasync().subscribe(x => result = x); sched.advancebyms(1000); assert.areequal(null, result); sched.advancebyms(10000); assert.areequal("hello world", result);

reactiveui

No comments:

Post a Comment