Ejemplo n.º 1
0
        public void RelayResultCommandShouldCallFunctionGeneric()
        {
            var function = Substitute.For<Func<object,int>>();
            var arg = new object();
            function.Invoke(arg).Returns(122);
            var target = new MVVM.Component.RelayResultCommand<object,int>(function);
      
            var res = target.Execute(arg).Result;

            function.Received(1).Invoke(arg);
            res.Should().Be(122);
        }
Ejemplo n.º 2
0
        public void RelayResultCommandShouldCallFunctionGeneric()
        {
            var function = Substitute.For <Func <object, int> >();
            var arg      = new object();

            function.Invoke(arg).Returns(122);
            var target = new MVVM.Component.RelayResultCommand <object, int>(function);

            var res = target.Execute(arg).Result;

            function.Received(1).Invoke(arg);
            res.Should().Be(122);
        }
Ejemplo n.º 3
0
        public void RelayResultCommandShouldCallFunctionGenericWithTask()
        {
            var function = Substitute.For<Func<object, Task<int>>>();
            var tcs = new TaskCompletionSource<int>();
            tcs.SetResult(35);
            var arg = new object();
            function.Invoke(arg).Returns(tcs.Task);
            var target = new MVVM.Component.RelayResultCommand<object, int>(function);

            var res = target.Execute(arg).Result;

            function.Received(1).Invoke(arg);
            res.Should().Be(35);
        }
Ejemplo n.º 4
0
        public void RelayResultCommandShouldHandleExceptionFunctionGeneric()
        {
            var exception = new Exception();
            var function = Substitute.For<Func<object, int>>();
            var arg = new object();
            function.When(f => f.Invoke(arg)).Do(_ => { throw exception; });
            var target = new MVVM.Component.RelayResultCommand<object, int>(function);

            var res = target.Execute(arg);

            function.Received(1).Invoke(arg);
            res.IsFaulted.Should().BeTrue();
            res.Exception.Flatten().InnerException.Should().Be(exception);
        }
Ejemplo n.º 5
0
        public void RelayResultCommandShouldHandleExceptionFunctionGeneric()
        {
            var exception = new Exception();
            var function  = Substitute.For <Func <object, int> >();
            var arg       = new object();

            function.When(f => f.Invoke(arg)).Do(_ => { throw exception; });
            var target = new MVVM.Component.RelayResultCommand <object, int>(function);

            var res = target.Execute(arg);

            function.Received(1).Invoke(arg);
            res.IsFaulted.Should().BeTrue();
            res.Exception.Flatten().InnerException.Should().Be(exception);
        }
Ejemplo n.º 6
0
        public void RelayResultCommandShouldCallFunctionGenericWithTask()
        {
            var function = Substitute.For <Func <object, Task <int> > >();
            var tcs      = new TaskCompletionSource <int>();

            tcs.SetResult(35);
            var arg = new object();

            function.Invoke(arg).Returns(tcs.Task);
            var target = new MVVM.Component.RelayResultCommand <object, int>(function);

            var res = target.Execute(arg).Result;

            function.Received(1).Invoke(arg);
            res.Should().Be(35);
        }