예제 #1
0
        private void SaveNewPersonsExecute()
        {
            var command = new AddPersonWithEmployer(_mapper.Map <Worker>(SelectedPerson.PersonModel));

            _commandDispatcher.Dispatch <AddPersonWithEmployer, Result>(command)
            .Tap(() =>
            {
                var viewModel = _personViewModelFunc(SelectedPerson.PersonModel);
                Persons.Add(viewModel);
            })
            .OnFailure(details =>
                       _messageDialogFunc().ShowErrorMessage(GetType().Name, "Failed to add person into database", details));
        }
        public void Completes_Transaction_After_Succesful_Run()
        {
            var command = new AddPersonWithEmployer(new Worker());
            var handler = new AddPersonWithEmployerCommandHandler(_unitOfWorkMock.Object);

            _unitOfWorkMock
            .Setup(m => m.Workers.AddWorker(It.IsAny <Worker>()))
            .Returns(() => true);

            handler.Handle(command);

            _unitOfWorkMock.Verify(m => m.Complete(), Times.Once);
        }
        public void Returns_Failed_Result_When_Transaction_With_Database_Throws_Exception()
        {
            var command = new AddPersonWithEmployer(new Worker());
            var handler = new AddPersonWithEmployerCommandHandler(_unitOfWorkMock.Object);

            _unitOfWorkMock
            .Setup(m => m.Workers.AddWorker(It.IsAny <Worker>()))
            .Returns(() => throw new Exception());

            var result = handler.Handle(command);

            Assert.True(result.IsFailure);
        }
        public void Uses_Persistency_To_Add_New_Worker_Into_Database()
        {
            var command = new AddPersonWithEmployer(new Worker());
            var handler = new AddPersonWithEmployerCommandHandler(_unitOfWorkMock.Object);

            _unitOfWorkMock
            .Setup(m => m.Workers.AddWorker(It.IsAny <Worker>()))
            .Returns(() => true);

            handler.Handle(command);

            _unitOfWorkMock.Verify(m => m.Workers.AddWorker(It.IsAny <Worker>()), Times.Once);
        }
        public void After_Succesful_Transaction_Completes_Operation()
        {
            var command = new AddPersonWithEmployer(new Worker());
            var handler = new AddPersonWithEmployerCommandHandler(_unitOfWorkMock.Object);

            _unitOfWorkMock
            .Setup(m => m.Workers.AddWorker(It.IsAny <Worker>()))
            .Returns(true);

            var result = handler.Handle(command);

            if (result.IsSuccess)
            {
                _unitOfWorkMock.Verify(m => m.Complete(), Times.Once);
            }
            else
            {
                _unitOfWorkMock.Verify(m => m.Complete(), Times.Never);
            }
        }