public void DoacaoController_AdicionarDadosInvalidos_BadRequest()
        {
            // Arrange
            var doacao = _doacaoFixture.DoacaoInvalida();
            var doacaoModelInvalida = new DoacaoViewModel();

            _mapper.Setup(a => a.Map <DoacaoViewModel, Doacao>(doacaoModelInvalida)).Returns(doacao);

            _doacaoController = new DoacoesController(_doacaoService, _domainNotificationService, _toastNotification.Object);

            // Act
            var retorno = _doacaoController.Create(doacaoModelInvalida);

            // Assert
            retorno.Should().BeOfType <ViewResult>();

            _mapper.Verify(a => a.Map <DoacaoViewModel, Doacao>(doacaoModelInvalida), Times.Once);
            _doacaoRepository.Verify(a => a.AdicionarAsync(doacao), Times.Never);
            _toastNotification.Verify(a => a.AddErrorToastMessage(It.IsAny <string>(), It.IsAny <LibraryOptions>()), Times.Once);

            var viewResult = ((ViewResult)retorno);

            viewResult.Model.Should().BeOfType <DoacaoViewModel>();

            ((DoacaoViewModel)viewResult.Model).Should().Be(doacaoModelInvalida);
        }
Esempio n. 2
0
        public void DonationController_CheckForValidEntry()
        {
            donationController = new DoacoesController(donationService, notificationService, toastNotification.Object);

            IActionResult response = donationController.Create(validDonationVM);

            mapper.Verify(a => a.Map <DoacaoViewModel, Doacao>(validDonationVM), Times.Once);
            toastNotification.Verify(a => a.AddSuccessToastMessage(It.IsAny <string>(), It.IsAny <LibraryOptions>()), Times.Once);
            response.Should().BeOfType <RedirectToActionResult>();
            (response as RedirectToActionResult).ActionName.Should().Be("Index");
            (response as RedirectToActionResult).ControllerName.Should().Be("Home");
        }
        public void DoacaoController_Adicionar_RetornaDadosComSucesso()
        {
            // Arrange
            _doacaoController = new DoacoesController(_doacaoService, _domainNotificationService, _toastNotification.Object);

            // Act
            var retorno = _doacaoController.Create(_doacaoModelValida);

            _mapper.Verify(a => a.Map <DoacaoViewModel, Doacao>(_doacaoModelValida), Times.Once);
            _toastNotification.Verify(a => a.AddSuccessToastMessage(It.IsAny <string>(), It.IsAny <LibraryOptions>()), Times.Once);

            retorno.Should().BeOfType <RedirectToActionResult>();

            ((RedirectToActionResult)retorno).ActionName.Should().Be("Index");
            ((RedirectToActionResult)retorno).ControllerName.Should().Be("Home");
        }
Esempio n. 4
0
        public void DonationController_CheckForInvalidData()
        {
            var invalidDonation   = donFix.Empty();
            var invalidDonationVM = new DoacaoViewModel();

            mapper.Setup(a => a.Map <DoacaoViewModel, Doacao>(invalidDonationVM)).Returns(invalidDonation);
            donationController = new DoacoesController(donationService, notificationService, toastNotification.Object);

            var response = donationController.Create(invalidDonationVM);

            response.Should().BeOfType <ViewResult>();
            mapper.Verify(a => a.Map <DoacaoViewModel, Doacao>(invalidDonationVM), Times.Once);
            donationRepository.Verify(a => a.AdicionarAsync(invalidDonation), Times.Never);
            toastNotification.Verify(a => a.AddErrorToastMessage(It.IsAny <string>(), It.IsAny <LibraryOptions>()), Times.Once);
            (response as ViewResult).Model.Should().BeOfType <DoacaoViewModel>();
            ((response as ViewResult).Model as DoacaoViewModel).Should().Be(invalidDonationVM);
        }