コード例 #1
0
        public void SetUp()
        {
            var listSkills = new Skill[]
            {
                new Skill()
                {
                    Id = 1, Name = "Nokia Lumia 630"
                },
                new Skill()
                {
                    Id = 2, Name = "Programming languages"
                },
                new Skill()
                {
                    Id = 3, Name = "Databases"
                }
            };

            Mock <IRepository <Skill> > skillRepositoy = new Mock <IRepository <Skill> >();

            skillRepositoy.Setup(m => m.GetAll()).Returns(listSkills.AsQueryable());
            skillRepositoy.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(
                (int id) => { return(skillRepositoy.Object.GetAll().FirstOrDefault(x => x.Id == id)); });


            Mock <IRepository <SubSkill> > subSkillRepositoy = new Mock <IRepository <SubSkill> >();
            var listSubSkills = new List <SubSkill>();
            var skill1        = skillRepositoy.Object.GetAll().FirstOrDefault(x => x.Name == "Programming languages");
            int subskillId    = 1;

            if (skill1 != null)
            {
                listSubSkills.Add(new SubSkill()
                {
                    SkillId = skill1.Id,
                    Name    = "C/C++",
                    Id      = subskillId++
                });
                listSubSkills.Add(new SubSkill()
                {
                    SkillId = skill1.Id,
                    Name    = "JavaScript / HTML / CSS"
                });
                listSubSkills.Add(new SubSkill()
                {
                    SkillId = skill1.Id,
                    Name    = "Delphi",
                    Id      = subskillId++
                });
            }
            var skill2 = skillRepositoy.Object.GetAll().FirstOrDefault(x => x.Name == "Databases");

            if (skill2 != null)
            {
                listSubSkills.Add(new SubSkill()
                {
                    SkillId = skill2.Id,
                    Name    = "Microsoft SQL Server",
                    Id      = subskillId++
                });
                listSubSkills.Add(new SubSkill()
                {
                    SkillId = skill2.Id,
                    Name    = "Oracle",
                    Id      = subskillId++
                });
            }


            subSkillRepositoy.Setup(m => m.GetAll()).Returns(listSubSkills.AsQueryable());
            subSkillRepositoy.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(
                (int id) => { return(subSkillRepositoy.Object.GetAll().FirstOrDefault(x => x.Id == id)); });

            var unitOfWork = new Mock <IUnitOfWork <SubSkill, Skill, Level, KnowledgeManagement.DAL.SpecifyingSkill.Entities.SpecifyingSkill> >();

            unitOfWork.Setup(x => x.Skills).Returns(skillRepositoy.Object);
            unitOfWork.Setup(x => x.SubSkills).Returns(subSkillRepositoy.Object);
            _skillService    = new SkillService(unitOfWork.Object, new MapperFactory());
            _subSkillService = new SubSkillService(unitOfWork.Object, new MapperFactory());
        }
コード例 #2
0
 public ManagerSkillController(ISubSkillService <SubSkillDTO> subSkillService, ISkillService <SkillDTO> skillService, IMapperFactoryWEB mapperFactory)
 {
     _subSkillService = subSkillService;
     _skillService    = skillService;
     _mapper          = mapperFactory.CreateMapperWEB();
 }