Beispiel #1
0
        public void TestAtExecuteKalderHandleExceptionOnExceptionHandlerViewModelMedIntranetGuiSystemExceptionHvisKontogruppeViewModelIkkeFindes()
        {
            var fixture = new Fixture();

            fixture.Customize <DateTime>(e => e.FromFactory(() => DateTime.Now));
            fixture.Customize <IKontoModel>(e => e.FromFactory(() =>
            {
                var mock = MockRepository.GenerateMock <IKontoModel>();
                mock.Expect(m => m.Kontogruppe)
                .Return(fixture.Create <int>())
                .Repeat.Any();
                return(mock);
            }));
            fixture.Customize <IKontogruppeViewModel>(e => e.FromFactory(() =>
            {
                var mock = MockRepository.GenerateMock <IKontogruppeViewModel>();
                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 kontoModelMock = fixture.Create <IKontoModel>();
            Func <IKontoModel> kontoModelGetter = () => kontoModelMock;
            var finansstyringRepositoryMock     = MockRepository.GenerateMock <IFinansstyringRepository>();

            finansstyringRepositoryMock.Expect(m => m.KontoGetAsync(Arg <int> .Is.GreaterThan(0), Arg <string> .Is.NotNull, Arg <DateTime> .Is.GreaterThan(DateTime.MinValue)))
            .Return(Task.Run(kontoModelGetter))
            .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.AccountGroupNotFound, kontoModelMock.Kontogruppe)));
                Assert.That(exception.InnerException, Is.Null);
            })
            .Repeat.Any();

            var regnskabsnummer = fixture.Create <int>();
            var kontogruppeViewModelMockCollection = fixture.CreateMany <IKontogruppeViewModel>(7).ToList();
            var regnskabViewModelMock = MockRepository.GenerateMock <IRegnskabViewModel>();

            regnskabViewModelMock.Expect(m => m.Nummer)
            .Return(regnskabsnummer)
            .Repeat.Any();
            regnskabViewModelMock.Expect(m => m.Kontogrupper)
            .Return(kontogruppeViewModelMockCollection)
            .Repeat.Any();

            var kontonummer        = fixture.Create <string>();
            var statusDato         = fixture.Create <DateTime>();
            var kontoViewModelMock = MockRepository.GenerateMock <IKontoViewModel>();

            kontoViewModelMock.Expect(m => m.Regnskab)
            .Return(regnskabViewModelMock)
            .Repeat.Any();
            kontoViewModelMock.Expect(m => m.Kontonummer)
            .Return(kontonummer)
            .Repeat.Any();
            kontoViewModelMock.Expect(m => m.StatusDato)
            .Return(statusDato)
            .Repeat.Any();

            var command = new KontoGetCommand(dependencyCommandMock, finansstyringRepositoryMock, exceptionHandlerMock);

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

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

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

            kontoViewModelMock.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.KontoGetAsync(Arg <int> .Is.Equal(regnskabsnummer), Arg <string> .Is.Equal(kontonummer), Arg <DateTime> .Is.Equal(statusDato)));
            regnskabViewModelMock.AssertWasCalled(m => m.Kontogrupper);
            kontoViewModelMock.AssertWasNotCalled(m => m.Kontonavn   = Arg <string> .Is.Anything);
            kontoViewModelMock.AssertWasNotCalled(m => m.Beskrivelse = Arg <string> .Is.Anything);
            kontoViewModelMock.AssertWasNotCalled(m => m.Notat       = Arg <string> .Is.Anything);
            kontoViewModelMock.AssertWasNotCalled(m => m.Kontogruppe = Arg <IKontogruppeViewModel> .Is.Anything);
            kontoViewModelMock.AssertWasNotCalled(m => m.StatusDato  = Arg <DateTime> .Is.Anything);
            kontoViewModelMock.AssertWasNotCalled(m => m.Kredit      = Arg <decimal> .Is.Anything);
            kontoViewModelMock.AssertWasNotCalled(m => m.Saldo       = Arg <decimal> .Is.Anything);
            exceptionHandlerMock.AssertWasCalled(m => m.HandleException(Arg <IntranetGuiSystemException> .Is.TypeOf));
        }
Beispiel #2
0
        public void TestAtExecuteKalderHandleExceptionOnExceptionHandlerViewModelVedExceptions()
        {
            var fixture = new Fixture();

            fixture.Customize <DateTime>(e => e.FromFactory(() => DateTime.Now));
            fixture.Customize <IKontogruppeViewModel>(e => e.FromFactory(() =>
            {
                var mock = MockRepository.GenerateMock <IKontogruppeViewModel>();
                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 <IKontoModel> kontoModelGetter = () =>
            {
                throw exception;
            };
            var finansstyringRepositoryMock = MockRepository.GenerateMock <IFinansstyringRepository>();

            finansstyringRepositoryMock.Expect(m => m.KontoGetAsync(Arg <int> .Is.GreaterThan(0), Arg <string> .Is.NotNull, Arg <DateTime> .Is.GreaterThan(DateTime.MinValue)))
            .Return(Task.Run(kontoModelGetter))
            .Repeat.Any();

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

            var regnskabsnummer = fixture.Create <int>();
            var kontogruppeViewModelMockCollection = fixture.CreateMany <IKontogruppeViewModel>(7).ToList();
            var regnskabViewModelMock = MockRepository.GenerateMock <IRegnskabViewModel>();

            regnskabViewModelMock.Expect(m => m.Nummer)
            .Return(regnskabsnummer)
            .Repeat.Any();
            regnskabViewModelMock.Expect(m => m.Kontogrupper)
            .Return(kontogruppeViewModelMockCollection)
            .Repeat.Any();

            var kontonummer        = fixture.Create <string>();
            var statusDato         = fixture.Create <DateTime>();
            var kontoViewModelMock = MockRepository.GenerateMock <IKontoViewModel>();

            kontoViewModelMock.Expect(m => m.Regnskab)
            .Return(regnskabViewModelMock)
            .Repeat.Any();
            kontoViewModelMock.Expect(m => m.Kontonummer)
            .Return(kontonummer)
            .Repeat.Any();
            kontoViewModelMock.Expect(m => m.StatusDato)
            .Return(statusDato)
            .Repeat.Any();

            var command = new KontoGetCommand(dependencyCommandMock, finansstyringRepositoryMock, exceptionHandlerMock);

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

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

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

            kontoViewModelMock.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.KontoGetAsync(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)));
        }
Beispiel #3
0
        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 <IKontoModel> kontoModelGetter = () => null;
            var finansstyringRepositoryMock     = MockRepository.GenerateMock <IFinansstyringRepository>();

            finansstyringRepositoryMock.Expect(m => m.KontoGetAsync(Arg <int> .Is.GreaterThan(0), Arg <string> .Is.NotNull, Arg <DateTime> .Is.GreaterThan(DateTime.MinValue)))
            .Return(Task.Run(kontoModelGetter))
            .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.Kontogrupper)
            .Return(new List <IKontogruppeViewModel>(0))
            .Repeat.Any();

            var kontonummer        = fixture.Create <string>();
            var statusDato         = fixture.Create <DateTime>();
            var kontoViewModelMock = MockRepository.GenerateMock <IKontoViewModel>();

            kontoViewModelMock.Expect(m => m.Regnskab)
            .Return(regnskabViewModelMock)
            .Repeat.Any();
            kontoViewModelMock.Expect(m => m.Kontonummer)
            .Return(kontonummer)
            .Repeat.Any();
            kontoViewModelMock.Expect(m => m.StatusDato)
            .Return(statusDato)
            .Repeat.Any();

            var command = new KontoGetCommand(dependencyCommandMock, finansstyringRepositoryMock, exceptionHandlerMock);

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

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

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

            kontoViewModelMock.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.KontoGetAsync(Arg <int> .Is.Equal(regnskabsnummer), Arg <string> .Is.Equal(kontonummer), Arg <DateTime> .Is.Equal(statusDato)));
            exceptionHandlerMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything));
        }