Example #1
0
        public async Task ThreeProjectsExist_Executed_ReturnThreeProjectViewModel()
        {
            //Arrange
            var projects = new List <Project>
            {
                new Project("Nome do Teste 1", "Descricao do Teste 1", 1, 1, 10000),
                new Project("Nome do Teste 2", "Descricao do Teste 2", 2, 2, 20000),
                new Project("Nome do Teste 3", "Descricao do Teste 3", 3, 3, 30000)
            };

            var projectRepositoryMock = new Mock <IProjectRepository>();

            projectRepositoryMock.Setup(pr => pr.GetAllAsync()).ReturnsAsync(projects);

            var getAllProjectsQuery        = new GetAllProjectsQuery("");
            var getAllProjectsQueryHandler = new GetAllProjectsQueryHandler(projectRepositoryMock.Object);

            //Act
            var projectViewModelList = await getAllProjectsQueryHandler.Handle(getAllProjectsQuery, new CancellationToken());

            //Assert
            Assert.NotNull(projectViewModelList);
            Assert.NotEmpty(projectViewModelList);
            Assert.Equal(projects.Count, projectViewModelList.Count);
            projectRepositoryMock.Verify(pr => pr.GetAllAsync(), Times.Once);
        }
Example #2
0
        public async Task ThreeProjectsExist_Executed_ReturnThreeProjectViewModels() //Aplicando o padrão PADRÃO GIVE WHEN THEN
        {
            //Padrão AAA
            //Arrange
            var projects = new List <Project>
            {
                new Project("Nome do projeto 1", "Descricao de teste", 1, 2, 10000),
                new Project("Nome do projeto 2", "Descricao de teste", 1, 2, 10000),
                new Project("Nome do projeto 3", "Descricao de teste", 1, 2, 10000),
            };

            var projectRepositoryMock = new Mock <IProjectRepository>();

            projectRepositoryMock.Setup(pr => pr.GetAllAsync().Result).Returns(projects);

            var getAllProjectsQuery        = new GetAllProjectsQuery("");
            var getAllProjectsQueryHandler = new GetAllProjectsQueryHandler(projectRepositoryMock.Object);

            //Act
            var projectViewModelList = await getAllProjectsQueryHandler.Handle(getAllProjectsQuery, new CancellationToken());

            //Assert
            Assert.NotNull(projectViewModelList);
            Assert.NotEmpty(projectViewModelList);
            Assert.Equal(projects.Count, projectViewModelList.Count);                //Verificar se foi retornada uma lista de 3 projetos no view model

            projectRepositoryMock.Verify(pr => pr.GetAllAsync().Result, Times.Once); //Verificar se o método GetAllAsync foi chamado uma vez
        }
Example #3
0
        public async Task Handle_GetAllQuery_ShouldReturnEntriesSuccessfully(List <ProjectDto> output)
        {
            // Arrange
            _mapperMock.Setup(m => m.Map <List <ProjectDto> >(It.IsAny <List <Project> >())).Returns(output); // AutoMapper setup

            var sut = new GetAllProjectsQueryHandler(_context, _mapperMock.Object);                           // creating system under test

            var temProject = _fixture.Create <Project>();

            // Act
            await ContextOperation.CreateEntity(_context, temProject);

            var result = await sut.Handle(new GetAllProjectsQuery(), CancellationToken.None);

            // Assert
            result.Count().ShouldBeGreaterThan(0);
        }