1
votes

I'm using ReactiveUI-5.99.6 but i'm having trouble making this simple test pass

public class ViewModel : ReactiveObject
{
    public ReactiveList<int> List { get; private set; }
    public IReactiveCommand Command { get; private set; }

    public ViewModel()
    {
        List = new ReactiveList<int>();
        Command = ReactiveCommand.Create(List.Changed.Select(_ => List.Any()));
    }
}

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        var vm = new ViewModel();

        vm.List.Add(2);
        Assert.IsTrue(vm.Command.CanExecute(null));
    }
}

Can someone please tell me what am i doing wrong?

1
There has never been a release 5.99.6, we had a 5.5.1 then we jumped to 6.0.0. We are currently at 8.7.2. Have you got version numbers confused? - Glenn Watson
I'm trying to upgrade from 4.6.5. I downloaded this version github.com/reactiveui/ReactiveUI/tree/5.99.6 - Dtex

1 Answers

1
votes

I don't know about version 5.99.6 (!?) but the following implementation should make your unit test pass in version 8.7.2:

public class ViewModel : ReactiveObject
{
    public ReactiveList<int> List { get; private set; }
    public ICommand Command { get; private set; }

    public ViewModel()
    {
        List = new ReactiveList<int>();
        Command = ReactiveCommand.Create(() => { /* do something */ }, List.Changed.Select(_ => List.Any()));
    }
}

If you change the type of the Command property to anything else than ICommand (for example ReactiveCommand<Unit, Unit>), your unit test would look something like this:

[TestMethod]
public async Task TestMethod1()
{
    var vm = new ViewModel();
    vm.List.Add(2);
    Assert.IsTrue(await vm.Command.CanExecute.FirstAsync());
}

What version should i get if my project is .Net 4.5?

ReactiveUI 7.4.0 supports .NET Framework 4.5. The solution above should work for this version as well.