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)
- Dependency Dashboard
- [Bug]: iOS threading exception on command execution. HOT 4
- Bounce transition duration support HOT 3
- [Bug]: WinUI/WAS - ReactiveUI.WinUi nuget attempts to load the ReactiveUI.XamForms assembly when WhenActivated is called on a IActivatableViewModel HOT 6
- Leverage dependencies available from framework HOT 1
- CI: code coverage token missing
- [Bug]: NavigateAndReset doesn't work in first view HOT 4
- [Bug]: Nested ItemsControl crashes entire app HOT 4
- [Bug]: ReactiveCommand causing application to hang with FilePicker in Avalonia HOT 3
- Remove DistinctUntilChanged from WhenAnyValue HOT 1
- [Bug]: WireUpControls throws exception in net8.0-android HOT 19
- [Bug]: Hot reload not working when referencing ReactiveUI.WinUI when targeting net7.0 HOT 4
- [Bug]: ThrownExceptions doent get triggered when i run Parallel.ForEachAsync HOT 12
- Source generators HOT 4
- [Bug]: reactiveui.fody 19.5.41 bool value does not notify UI when using [Reactive] and bool value changed HOT 4
- [Bug]: iOS BindCommand throws exception when executing on iPad (device) HOT 1
- [Bug]: Annoying Trace Listener popups when working with Winforms Designer
- [Bug]: `ObserveOn(IObservable<TSource>, Control)` duplicates in `ReactiveUI.WinForms` and `System.Reactive`
- [Bug]: Mixing WPF and WinForms packages (`ElementHost`ing WPF controls inside WinForms) breaks MainThreadScheduler (and possibly other things) HOT 3
- [Bug]: .net 8.0 nuget add ReactiveUI.wpf warn HOT 1
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.