public void AddSkillCategory_Post_Test() { // Act var uow = new UnitOfWorkFakeFactory().Uow.Object; var paramUser = new AddSkillCategoryModel() { Texts = new List <TextModel>() { new TextModel() { Language = uow.LanguagesRepository.Get().ToList()[0], Value = "NewSkillCat.fr" }, new TextModel() { Language = uow.LanguagesRepository.Get().ToList()[1], Value = "NewSkillCat.en" } } }; var expected = paramUser.ToDto(uow.LanguagesRepository.Get().ToList()); expected.Id = uow.SkillCategoriesRepository.Get().Count() + 1; var nbGrades = uow.SkillCategoriesRepository.Get().ToList().Count; var result = new IntroductionController(uow).AddSkillCategory(paramUser) as RedirectToRouteResult; // Assert Assert.IsNotNull(result); Assert.AreEqual(result.RouteValues["Action"], nameof(IntroductionController.ShowSkills)); Assert.AreEqual(nbGrades + 1, uow.SkillCategoriesRepository.Get().Count()); AssertExtension.PropertyValuesAreEquals(expected, uow.SkillCategoriesRepository.Get().Last()); }
public ActionResult AddSkillCategory(AddSkillCategoryModel model) { if (ModelState.IsValid) { _uow.SkillCategoriesRepository.Insert(model.ToDto(_uow.LanguagesRepository.Get().ToList())); _uow.Save(); return(RedirectToAction(nameof(ShowSkills))); } return(RedirectToAction(nameof(AddSkillCategory))); }
public void Should_Transform_AddSkillCategoryModel_To_SkillCategory() { var expected = new SkillCategory() { Id = 1, DisplayPriority = 1, Texts = new List <Text>() { new Text() { Language = _languages[0], Value = "skc1" }, new Text() { Language = _languages[1], Value = "skc2" } }, Skills = new List <Skill>() { new Skill() { Id = 1, KnowledgePercent = 50, Texts = new List <Text>() { new Text() { Language = _languages[0], Value = "sk1" }, new Text() { Language = _languages[1], Value = "sk2" } } }, new Skill() { Id = 2, KnowledgePercent = 50, Texts = new List <Text>() { new Text() { Language = _languages[0], Value = "sk3" }, new Text() { Language = _languages[1], Value = "sk4" } } } } }; var act = new AddSkillCategoryModel() { DisplayPriority = 1, Texts = new List <TextModel>() { new TextModel() { Language = _languages[0], Value = "skc1" }, new TextModel() { Language = _languages[1], Value = "skc2" } } }; Assert.AreEqual(expected.DisplayPriority, act.ToDto(_languages).DisplayPriority); AssertExtension.CompareIEnumerable(expected.Texts, act.ToDto(_languages).Texts, (x, y) => x.Language == y.Language && x.Value == y.Value); }