public ActionResult ShowSkills() { var skills = new SkillCategoriesModel { Categories = _uow.SkillCategoriesRepository.Get().ToList(), ChartDatas = new ChartPie() }; Func <SkillCategory, Color> getColorFromPalette = sk => skills.Palette[skills.Categories.ToList().IndexOf(sk)]; while (skills.Palette.Count < skills.Categories.Count) { skills.Palette.Add(skills.Palette.Last().GetNextColor()); } skills.ChartDatas.Slices = new List <ChartPieSlice>(); skills.ChartDatas.Slices = skills.Categories.OrderByDescending(sc => sc.Skills.Count).Select(x => new ChartPieSlice() { Label = x.Texts.GetText(CultureInfo.CurrentUICulture), Color = getColorFromPalette(x).GetHexValue(), Value = skills.Categories.Count > 0 ? x.Skills.Count : 1, ToolTip = x.Texts.GetText(CultureInfo.CurrentUICulture), Slices = new List <ChartPieSlice>(x.Skills.OrderByDescending(s => Math.Sin(s.Texts.GetText(CultureInfo.CurrentUICulture).Length)).Select(y => new ChartPieSlice() { Label = y.Texts.GetText(CultureInfo.CurrentUICulture), Color = getColorFromPalette(x).GetHexValue(), Value = y.KnowledgePercent, ToolTip = y.Texts.GetText(CultureInfo.CurrentUICulture) + " " + Utilities.GetGlyphiconStarsFromPercents(y.KnowledgePercent, 5) })) }); return(View(skills)); }
public void ShowSkills_Test() { var uow = new UnitOfWorkFakeFactory().Uow.Object; var expected = new SkillCategoriesModel() { Categories = uow.SkillCategoriesRepository.Get().ToList(), ChartDatas = new ChartPie() { Infos = new CharPieInfo(), Slices = new List <ChartPieSlice>() { new ChartPieSlice() { Label = uow.SkillCategoriesRepository.Find(1).Texts.GetText(CultureInfo.CurrentUICulture), Color = "#4285f4", Value = 2, ToolTip = uow.SkillCategoriesRepository.Find(1).Texts.GetText(CultureInfo.CurrentUICulture), Slices = new List <ChartPieSlice>() { new ChartPieSlice() { Label = uow.SkillsRepository.Find(1).Texts.GetText(CultureInfo.CurrentUICulture), Color = "#4285f4", Value = uow.SkillsRepository.Find(1).KnowledgePercent, ToolTip = uow.SkillsRepository.Find(1).Texts.GetText(CultureInfo.CurrentUICulture) + " " + Utilities.GetGlyphiconStarsFromPercents( uow.SkillsRepository.Find(1).KnowledgePercent, 5) }, new ChartPieSlice() { Label = uow.SkillsRepository.Find(2).Texts.GetText(CultureInfo.CurrentUICulture), Color = "#4285f4", Value = uow.SkillsRepository.Find(2).KnowledgePercent, ToolTip = uow.SkillsRepository.Find(2).Texts.GetText(CultureInfo.CurrentUICulture) + " " + Utilities.GetGlyphiconStarsFromPercents( uow.SkillsRepository.Find(2).KnowledgePercent, 5) }, } }, new ChartPieSlice() { Label = uow.SkillCategoriesRepository.Find(2).Texts.GetText(CultureInfo.CurrentUICulture), Color = "#34a853", Value = 2, ToolTip = uow.SkillCategoriesRepository.Find(2).Texts.GetText(CultureInfo.CurrentUICulture), Slices = new List <ChartPieSlice>() { new ChartPieSlice() { Label = uow.SkillsRepository.Find(3).Texts.GetText(CultureInfo.CurrentUICulture), Color = "#34a853", Value = uow.SkillsRepository.Find(3).KnowledgePercent, ToolTip = uow.SkillsRepository.Find(3).Texts.GetText(CultureInfo.CurrentUICulture) + " " + Utilities.GetGlyphiconStarsFromPercents( uow.SkillsRepository.Find(3).KnowledgePercent, 5) }, new ChartPieSlice() { Label = uow.SkillsRepository.Find(4).Texts.GetText(CultureInfo.CurrentUICulture), Color = "#34a853", Value = uow.SkillsRepository.Find(4).KnowledgePercent, ToolTip = uow.SkillsRepository.Find(4).Texts.GetText(CultureInfo.CurrentUICulture) + " " + Utilities.GetGlyphiconStarsFromPercents( uow.SkillsRepository.Find(4).KnowledgePercent, 5) }, } } } } }; var controller = new IntroductionController(uow); var result = controller.ShowSkills() as ViewResult; // Assert Assert.IsNotNull(result); Assert.AreEqual(expected.ChartDatas.ToJson(), ((SkillCategoriesModel)result.Model).ChartDatas.ToJson()); }