public void AddSkill(AddSkillModel model) { userSkillRepo.Add(new UserSkill { CategoryId = model.CategoryId, UserId = model.UserId }); }
public ActionResult AddSkill(AddSkillModel model) { if (ModelState.IsValid) { _uow.SkillsRepository.Insert(model.ToDto(_uow.SkillCategoriesRepository.Get().ToList(), _uow.LanguagesRepository.Get().ToList())); _uow.Save(); return(RedirectToAction(nameof(ShowSkills))); } return(RedirectToAction(nameof(AddSkill))); }
public static Skill ToDto(this AddSkillModel model, List <SkillCategory> skillCategories, List <Language> languages) { var dto = new Skill { Category = skillCategories.First(x => x.Id == model.CategoryId), KnowledgePercent = model.KnowledgePercent, Texts = model.Texts.ToDto(languages), }; return(dto); }
public ActionResult AddSkill(int skillCategoryId) { var model = new AddSkillModel { Texts = _uow.LanguagesRepository.Get().Select(language => new TextModel() { Language = language }).ToList(), CategoryId = skillCategoryId }; return(View(model)); }
public void Should_Transform_AddSkillModel_To_Skill() { var skillCategories = new List <SkillCategory>() { NewSkillCategory(1), NewSkillCategory(2) }; var expected = new Skill() { Id = 1, KnowledgePercent = 50, Category = skillCategories[0], Texts = new List <Text>() { new Text() { Language = _languages[0], Value = "sk1.fr" }, new Text() { Language = _languages[1], Value = "sk1.en" } } }; var act = new AddSkillModel() { CategoryId = 1, KnowledgePercent = 50, Texts = new List <TextModel>() { new TextModel() { Language = _languages[0], Value = "sk1.fr" }, new TextModel() { Language = _languages[1], Value = "sk1.en" } } }; var result = act.ToDto(skillCategories, _languages); Assert.AreEqual(expected.KnowledgePercent, result.KnowledgePercent); Assert.AreEqual(expected.Category, result.Category); AssertExtension.CompareIEnumerable(expected.Texts, result.Texts, (x, y) => x.Language == y.Language && x.Value == y.Value); }
public void AddSkill_Get_Test() { // Act var uow = new UnitOfWorkFakeFactory().Uow.Object; var controller = new IntroductionController(uow); const int skillCategoryId = 1; var expected = new AddSkillModel { Texts = uow.LanguagesRepository.Get().Select(language => new TextModel() { Language = language }).ToList(), CategoryId = skillCategoryId }; var result = controller.AddSkill(skillCategoryId) as ViewResult; // Assert Assert.IsNotNull(result); AssertExtension.PropertyValuesAreEquals(expected, result.Model); }
public void Should_Transform_Skill_To_AddSkillModel() { var expected = new AddSkillModel() { KnowledgePercent = 50, Texts = new List <TextModel>() { new TextModel() { Language = _languages[0], Value = "sk1.fr" }, new TextModel() { Language = _languages[1], Value = "sk1.en" } } }; var act = new Skill() { KnowledgePercent = 50, Texts = new List <Text>() { new Text() { Language = _languages[0], Value = "sk1.fr" }, new Text() { Language = _languages[1], Value = "sk1.en" } } }; var result = act.ToDto(); Assert.AreEqual(expected.KnowledgePercent, result.KnowledgePercent); AssertExtension.CompareIEnumerable(expected.Texts, result.Texts, (x, y) => x.Language == y.Language && x.Value == y.Value); }
public void AddSkill_Post_Test() { // Act var uow = new UnitOfWorkFakeFactory().Uow.Object; const int skillCategorieId = 1; var paramUser = new AddSkillModel() { KnowledgePercent = 50, CategoryId = skillCategorieId, Texts = new List <TextModel>() { new TextModel() { Language = uow.LanguagesRepository.Get().ToList()[0], Value = "NewSkill.fr" }, new TextModel() { Language = uow.LanguagesRepository.Get().ToList()[1], Value = "NewSkill.en" } } }; var expected = paramUser.ToDto(uow.SkillCategoriesRepository.Get().ToList(), uow.LanguagesRepository.Get().ToList()); expected.Id = uow.SkillsRepository.Get().Count() + 1; var nbSkills = uow.SkillsRepository.Get().ToList().Count; var result = new IntroductionController(uow).AddSkill(paramUser) as RedirectToRouteResult; // Assert Assert.IsNotNull(result); Assert.AreEqual(result.RouteValues["Action"], nameof(IntroductionController.ShowSkills)); Assert.AreEqual(nbSkills + 1, uow.SkillsRepository.Get().Count()); AssertExtension.PropertyValuesAreEquals(expected, uow.SkillsRepository.Get().Last()); }