Comments (6)
So, the code below isn't surprising if you're outside of a unit test runner because we end up updating things on the Dispatcher - so, if you change something then instantly check for it, it's not up-to-date (in the unit test runner, the default Scheduler is changed so that tests like this are possible to write).
Can you show me your code that tries to do this, it should look something like (coding via Email ahead):
var theCmd = new ReactiveCommand(
this.WhenAny(x => x.TheTextBoxText, x => !String.IsNullOrWhitespace(x.Value)));
One big difference between WhenAny and ObservableForProperty, is that WhenAny sends a notification when you first set it up, so it solves the "initial state" problem, whereas with ObsForProp you would always have to tack on .StartWith(TheProperty)
Paul Betts [email protected]
On Thursday, August 25, 2011 at 1:32 PM, alski wrote:
I have a UI where an empty text box prevents an OK button being clicked, but unfortunately it seems to be enabled until after you have set and cleared the textbox. After stripping it down and down I can still recreate the issue with code as simple as
static void Main(string[] args) { ReactiveCommand cmd = new ReactiveCommand(Observable.Return(false)); Debug.Assert(cmd.CanExecute(null) == false); }Following the ReactiveCommand constructor in the source, it seems to be that the InitialValue is being set to true. Can you remember the reason for this? Is there anyway we can detect an initial value from the observable that we are watching?
Reply to this email directly or view it on GitHub:
https://github.com/xpaulbettsx/ReactiveUI/issues/32
from reactiveui.
OK, l think I might know what's wrong. I'm using nbehave to test with. Is that going to be recognised as a runner?
Just in case, my code is below including the debug Do()s. I'm sure it had a StartWith before :-)
AddCommand = new ReactiveCommand(
this.ObservableForProperty(x => x.NewIntention)
.Do(x=> Console.WriteLine("AddCommand: NewIntetnion={0}|{1}",x.Value,NewIntention))
.Select(x => String.IsNullOrEmpty(x.Value) == false)
.Do(x => Console.WriteLine("AddCommand: NewIntention is not blank {0}", x))
);
from reactiveui.
Not currently, but I'll add it. In the meantime, if you put at the top of your test:
RxApp.DeferredScheduler = Scheduler.Immediate;
That should unblock you
Paul Betts
SENT FROM MY COMMODORE 64: RESPONSES MAY BE IN ALL CAPS
On Aug 26, 2011, at 3:45, [email protected] wrote:
OK, l think I might know what's wrong. I'm using nbehave to test with. Is that going to be recognised as a runner?
AddCommand = new ReactiveCommand(
this.ObservableForProperty(x => x.NewIntention)
.Do(x=> Console.WriteLine("AddCommand: NewIntetnion={0}|{1}",x.Value,NewIntention))
.Select(x => String.IsNullOrEmpty(x.Value) == false)
.Do(x => Console.WriteLine("AddCommand: NewIntention is not blank {0}", x))
);Reply to this email directly or view it on GitHub:
https://github.com/xpaulbettsx/ReactiveUI/issues/32#issuecomment-1911549
from reactiveui.
Ok, so if I add a referenec to nUnit and wrap my existing test code with
using NUnit.Framework;
...
[Test]
public void CanAddWhenNewIntentionIsNotBlank()
{
GivenANewProjectViewModel();
WhenMyProjectViewModelHasANewIntention("Hello world");
ThenMyProjectViewModelShouldBeAbleToAddANewIntention();
WhenMyProjectViewModelHasABlankNewIntention();
ThenMyProjectViewModelShouldNotBeAbleToAddANewIntention();
}
Then I can confirm that the tests pass in an NUnit Gui, via TestDriven.Net's Run Test and NBehave's Run Scenario.
Under TestDriven I get the message
Error: *** Detected Unit Test Runner, setting Scheduler to Immediate ***
Error: If we are not actually in a test runner, please file a bug
When I remove the [Test] everything works (except in nUnit Gui) which can't find a test (still getting the Error under TestDriven)
When I remove the [TestFixture] nBehave RunScenario fails independant of the fact the nUnit assemblies are still referenced. Would that imply because nUnit isn't actually used its not been loaded?
from reactiveui.
Could it be as simple as changing the code under RxApp.InUnitTestRunner() ? I agree with your comment, I can't think of a better way either.
from reactiveui.
Yes, assembly loading is lazy - the loaded assemblies list won't reflect referenced assemblies that aren't being used, so it won't be picked up
Paul Betts
SENT FROM MY COMMODORE 64: RESPONSES MAY BE IN ALL CAPS
On Aug 26, 2011, at 11:41, [email protected] wrote:
Ok, so if I add a referenec to nUnit and wrap my existing test code with
using NUnit.Framework;
...
[Test]
public void CanAddWhenNewIntentionIsNotBlank()
{
GivenANewProjectViewModel();
WhenMyProjectViewModelHasANewIntention("Hello world");
ThenMyProjectViewModelShouldBeAbleToAddANewIntention();
WhenMyProjectViewModelHasABlankNewIntention();
ThenMyProjectViewModelShouldNotBeAbleToAddANewIntention();
}Then I can confirm that the tests pass in an NUnit Gui, via TestDriven.Net's Run Test and NBehave's Run Scenario.
Under TestDriven I get the message
Error: *** Detected Unit Test Runner, setting Scheduler to Immediate ***
Error: If we are not actually in a test runner, please file a bugWhen I remove the [Test] everything works (except in nUnit Gui) which can't find a test (still getting the Error under TestDriven)
When I remove the [TestFixture] nBehave RunScenario fails (I'll pass this to them separately) independant of the fact the nUnit assemblies are still referenced. Would that imply because nUnit isn't actually used its not been loaded?
Reply to this email directly or view it on GitHub:
https://github.com/xpaulbettsx/ReactiveUI/issues/32#issuecomment-1915709
from reactiveui.
Related Issues (20)
- [Bug]: Duplicate deactivation of ViewModel, from ViewModelActivator. HOT 4
- [Bug]: Accessibility properties SizeOfSet and PositionOfSet are not being set when using <ReactiveWindow> HOT 6
- [Bug]: ReactiveUI incompatible with .NET Assembly Load Contexts HOT 2
- [Bug]: On Maui initial NavigateAndReset pushes the same screen twice HOT 8
- Make generic IViewFor<TViewModel> implementation optional in favor of non-generic IViewFor HOT 15
- Add overloads for the command binders that accept IViewFor HOT 1
- [Bug]: got imcompatible message when using with .net 7 HOT 2
- [Bug]: Visual Studio hot reload broken HOT 21
- [Bug]: Putting RoutedViewHost inside a TabControl on Avalonia causes an app crash after navigating the second time HOT 7
- [Bug]: `ObservableAsPropertyHelper` emits property changed for lazy initial value after first-time reading and doesn't respect `DistinctUntilChanged` HOT 1
- [Bug]: WPF ReactiveCommand stays disabled after first execution HOT 9
- [Bug]: Mark ReactiveObject IObservable properties with DisplayAttribute for Winforms HOT 9
- ReactiveUI.WPF does not include .net 8.0 as a target: HOT 3
- [Bug]: Unable to use activation of views on Windows with MAUI HOT 2
- ViewModelViewHost: Better to Allow Developers Bypass the Default Fallback Behavior That Resovles View With No Contract HOT 2
- [Bug]: WireUpControls throws exception in net8.0-android HOT 2
- [Bug]: ViewModelViewHost does not set DataContext in WPF HOT 2
- [Bug]: WPF targeting issue for net6.0-windows HOT 4
- Dependency Dashboard
- [Bug]: iOS threading exception on command execution. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactiveui.