コード例 #1
0
        public async Task ProjectWithIdExists_Executed_ReturnProjecViewModel()
        {
            //Arrange
            var project    = new Project("Nome do projeto", "descrição de teste", 1, 2, 10000);
            var client     = new User("User 1", "*****@*****.**", Convert.ToDateTime("15/12/1993"), "@123456", "client");
            var freelancer = new User("User 2", "*****@*****.**", Convert.ToDateTime("06/03/1998"), "@654321", "freelancer");

            project.SetUserClient(client);
            project.SetUserFreelancer(freelancer);

            var projectRepositoryMock = new Mock <IProjectRepository>();

            var getProjectByIdQuery        = new GetProjectByIdQuery(2); //Passando o id 2 para obter um objeto específico
            var getProjectByIdQueryHandler = new GetProjectByIdQueryHandler(projectRepositoryMock.Object);

            projectRepositoryMock.Setup(p => p.GetByIdAsync(getProjectByIdQuery.Id).Result).Returns(project);

            //Act
            var projectDetailsViewModel = await getProjectByIdQueryHandler.Handle(getProjectByIdQuery, new CancellationToken());

            //Assert
            Assert.NotNull(projectDetailsViewModel);

            projectRepositoryMock.Verify(pr => pr.GetByIdAsync(It.IsAny <int>()), Times.Once);
        }
コード例 #2
0
        public async Task ThreeProjectsExist_Executed_ReturnThreeProjectByIdViewModels()
        {
            // CRIAR UM PROJETO
            // Arrange
            var project = new Project("Nome de Teste", "Descricao de Teste", 1, 2, 10000, DateTime.Parse("2022-04-08"));

            var projectRepositoryMock = new Mock <IProjectRepository>();

            projectRepositoryMock.Setup(pr => pr.GetByIdAsync(project.Id).Result).Returns(project);

            var getProjectByIdQuery        = new GetProjectByIdQuery(project.Id);
            var getProjectByIdQueryHandler = new GetProjectByIdQueryHandler(projectRepositoryMock.Object);

            // Act
            var projectViewModel = await getProjectByIdQueryHandler.Handle(getProjectByIdQuery, new CancellationToken());

            //Assert
            Assert.NotNull(projectViewModel);

            projectRepositoryMock.Verify(pr => pr.GetByIdAsync(project.Id).Result, Times.Once);
        }