public void TestAtHandleResultFromTaskKalderHandleExceptionOnExceptionHandlerViewModelHvisOnHandleTaskResultKasterException() { var fixture = new Fixture(); fixture.Customize <IModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IModel>())); fixture.Customize <IViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IViewModel>())); var exceptionHandlerViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); var actionCalled = false; var exception = fixture.Create <IntranetGuiBusinessException>(); Action <IViewModel, IModel, object> onHandleResult = (viewMode, model, argument) => { actionCalled = true; throw exception; }; var modelMock = fixture.Create <IModel>(); Func <IModel> modelGetter = () => modelMock; var command = new MyViewModelCommand(exceptionHandlerViewModelMock); Assert.That(command, Is.Not.Null); Assert.That(actionCalled, Is.False); Task.Run(async() => { var task = Task.Run(modelGetter); await task.ContinueWith(t => command.HandleResultFromTask(t, fixture.Create <IViewModel>(), null, onHandleResult)); }).Wait(3000); Assert.That(actionCalled, Is.True); exceptionHandlerViewModelMock.AssertWasCalled(m => m.HandleException(Arg <IntranetGuiBusinessException> .Is.TypeOf)); }
public void TestAtHandleResultFromTaskIkkeKalderOnHandleTaskResultHvisResultErNull() { var fixture = new Fixture(); fixture.Customize <IModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IModel>())); fixture.Customize <IViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IViewModel>())); var exceptionHandlerViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); var actionCalled = false; Action <IViewModel, IModel, object> onHandleResult = (viewMode, model, argument) => { actionCalled = true; }; Func <IModel> modelGetter = () => null; var command = new MyViewModelCommand(exceptionHandlerViewModelMock); Assert.That(command, Is.Not.Null); Assert.That(actionCalled, Is.False); Task.Run(async() => { var task = Task.Run(modelGetter); await task.ContinueWith(t => command.HandleResultFromTask(t, fixture.Create <IViewModel>(), null, onHandleResult)); }).Wait(3000); Assert.That(actionCalled, Is.False); exceptionHandlerViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything)); }
public void TestAtHandleResultFromTaskKasterArgumentNullExceptionHvisTaskErNull() { var fixture = new Fixture(); fixture.Customize <IModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IModel>())); fixture.Customize <IViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IViewModel>())); var exceptionHandlerViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); Action <IViewModel, IModel, object> onHandleResult = (viewMode, model, argument) => { }; onHandleResult.Invoke(fixture.Create <IViewModel>(), fixture.Create <IModel>(), null); var command = new MyViewModelCommand(exceptionHandlerViewModelMock); Assert.That(command, Is.Not.Null); var exception = Assert.Throws <ArgumentNullException>(() => command.HandleResultFromTask(null, fixture.Create <IViewModel>(), null, onHandleResult)); Assert.That(exception, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Empty); Assert.That(exception.ParamName, Is.EqualTo("task")); Assert.That(exception.InnerException, Is.Null); exceptionHandlerViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything)); }
public void TestAtHandleResultFromTaskKasterArgumentNullExceptionHvisViewModelErNull() { var fixture = new Fixture(); fixture.Customize <IModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IModel>())); fixture.Customize <IViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IViewModel>())); var exceptionHandlerViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); Action <IViewModel, IModel, object> onHandleResult = (viewMode, model, argument) => { }; onHandleResult.Invoke(fixture.Create <IViewModel>(), fixture.Create <IModel>(), null); var modelMock = fixture.Create <IModel>(); Func <IModel> modelGetter = () => modelMock; var command = new MyViewModelCommand(exceptionHandlerViewModelMock); Assert.That(command, Is.Not.Null); ArgumentNullException exception = null; var aggregateException = Assert.Throws <AggregateException>(() => { var task = Task.Run(modelGetter); task.ContinueWith(t => command.HandleResultFromTask(t, null, null, onHandleResult)).Wait(); }); aggregateException.Handle(e => { exception = e as ArgumentNullException; return(true); }); Assert.That(exception, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Empty); Assert.That(exception.ParamName, Is.EqualTo("viewModel")); Assert.That(exception.InnerException, Is.Null); exceptionHandlerViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything)); }