public void ContasController_RegistrarConta_RetornarSucesso()
        {
            var contaViewModel = new ContaViewModel();
            var contaCommand   = new RegistrarContaCommand("Foo", DateTime.Now, 100, false, 0, "", Guid.NewGuid(), Guid.NewGuid());

            mockMapper.Setup(m => m.Map <RegistrarContaCommand>(contaViewModel)).Returns(contaCommand);
            mockNotification.Setup(m => m.GetNotifications()).Returns(new List <DomainNotification>());

            var result = contasController.Post(contaViewModel);

            mockMediator.Verify(m => m.EnviarComando(contaCommand), Times.Once);
            Assert.IsType <OkObjectResult>(result);
        }
示例#2
0
        public void Controller_Contas_Post_DevePassar()
        {
            // Arrange
            var id = 1;

            _contaServiceMock.Setup(c => c.Add(_contaRegisterCmd.Object)).Returns(id);
            // Action
            IHttpActionResult callback = _contasController.Post(_contaRegisterCmd.Object);
            // Assert
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <int> >().Subject;

            httpResponse.Content.Should().Be(id);
            _contaServiceMock.Verify(s => s.Add(_contaRegisterCmd.Object), Times.Once);
        }
示例#3
0
        public async Task PostBadRequest()
        {
            var serviceMock = new Mock <IContaService>();

            serviceMock.Setup(m => m.Post(It.IsAny <ContaDtoCreate>())).ReturnsAsync(
                new ContaDtoCreateResult
            {
                Id          = Guid.NewGuid(),
                Name        = "PV Conta",
                Description = "Conta Corrente",
                Balance     = 0,
                Status      = true,
                CreateAt    = DateTime.Now
            }
                );

            _controller = new ContasController(serviceMock.Object);
            _controller.ModelState.AddModelError("Id", "Formato Inválido");

            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;

            var contaDtoCreate = new ContaDtoCreate
            {
                Name        = "PV Conta",
                Description = "Conta Corrente",
                Status      = true
            };

            var result = await _controller.Post(contaDtoCreate);

            Assert.True(result is BadRequestObjectResult);
        }