예제 #1
0
        public async Task TwoSkillsExist_Executed_ReturnTwoSkillsDTO()
        {
            //Arrange
            var skills = new List <SkillDTO>
            {
                new SkillDTO(1, "Descrição de teste 1"),
                new SkillDTO(2, "Descrição de teste 2")
            };

            var skillsRepositoryMock = new Mock <ISkillRepository>();

            skillsRepositoryMock.Setup(s => s.GetAllAsync().Result).Returns(skills);

            var getAllSkillsQuery        = new GetAllSkillsQuery("");
            var getAllSkillsQueryHandler = new GetAllSkillsQueryHandler(skillsRepositoryMock.Object);

            //Act
            var skillDTOList = await getAllSkillsQueryHandler.Handle(getAllSkillsQuery, new CancellationToken());

            //Assert
            Assert.NotNull(skillDTOList);
            Assert.NotEmpty(skillDTOList);
            Assert.Equal(skills.Count, skillDTOList.Count);

            skillsRepositoryMock.Verify(s => s.GetAllAsync().Result, Times.Once);
        }
예제 #2
0
        public async Task ExistThreeSkills_Executed_ThreeSkillViewModel() //padrão nomenclatura given_when_then
        {
            //Arrange
            var skills = new List <Skill>
            {
                new Skill(".Net"),
                new Skill("Angular"),
                new Skill("Sql Server")
            };

            var skillRepository = new Mock <ISkillRepository>();

            skillRepository.Setup(sr => sr.GetAll()).Returns(Task.FromResult(skills));
            var getAllSkillsQuery        = new GetAllSkillsQuery();
            var getAllSkillsQueryHandler = new GetAllSkillsQueryHandler(skillRepository.Object);

            //Act
            var skillsViewModel = await getAllSkillsQueryHandler.Handle(getAllSkillsQuery, new CancellationToken());

            //Assert
            Assert.NotNull(skillsViewModel);
            Assert.Equal(skills.Count, skillsViewModel.Count);

            foreach (var skill in skills)
            {
                var skillViewModel = skillsViewModel.SingleOrDefault(s => s.Description == skill.Description);
                Assert.NotNull(skillViewModel);
            }

            skillRepository.Verify(sr => sr.GetAll(), Times.Once);
        }
        public async Task ExistThreeSkills_Executed_ThreeSkillsViewModel()
        {
            //Arrange
            var skills = new List <Skill>
            {
                new Skill(".NET"),
                new Skill("Angular"),
                new Skill("SQL Server")
            };

            var skillsRepository = new Mock <ISkillRepository>();

            skillsRepository.Setup(sr => sr.GetAllSkillsAsync()).Returns(Task.FromResult(skills)); //Mockando os dados da entidade para as classes do CRQS e validá-los posteriormente

            var getAllSkillsQuery        = new GetAllSkillsQuery();
            var getAllSkillsQueryHandler = new GetAllSkillsQueryHandler(skillsRepository.Object);

            //Act
            var skillsViewModel = await getAllSkillsQueryHandler.Handle(getAllSkillsQuery, new CancellationToken());

            //Assert
            Assert.NotNull(skillsViewModel);
            Assert.Equal(skills.Count, skillsViewModel.Count);

            foreach (var item in skills)
            {
                var skillViewModel = skillsViewModel.FirstOrDefault(s => s.Description == item.Description);

                Assert.NotNull(skillViewModel);
            }

            skillsRepository.Verify(sr => sr.GetAllSkillsAsync(), Times.Once);
        }