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); }
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); }
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); }
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); }
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); }
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); }