public async Task ListTargetsTest() { var targets = new List <AvailableTarget> { new AvailableTarget { Name = "Target1" }, new AvailableTarget { Name = "Target2" } }; var progressReporter = Substitute.For <IProgressReporter>(); var targetMapper = Substitute.For <ITargetMapper>(); var dependencyFinder = Substitute.For <IDependencyFinder>(); var reportGenerator = Substitute.For <IReportGenerator>(); var ignoreAssemblyInfoList = Substitute.For <IEnumerable <IgnoreAssemblyInfo> >(); var apiPortService = Substitute.For <IApiPortService>(); apiPortService.GetTargetsAsync().Returns(CreateResponse <IEnumerable <AvailableTarget> >(targets.AsReadOnly())); var client = new ApiPortClient(apiPortService, progressReporter, targetMapper, dependencyFinder, reportGenerator, ignoreAssemblyInfoList); var actualTargets = await client.ListTargets(); Assert.Equal <AvailableTarget[]>(actualTargets.OrderBy(k => k.Name).ToArray(), targets.OrderBy(k => k.Name).ToArray()); }
private static async Task ListTargets(ApiPortClient apiPortClient, ITargetMapper targetMapper) { const string SelectedMarker = "*"; var targets = await apiPortClient.ListTargets(); if (targets.Any()) { Console.WriteLine(); Console.WriteLine(LocalizedStrings.AvailableTargets); var expandableTargets = targets.Where(target => target.ExpandedTargets.Any()); var groupedTargets = targets.Where(target => !target.ExpandedTargets.Any()).GroupBy(target => target.Name); foreach (var item in groupedTargets) { Console.WriteLine(LocalizedStrings.TargetsList, item.Key, String.Join(LocalizedStrings.VersionListJoin, item.Select(v => v.Version.ToString() + (v.IsSet ? SelectedMarker : String.Empty)))); } if (expandableTargets.Any()) { Console.WriteLine(); Console.WriteLine(Microsoft.Fx.Portability.Resources.LocalizedStrings.AvailableGroupedTargets); foreach (var item in expandableTargets) { Console.WriteLine(LocalizedStrings.TargetsListGrouped, item.Name, String.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " ", item.ExpandedTargets)); } } } if (targetMapper.Aliases.Any()) { Console.WriteLine(); Console.WriteLine(LocalizedStrings.AvailableAliases); foreach (var alias in targetMapper.Aliases) { Console.WriteLine(LocalizedStrings.TargetsListNoVersion, alias); } } Console.WriteLine(); Console.WriteLine(LocalizedStrings.NotesOnUsage); Console.WriteLine(LocalizedStrings.TargetsListNoVersion, Microsoft.Fx.Portability.Resources.LocalizedStrings.HowToSpecifyVersion); Console.WriteLine(); Console.WriteLine(LocalizedStrings.TargetsListNoVersion, LocalizedStrings.WhatAsteriskMeans); }