public void TestAtExecuteKalderHandleExceptionOnExceptionHandlerViewModelVedException()
        {
            var fixture = new Fixture();

            fixture.Customize <IRegnskabViewModel>(e => e.FromFactory(() =>
            {
                var mock = MockRepository.GenerateMock <IRegnskabViewModel>();
                mock.Expect(m => m.Budgetkontogrupper)
                .Return(new List <IBudgetkontogruppeViewModel>(0))
                .Repeat.Any();
                return(mock);
            }));

            var exception = fixture.Create <IntranetGuiRepositoryException>();
            Func <IEnumerable <IBudgetkontogruppeModel> > kontogruppelisteGetter = () =>
            {
                throw exception;
            };
            var finansstyringRepositoryMock = MockRepository.GenerateMock <IFinansstyringRepository>();

            finansstyringRepositoryMock.Expect(m => m.BudgetkontogruppelisteGetAsync())
            .Return(Task.Run(kontogruppelisteGetter))
            .Repeat.Any();

            var exceptionHandlerViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>();

            var regnskabViewModelMock = fixture.Create <IRegnskabViewModel>();

            var command = new BudgetkontogrupperGetCommand(finansstyringRepositoryMock, exceptionHandlerViewModelMock);

            Assert.That(command, Is.Not.Null);
            Assert.That(command.ExecuteTask, Is.Null);

            Action action = () =>
            {
                command.Execute(regnskabViewModelMock);
                Assert.That(command.ExecuteTask, Is.Not.Null);
                command.ExecuteTask.Wait();
            };

            Task.Run(action).Wait(3000);

            regnskabViewModelMock.AssertWasCalled(m => m.Budgetkontogrupper);
            finansstyringRepositoryMock.AssertWasCalled(m => m.BudgetkontogruppelisteGetAsync());
            regnskabViewModelMock.AssertWasNotCalled(m => m.BudgetkontogruppeAdd(Arg <IBudgetkontogruppeViewModel> .Is.Anything));
            exceptionHandlerViewModelMock.AssertWasCalled(m => m.HandleException(Arg <IntranetGuiRepositoryException> .Is.Equal(exception)));
        }
        public void TestAtExecuteHenterBudgetkontogrupper()
        {
            var fixture = new Fixture();

            fixture.Customize <IBudgetkontogruppeModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IBudgetkontogruppeModel>()));
            fixture.Customize <IRegnskabViewModel>(e => e.FromFactory(() =>
            {
                var mock = MockRepository.GenerateMock <IRegnskabViewModel>();
                mock.Expect(m => m.Budgetkontogrupper)
                .Return(new List <IBudgetkontogruppeViewModel>(0))
                .Repeat.Any();
                return(mock);
            }));

            var budgetkontogruppeModelMockCollection = fixture.CreateMany <IBudgetkontogruppeModel>(7).ToList();
            Func <IEnumerable <IBudgetkontogruppeModel> > kontogruppelisteGetter = () => budgetkontogruppeModelMockCollection;
            var finansstyringRepositoryMock = MockRepository.GenerateMock <IFinansstyringRepository>();

            finansstyringRepositoryMock.Expect(m => m.BudgetkontogruppelisteGetAsync())
            .Return(Task.Run(kontogruppelisteGetter))
            .Repeat.Any();

            var exceptionHandlerViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>();

            var regnskabViewModelMock = fixture.Create <IRegnskabViewModel>();

            var command = new BudgetkontogrupperGetCommand(finansstyringRepositoryMock, exceptionHandlerViewModelMock);

            Assert.That(command, Is.Not.Null);
            Assert.That(command.ExecuteTask, Is.Null);

            Action action = () =>
            {
                command.Execute(regnskabViewModelMock);
                Assert.That(command.ExecuteTask, Is.Not.Null);
                command.ExecuteTask.Wait();
            };

            Task.Run(action).Wait(3000);

            regnskabViewModelMock.AssertWasCalled(m => m.Budgetkontogrupper);
            finansstyringRepositoryMock.AssertWasCalled(m => m.BudgetkontogruppelisteGetAsync());
            regnskabViewModelMock.AssertWasCalled(m => m.BudgetkontogruppeAdd(Arg <IBudgetkontogruppeViewModel> .Is.NotNull), opt => opt.Repeat.Times(budgetkontogruppeModelMockCollection.Count));
            exceptionHandlerViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything));
        }
        public void TestAtExecuteReturnererHvisKontogrupperErHentet()
        {
            var fixture = new Fixture();

            fixture.Customize <IBudgetkontogruppeViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IBudgetkontogruppeViewModel>()));
            fixture.Customize <IRegnskabViewModel>(e => e.FromFactory(() =>
            {
                var mock = MockRepository.GenerateMock <IRegnskabViewModel>();
                mock.Expect(m => m.Budgetkontogrupper)
                .Return(fixture.CreateMany <IBudgetkontogruppeViewModel>(7).ToList())
                .Repeat.Any();
                return(mock);
            }));

            var finansstyringRepositoryMock   = MockRepository.GenerateMock <IFinansstyringRepository>();
            var exceptionHandlerViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>();

            var regnskabViewModelMock = fixture.Create <IRegnskabViewModel>();

            var command = new BudgetkontogrupperGetCommand(finansstyringRepositoryMock, exceptionHandlerViewModelMock);

            Assert.That(command, Is.Not.Null);
            Assert.That(command.ExecuteTask, Is.Null);

            Action action = () =>
            {
                command.Execute(regnskabViewModelMock);
                Assert.That(command.ExecuteTask, Is.Null);
            };

            Task.Run(action).Wait(3000);

            regnskabViewModelMock.AssertWasCalled(m => m.Budgetkontogrupper);
            finansstyringRepositoryMock.AssertWasNotCalled(m => m.BudgetkontogruppelisteGetAsync());
            exceptionHandlerViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything));
        }