コード例 #1
0
        public void EventosController_Registrar_RetornarComErrosDeDominio()
        {
            // Arrange
            var eventoViewModel = new EventoViewModel();

            var eventoCommand = new RegistrarEventoCommand("Teste com erros de domínio", "X", "XXX",
                                                           System.DateTime.Now, System.DateTime.Now.AddDays(1), true, 0, true, "",
                                                           System.Guid.NewGuid(), System.Guid.NewGuid(),
                                                           new IncluirEnderecoEventoCommand(System.Guid.NewGuid(), "", "", "", "", "", "", "", null));

            mockMapper.Setup(m => m.Map <RegistrarEventoCommand>(eventoViewModel)).Returns(eventoCommand);

            var notificationList = new List <DomainNotification>
            {
                new DomainNotification("Erro", "Erro ao adicionar o evento")
            };

            mockNotification.Setup(n => n.GetNotifications()).Returns(notificationList);
            mockNotification.Setup(n => n.HasNotifications()).Returns(true);

            // Act
            var result = eventosController.Post(eventoViewModel);

            // Assert
            mockMediator.Verify(m => m.EnviarComando(eventoCommand), Times.Once);
            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: RodrigoMouraBR/Lab
    static void Main(string[] args)
    {
        var bus = new FakeBus();

        // Registro com sucesso
        var cmd = new RegistrarEventoCommand("DevX", DateTime.Now.AddDays(1), DateTime.Now.AddDays(2), true, 0, true, "Empresa");

        Inicio(cmd);
        bus.SendCommand(cmd);
        Fim(cmd);

        // Registro com erros
        cmd = new RegistrarEventoCommand("", DateTime.Now.AddDays(2), DateTime.Now.AddDays(1), false, 0, false, "");
        Inicio(cmd);
        bus.SendCommand(cmd);
        Fim(cmd);

        // Atualizar Evento
        var cmd2 = new AtualizarEventoCommand(Guid.NewGuid(), "DevX", "", "", DateTime.Now.AddDays(1), DateTime.Now.AddDays(2), false, 50, true, "Empresa");

        Inicio(cmd2);
        bus.SendCommand(cmd2);
        Fim(cmd2);

        // Excluir Evento
        var cmd3 = new ExcluirEventoCommand(Guid.NewGuid());

        Inicio(cmd3);
        bus.SendCommand(cmd3);
        Fim(cmd3);

        Console.ReadKey();
    }
        // Meu código sabe validar se houve algum erro no domínio ?
        public void EventosController_RegistrarEvento_RetornarComErrosDeDominio()
        {
            // Arrange

            var eventoViewModel = new EventoViewModel();

            var eventoCommand = new RegistrarEventoCommand("Teste", "", "", DateTime.Now, DateTime.Now.AddDays(1), true,
                                                           0, true, "", Guid.NewGuid(), Guid.NewGuid(),
                                                           new IncluirEnderecoEventoCommand(Guid.NewGuid(), "", null, "", "", "", "", "", null));

            mockMapper.Setup(m => m.Map <RegistrarEventoCommand>(eventoViewModel)).Returns(eventoCommand);

            // Estou criando uma notificação de Erro de Domínio
            var notificationList = new List <DomainNotification> {
                new DomainNotification("Erro", "Erro ao adicionar o evento")
            };

            mockNotification.Setup(m => m.GetNotifications()).Returns(notificationList);
            mockNotification.Setup(c => c.HasNotifications()).Returns(true);

            // Act
            var result = eventosController.Post(new EventoViewModel());

            // Assert (Validar) : Utilizamos o AtLeastOnce para garantir que o Mediator será executado uma vez que este comando vem antes das validações de domínio
            mockMediator.Verify(m => m.EnviarComando(It.IsAny <RegistrarEventoCommand>()), Times.AtLeastOnce);
            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #4
0
        public void EventosController_RegistrarEvento_RetornarComSucesso()
        {
            //Arrange
            var eventoViewModel = new EventoViewModel();
            var eventoCommand   = new RegistrarEventoCommand
                                  (
                Guid.NewGuid(),
                "Teste", "", "", DateTime.Now, DateTime.Now.AddDays(1), true,
                0, true, "", Guid.NewGuid(), Guid.NewGuid(),

                new IncluirEnderecoEventoCommand
                (
                    Guid.NewGuid(), "", null, "", "", "", "", "", null
                )
                                  );

            mockMapper.Setup(m => m.Map <RegistrarEventoCommand>(eventoViewModel)).Returns(eventoCommand);

            //Act
            var result = eventosController.Post(eventoViewModel);

            //Assert
            mockMediator.Verify(m => m.EnviarComando(eventoCommand), Times.Once);
            Assert.IsType <OkObjectResult>(result);
        }
コード例 #5
0
 public void CriaRegistroFalho()
 {
     //  var bus = new FakeBus();
     //Criar o comando de registro com sucesso
     var cmd = new RegistrarEventoCommand(
         "Nome do Evento", "Descricao Evento", "Desc Event", DateTime.Now.AddDays(20), DateTime.Now.AddDays(20), true,
         0, true, "Wagner Nogueira", Guid.Empty, Guid.Empty, null);
     //bus.SendCommand(cmd);
 }
コード例 #6
0
        public void AtualizarEvento()
        {
            //var bus = new FakeBus();
            //Criar o comando de registro com sucesso
            var cmd = new RegistrarEventoCommand(
                "Nome do Evento", "Descricao Evento", "Desc Event", DateTime.Now.AddDays(20), DateTime.Now.AddDays(20), true,
                0, true, "Wagner Nogueira", Guid.Empty, Guid.Empty, null);
            //bus.SendCommand(cmd);

            var att = new AtualizarEventoCommand(cmd.Id, "Legal", "Descricao", "Desc", DateTime.Now.AddDays(12), DateTime.Now.AddDays(13), true, 0, true, "Wagner Nogueira", Guid.Empty, Guid.Empty);
            //bus.SendCommand(att);
        }
コード例 #7
0
        public IActionResult Post([FromBody] RegistrarEventoCommand eventoCommand)
        {
            if (!ModelState.IsValid)
            {
                NotificarErroModelStateInvalido();
                return(Response());
            }

            // Registra o evento
            _bus.SendCommand(eventoCommand);
            return(Response(eventoCommand));
        }
コード例 #8
0
        public void EventosController_Registrar_RetornarComSucesso()
        {
            // Arrange
            var eventoViewModel = new EventoViewModel();
            var eventoCommand   = new RegistrarEventoCommand("Teste", "X", "XXX",
                                                             DateTime.Now, DateTime.Now.AddDays(1), true, 0, true, "",
                                                             System.Guid.NewGuid(), Guid.NewGuid(),
                                                             new IncluirEnderecoEventoCommand(System.Guid.NewGuid(), "", "", "", "", "", "", "", null));

            // quando vc chamar o Map<xxx>(yyy) retorna o zzz
            mockMapper.Setup(m => m.Map <RegistrarEventoCommand>(eventoViewModel)).Returns(eventoCommand);
            // quando eu pedir GetNotification() retorna a lista vazia
            mockNotification.Setup(m => m.GetNotifications()).Returns(new List <DomainNotification>());

            // Act
            var result = eventosController.Post(eventoViewModel);

            // Assert
            mockMediator.Verify(m => m.EnviarComando(eventoCommand), Times.Once);
            Assert.IsType <OkObjectResult>(result);
        }
        // Eu consigo criar um evento ?
        public void EventosController_RegistrarEvento_RetornarComSucesso()
        {
            // Arrange (Criar: Estou criando uma instância representativa dos objetos que estão com injeção de dependência)

            var eventoViewModel = new EventoViewModel();
            // Estou criando um evento fake para checar as regras de validação da criação de um evento
            var eventoCommand = new RegistrarEventoCommand("Teste", "", "", DateTime.Now, DateTime.Now.AddDays(1), true,
                                                           0, true, "", Guid.NewGuid(), Guid.NewGuid(),
                                                           new IncluirEnderecoEventoCommand(Guid.NewGuid(), "", null, "", "", "", "", "", null));

            // Estou configurando o Mapper para retornar um eventoCommand quando o comando Map for utilizado
            mockMapper.Setup(m => m.Map <RegistrarEventoCommand>(eventoViewModel)).Returns(eventoCommand);
            // Estou configurando o o componente de notificações para retornar uma lista vazia de notificações
            mockNotification.Setup(m => m.GetNotifications()).Returns(new List <DomainNotification>());

            // Act (Testar)
            var result = eventosController.Post(eventoViewModel);

            // Assert (Validar)
            mockMediator.Verify(m => m.EnviarComando(eventoCommand), Times.Once);
            Assert.IsType <OkObjectResult>(result);
        }
コード例 #10
0
        public EventosControllerTests()
        {
            mockMapper           = new Mock <IMapper>();
            mockBus              = new Mock <IBus>();
            mockNotification     = new Mock <DomainNotificationHandler>();
            mockEventoAppService = new Mock <IEventoAppService>();

            var mockUser       = new Mock <IUser>();
            var mockRepository = new Mock <IEventoRepository>();

            eventoViewModel = new EventoViewModel();

            eventoCommand = new RegistrarEventoCommand("Teste", "", "", DateTime.Now, DateTime.Now.AddDays(1), true,
                                                       0, true, "Teste", Guid.NewGuid(), Guid.NewGuid(),
                                                       new IncluirEnderecoEventoCommand(Guid.NewGuid(), "", "", "", "", "", "", "", Guid.NewGuid()));

            eventosController = new EventosController(
                mockNotification.Object,
                mockUser.Object,
                mockBus.Object,
                mockEventoAppService.Object,
                mockRepository.Object,
                mockMapper.Object);
        }
コード例 #11
0
        public void Registrar(EventoViewModel eventoViewModel)
        {
            RegistrarEventoCommand registroCommand = _mapper.Map <RegistrarEventoCommand>(eventoViewModel);

            _bus.SendCommand(registroCommand);
        }