GithubHelp home page GithubHelp logo

Comments (6)

anaisbetts avatar anaisbetts commented on April 25, 2024

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.

alski avatar alski commented on April 25, 2024

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.

anaisbetts avatar anaisbetts commented on April 25, 2024

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.

alski avatar alski commented on April 25, 2024

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.

alski avatar alski commented on April 25, 2024

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.

anaisbetts avatar anaisbetts commented on April 25, 2024

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 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 (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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.