public void TestAtExecuteKalderHandleExceptionOnExceptionHandlerViewModelVedExceptions() { var fixture = new Fixture(); fixture.Customize <DateTime>(e => e.FromFactory(() => DateTime.Now)); fixture.Customize <IBudgetkontogruppeViewModel>(e => e.FromFactory(() => { var mock = MockRepository.GenerateMock <IBudgetkontogruppeViewModel>(); mock.Expect(m => m.Nummer) .Return(fixture.Create <int>()) .Repeat.Any(); return(mock); })); var dependencyCommandMock = MockRepository.GenerateMock <ITaskableCommand>(); dependencyCommandMock.Expect(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.TypeOf)) .Return(false) .Repeat.Any(); var exception = fixture.Create <IntranetGuiRepositoryException>(); Func <IBudgetkontoModel> budgetkontoModelGetter = () => { throw exception; }; var finansstyringRepositoryMock = MockRepository.GenerateMock <IFinansstyringRepository>(); finansstyringRepositoryMock.Expect(m => m.BudgetkontoGetAsync(Arg <int> .Is.GreaterThan(0), Arg <string> .Is.NotNull, Arg <DateTime> .Is.GreaterThan(DateTime.MinValue))) .Return(Task.Run(budgetkontoModelGetter)) .Repeat.Any(); var exceptionHandlerMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); var regnskabsnummer = fixture.Create <int>(); var budgetkontogruppeViewModelMockCollection = fixture.CreateMany <IBudgetkontogruppeViewModel>(7).ToList(); var regnskabViewModelMock = MockRepository.GenerateMock <IRegnskabViewModel>(); regnskabViewModelMock.Expect(m => m.Nummer) .Return(regnskabsnummer) .Repeat.Any(); regnskabViewModelMock.Expect(m => m.Budgetkontogrupper) .Return(budgetkontogruppeViewModelMockCollection) .Repeat.Any(); var kontonummer = fixture.Create <string>(); var statusDato = fixture.Create <DateTime>(); var budgetkontoViewModelMock = MockRepository.GenerateMock <IBudgetkontoViewModel>(); budgetkontoViewModelMock.Expect(m => m.Regnskab) .Return(regnskabViewModelMock) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.Kontonummer) .Return(kontonummer) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.StatusDato) .Return(statusDato) .Repeat.Any(); var command = new BudgetkontoGetCommand(dependencyCommandMock, finansstyringRepositoryMock, exceptionHandlerMock); Assert.That(command, Is.Not.Null); Assert.That(command.ExecuteTask, Is.Null); Action action = () => { command.Execute(budgetkontoViewModelMock); Assert.That(command.ExecuteTask, Is.Not.Null); command.ExecuteTask.Wait(); }; Task.Run(action).Wait(3000); budgetkontoViewModelMock.AssertWasCalled(m => m.Regnskab); dependencyCommandMock.AssertWasCalled(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.Equal(regnskabViewModelMock))); dependencyCommandMock.AssertWasNotCalled(m => m.Execute(Arg <object> .Is.Anything)); dependencyCommandMock.AssertWasNotCalled(m => m.ExecuteTask); finansstyringRepositoryMock.AssertWasCalled(m => m.BudgetkontoGetAsync(Arg <int> .Is.Equal(regnskabsnummer), Arg <string> .Is.Equal(kontonummer), Arg <DateTime> .Is.Equal(statusDato))); exceptionHandlerMock.AssertWasCalled(m => m.HandleException(Arg <IntranetGuiSystemException> .Is.Equal(exception))); }
public void TestAtExecuteOpdatererBudgetkontoViewModel() { var fixture = new Fixture(); fixture.Customize <DateTime>(e => e.FromFactory(() => DateTime.Now)); fixture.Customize <IBudgetkontoModel>(e => e.FromFactory(() => { var mock = MockRepository.GenerateMock <IBudgetkontoModel>(); mock.Expect(m => m.Kontonavn) .Return(fixture.Create <string>()) .Repeat.Any(); mock.Expect(m => m.Beskrivelse) .Return(fixture.Create <string>()) .Repeat.Any(); mock.Expect(m => m.Notat) .Return(fixture.Create <string>()) .Repeat.Any(); mock.Expect(m => m.Kontogruppe) .Return(fixture.Create <int>()) .Repeat.Any(); mock.Expect(m => m.StatusDato) .Return(fixture.Create <DateTime>().AddHours(3)) .Repeat.Any(); mock.Expect(m => m.Indtægter) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.Udgifter) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.BudgetSidsteMåned) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.BudgetÅrTilDato) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.BudgetSidsteÅr) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.Bogført) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.BogførtSidsteMåned) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.BogførtÅrTilDato) .Return(fixture.Create <decimal>()) .Repeat.Any(); mock.Expect(m => m.BogførtSidsteÅr) .Return(fixture.Create <decimal>()) .Repeat.Any(); return(mock); })); fixture.Customize <IBudgetkontogruppeViewModel>(e => e.FromFactory(() => { var mock = MockRepository.GenerateMock <IBudgetkontogruppeViewModel>(); mock.Expect(m => m.Nummer) .Return(fixture.Create <int>()) .Repeat.Any(); return(mock); })); var dependencyCommandMock = MockRepository.GenerateMock <ITaskableCommand>(); dependencyCommandMock.Expect(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.TypeOf)) .Return(false) .Repeat.Any(); var budgetkontoModelMock = fixture.Create <IBudgetkontoModel>(); Func <IBudgetkontoModel> budgetkontoModelGetter = () => budgetkontoModelMock; var finansstyringRepositoryMock = MockRepository.GenerateMock <IFinansstyringRepository>(); finansstyringRepositoryMock.Expect(m => m.BudgetkontoGetAsync(Arg <int> .Is.GreaterThan(0), Arg <string> .Is.NotNull, Arg <DateTime> .Is.GreaterThan(DateTime.MinValue))) .Return(Task.Run(budgetkontoModelGetter)) .Repeat.Any(); var exceptionHandlerMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); var regnskabsnummer = fixture.Create <int>(); var budgetkontogruppeViewModelMockCollection = fixture.CreateMany <IBudgetkontogruppeViewModel>(6).ToList(); var budgetkontogruppeViewModelMock = MockRepository.GenerateMock <IBudgetkontogruppeViewModel>(); budgetkontogruppeViewModelMock.Expect(m => m.Nummer) .Return(budgetkontoModelMock.Kontogruppe) .Repeat.Any(); budgetkontogruppeViewModelMockCollection.Add(budgetkontogruppeViewModelMock); var regnskabViewModelMock = MockRepository.GenerateMock <IRegnskabViewModel>(); regnskabViewModelMock.Expect(m => m.Nummer) .Return(regnskabsnummer) .Repeat.Any(); regnskabViewModelMock.Expect(m => m.Budgetkontogrupper) .Return(budgetkontogruppeViewModelMockCollection) .Repeat.Any(); var kontonummer = fixture.Create <string>(); var statusDato = fixture.Create <DateTime>(); var budgetkontoViewModelMock = MockRepository.GenerateMock <IBudgetkontoViewModel>(); budgetkontoViewModelMock.Expect(m => m.Regnskab) .Return(regnskabViewModelMock) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.Kontonummer) .Return(kontonummer) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.StatusDato) .Return(statusDato) .Repeat.Any(); var command = new BudgetkontoGetCommand(dependencyCommandMock, finansstyringRepositoryMock, exceptionHandlerMock); Assert.That(command, Is.Not.Null); Assert.That(command.ExecuteTask, Is.Null); Action action = () => { command.Execute(budgetkontoViewModelMock); Assert.That(command.ExecuteTask, Is.Not.Null); command.ExecuteTask.Wait(); }; Task.Run(action).Wait(3000); budgetkontoViewModelMock.AssertWasCalled(m => m.Regnskab); dependencyCommandMock.AssertWasCalled(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.Equal(regnskabViewModelMock))); dependencyCommandMock.AssertWasNotCalled(m => m.Execute(Arg <object> .Is.Anything)); dependencyCommandMock.AssertWasNotCalled(m => m.ExecuteTask); finansstyringRepositoryMock.AssertWasCalled(m => m.BudgetkontoGetAsync(Arg <int> .Is.Equal(regnskabsnummer), Arg <string> .Is.Equal(kontonummer), Arg <DateTime> .Is.Equal(statusDato))); regnskabViewModelMock.AssertWasCalled(m => m.Budgetkontogrupper); budgetkontoViewModelMock.AssertWasCalled(m => m.Kontonavn = Arg <string> .Is.Equal(budgetkontoModelMock.Kontonavn)); budgetkontoViewModelMock.AssertWasCalled(m => m.Beskrivelse = Arg <string> .Is.Equal(budgetkontoModelMock.Beskrivelse)); budgetkontoViewModelMock.AssertWasCalled(m => m.Notat = Arg <string> .Is.Equal(budgetkontoModelMock.Notat)); budgetkontoViewModelMock.AssertWasCalled(m => m.Kontogruppe = Arg <IBudgetkontogruppeViewModel> .Is.NotNull); budgetkontoViewModelMock.AssertWasCalled(m => m.StatusDato = Arg <DateTime> .Is.Equal(budgetkontoModelMock.StatusDato)); budgetkontoViewModelMock.AssertWasCalled(m => m.Indtægter = Arg <decimal> .Is.Equal(budgetkontoModelMock.Indtægter)); budgetkontoViewModelMock.AssertWasCalled(m => m.Udgifter = Arg <decimal> .Is.Equal(budgetkontoModelMock.Udgifter)); budgetkontoViewModelMock.AssertWasCalled(m => m.BudgetSidsteMåned = Arg <decimal> .Is.Equal(budgetkontoModelMock.BudgetSidsteMåned)); budgetkontoViewModelMock.AssertWasCalled(m => m.BudgetÅrTilDato = Arg <decimal> .Is.Equal(budgetkontoModelMock.BudgetÅrTilDato)); budgetkontoViewModelMock.AssertWasCalled(m => m.BudgetSidsteÅr = Arg <decimal> .Is.Equal(budgetkontoModelMock.BudgetSidsteÅr)); budgetkontoViewModelMock.AssertWasCalled(m => m.Bogført = Arg <decimal> .Is.Equal(budgetkontoModelMock.Bogført)); budgetkontoViewModelMock.AssertWasCalled(m => m.BogførtSidsteMåned = Arg <decimal> .Is.Equal(budgetkontoModelMock.BogførtSidsteMåned)); budgetkontoViewModelMock.AssertWasCalled(m => m.BogførtÅrTilDato = Arg <decimal> .Is.Equal(budgetkontoModelMock.BogførtÅrTilDato)); budgetkontoViewModelMock.AssertWasCalled(m => m.BogførtSidsteÅr = Arg <decimal> .Is.Equal(budgetkontoModelMock.BogførtSidsteÅr)); exceptionHandlerMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything)); }
public void TestAtExecuteKalderHandleExceptionOnExceptionHandlerViewModelMedIntranetGuiSystemExceptionHvisBudgetkontogruppeViewModelIkkeFindes() { var fixture = new Fixture(); fixture.Customize <DateTime>(e => e.FromFactory(() => DateTime.Now)); fixture.Customize <IBudgetkontoModel>(e => e.FromFactory(() => { var mock = MockRepository.GenerateMock <IBudgetkontoModel>(); mock.Expect(m => m.Kontogruppe) .Return(fixture.Create <int>()) .Repeat.Any(); return(mock); })); fixture.Customize <IBudgetkontogruppeViewModel>(e => e.FromFactory(() => { var mock = MockRepository.GenerateMock <IBudgetkontogruppeViewModel>(); mock.Expect(m => m.Nummer) .Return(fixture.Create <int>()) .Repeat.Any(); return(mock); })); var dependencyCommandMock = MockRepository.GenerateMock <ITaskableCommand>(); dependencyCommandMock.Expect(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.TypeOf)) .Return(false) .Repeat.Any(); var budgetkontoModelMock = fixture.Create <IBudgetkontoModel>(); Func <IBudgetkontoModel> budgetkontoModelGetter = () => budgetkontoModelMock; var finansstyringRepositoryMock = MockRepository.GenerateMock <IFinansstyringRepository>(); finansstyringRepositoryMock.Expect(m => m.BudgetkontoGetAsync(Arg <int> .Is.GreaterThan(0), Arg <string> .Is.NotNull, Arg <DateTime> .Is.GreaterThan(DateTime.MinValue))) .Return(Task.Run(budgetkontoModelGetter)) .Repeat.Any(); var exceptionHandlerMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); exceptionHandlerMock.Expect(m => m.HandleException(Arg <IntranetGuiSystemException> .Is.TypeOf)) .WhenCalled(e => { var exception = (IntranetGuiSystemException)e.Arguments.ElementAt(0); Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.Not.Null); Assert.That(exception.Message, Is.Not.Empty); Assert.That(exception.Message, Is.EqualTo(Resource.GetExceptionMessage(ExceptionMessage.BudgetAccountGroupNotFound, budgetkontoModelMock.Kontogruppe))); Assert.That(exception.InnerException, Is.Null); }) .Repeat.Any(); var regnskabsnummer = fixture.Create <int>(); var budgetkontogruppeViewModelMockCollection = fixture.CreateMany <IBudgetkontogruppeViewModel>(7).ToList(); var regnskabViewModelMock = MockRepository.GenerateMock <IRegnskabViewModel>(); regnskabViewModelMock.Expect(m => m.Nummer) .Return(regnskabsnummer) .Repeat.Any(); regnskabViewModelMock.Expect(m => m.Budgetkontogrupper) .Return(budgetkontogruppeViewModelMockCollection) .Repeat.Any(); var kontonummer = fixture.Create <string>(); var statusDato = fixture.Create <DateTime>(); var budgetkontoViewModelMock = MockRepository.GenerateMock <IBudgetkontoViewModel>(); budgetkontoViewModelMock.Expect(m => m.Regnskab) .Return(regnskabViewModelMock) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.Kontonummer) .Return(kontonummer) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.StatusDato) .Return(statusDato) .Repeat.Any(); var command = new BudgetkontoGetCommand(dependencyCommandMock, finansstyringRepositoryMock, exceptionHandlerMock); Assert.That(command, Is.Not.Null); Assert.That(command.ExecuteTask, Is.Null); Action action = () => { command.Execute(budgetkontoViewModelMock); Assert.That(command.ExecuteTask, Is.Not.Null); command.ExecuteTask.Wait(); }; Task.Run(action).Wait(3000); budgetkontoViewModelMock.AssertWasCalled(m => m.Regnskab); dependencyCommandMock.AssertWasCalled(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.Equal(regnskabViewModelMock))); dependencyCommandMock.AssertWasNotCalled(m => m.Execute(Arg <object> .Is.Anything)); dependencyCommandMock.AssertWasNotCalled(m => m.ExecuteTask); finansstyringRepositoryMock.AssertWasCalled(m => m.BudgetkontoGetAsync(Arg <int> .Is.Equal(regnskabsnummer), Arg <string> .Is.Equal(kontonummer), Arg <DateTime> .Is.Equal(statusDato))); regnskabViewModelMock.AssertWasCalled(m => m.Budgetkontogrupper); budgetkontoViewModelMock.AssertWasNotCalled(m => m.Kontonavn = Arg <string> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.Beskrivelse = Arg <string> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.Notat = Arg <string> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.Kontogruppe = Arg <IBudgetkontogruppeViewModel> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.StatusDato = Arg <DateTime> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.Indtægter = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.Udgifter = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.BudgetSidsteMåned = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.BudgetÅrTilDato = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.BudgetSidsteÅr = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.Bogført = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.BogførtSidsteMåned = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.BogførtÅrTilDato = Arg <decimal> .Is.Anything); budgetkontoViewModelMock.AssertWasNotCalled(m => m.BogførtSidsteÅr = Arg <decimal> .Is.Anything); exceptionHandlerMock.AssertWasCalled(m => m.HandleException(Arg <IntranetGuiSystemException> .Is.TypeOf)); }
public void TestAtExecuteExecuteDependencyCommandHvisCanExecuteOnDepencendyCommandErTrue() { var fixture = new Fixture(); fixture.Customize <DateTime>(e => e.FromFactory(() => DateTime.Now)); var dependencyCommandMock = MockRepository.GenerateMock <ITaskableCommand>(); dependencyCommandMock.Expect(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.TypeOf)) .Return(true) .Repeat.Any(); dependencyCommandMock.Expect(m => m.ExecuteTask) .Return(Task.Run(() => Thread.Sleep(1000))) .Repeat.Any(); Func <IBudgetkontoModel> budgetkontoModelGetter = () => null; var finansstyringRepositoryMock = MockRepository.GenerateMock <IFinansstyringRepository>(); finansstyringRepositoryMock.Expect(m => m.BudgetkontoGetAsync(Arg <int> .Is.GreaterThan(0), Arg <string> .Is.NotNull, Arg <DateTime> .Is.GreaterThan(DateTime.MinValue))) .Return(Task.Run(budgetkontoModelGetter)) .Repeat.Any(); var exceptionHandlerMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>(); var regnskabsnummer = fixture.Create <int>(); var regnskabViewModelMock = MockRepository.GenerateMock <IRegnskabViewModel>(); regnskabViewModelMock.Expect(m => m.Nummer) .Return(regnskabsnummer) .Repeat.Any(); regnskabViewModelMock.Expect(m => m.Budgetkontogrupper) .Return(new List <IBudgetkontogruppeViewModel>(0)) .Repeat.Any(); var kontonummer = fixture.Create <string>(); var statusDato = fixture.Create <DateTime>(); var budgetkontoViewModelMock = MockRepository.GenerateMock <IBudgetkontoViewModel>(); budgetkontoViewModelMock.Expect(m => m.Regnskab) .Return(regnskabViewModelMock) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.Kontonummer) .Return(kontonummer) .Repeat.Any(); budgetkontoViewModelMock.Expect(m => m.StatusDato) .Return(statusDato) .Repeat.Any(); var command = new BudgetkontoGetCommand(dependencyCommandMock, finansstyringRepositoryMock, exceptionHandlerMock); Assert.That(command, Is.Not.Null); Assert.That(command.ExecuteTask, Is.Null); Action action = () => { command.Execute(budgetkontoViewModelMock); Assert.That(command.ExecuteTask, Is.Not.Null); command.ExecuteTask.Wait(); }; Task.Run(action).Wait(3000); budgetkontoViewModelMock.AssertWasCalled(m => m.Regnskab); dependencyCommandMock.AssertWasCalled(m => m.CanExecute(Arg <IRegnskabViewModel> .Is.Equal(regnskabViewModelMock))); dependencyCommandMock.AssertWasCalled(m => m.Execute(Arg <IRegnskabViewModel> .Is.Equal(regnskabViewModelMock))); dependencyCommandMock.AssertWasCalled(m => m.ExecuteTask); finansstyringRepositoryMock.AssertWasCalled(m => m.BudgetkontoGetAsync(Arg <int> .Is.Equal(regnskabsnummer), Arg <string> .Is.Equal(kontonummer), Arg <DateTime> .Is.Equal(statusDato))); exceptionHandlerMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything)); }