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);
        }
Пример #2
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);
        }