/// <summary> /// Initializes a new instance of the <see cref="Group"/> class /// </summary> /// <param name="ci">A <see cref="GroupCI"/> used to create new instance</param> /// <param name="cultures">A culture of the current instance of <see cref="GroupDTO"/></param> /// <param name="sportEntityFactory">A <see cref="ISportEntityFactory"/> used to retrieve <see cref="IPlayerProfile"/></param> /// <param name="competitorsReferenceIds">A list of <see cref="ReferenceIdCI"/> for all competitors</param> public Group(GroupCI ci, IEnumerable <CultureInfo> cultures, ISportEntityFactory sportEntityFactory, IDictionary <URN, ReferenceIdCI> competitorsReferenceIds) { Guard.Argument(ci, nameof(ci)).NotNull(); Id = ci.Id; Name = ci.Name; if (ci.Competitors != null) { //var competitors = new List<ICompetitor>(); //var cultureInfos = cultures.ToList(); //foreach (CompetitorCI competitorCI in ci.Competitors) //{ // if (competitorCI == null) // { // var x = "2"; // } // var comp = new Competitor(competitorCI, cultureInfos, sportEntityFactory, competitorsReferenceIds); // competitors.Add(comp); //} //_competitors = competitors; _competitors = ci.Competitors.Select(t => sportEntityFactory.BuildCompetitor(t, cultures, competitorsReferenceIds)).ToList(); } }
public static GroupDTO FindExistingGroup(List <GroupDTO> dtoGroups, GroupCI ciGroup) { // find by id var resultGroup = !string.IsNullOrEmpty(ciGroup.Id) ? dtoGroups.FirstOrDefault(c => c.Id.Equals(ciGroup.Id)) : null; // find by name if (resultGroup == null) { resultGroup = !string.IsNullOrEmpty(ciGroup.Name) ? dtoGroups.FirstOrDefault(c => c.Name.Equals(ciGroup.Name)) : null; } // find by competitors, only for when group id and name not defined if (resultGroup == null && string.IsNullOrEmpty(ciGroup.Id) && string.IsNullOrEmpty(ciGroup.Name)) { foreach (var existingGroup in dtoGroups) { if (string.IsNullOrEmpty(existingGroup.Id) && string.IsNullOrEmpty(existingGroup.Name)) { if (existingGroup.Competitors?.Count() != ciGroup.CompetitorsIds.Count()) { continue; } // if all competitors match in the group if (ciGroup.CompetitorsIds.All(cId => existingGroup.Competitors.Count(c => cId.Equals(c.Id)) == 1)) { return(existingGroup); } } } } return(resultGroup); }
private void VerifyTournamentGroups(IEnumerable <tournamentGroup> apiGroups, IEnumerable <GroupCI> ciTourGroups) { var sapiGroups = apiGroups?.ToList(); var ciGroups = ciTourGroups?.ToList(); if (sapiGroups.IsNullOrEmpty()) { Assert.IsTrue(ciGroups.IsNullOrEmpty()); return; } Assert.AreEqual(sapiGroups.Count, ciGroups.Count); foreach (var sapiGroup in sapiGroups) { if (!string.IsNullOrEmpty(sapiGroup.id)) { Assert.IsTrue(ciGroups.Exists(a => a.Id.Equals(sapiGroup.id))); } if (!string.IsNullOrEmpty(sapiGroup.name)) { Assert.IsTrue(ciGroups.Exists(a => a.Name.Equals(sapiGroup.name))); } GroupCI matchingGroup = MergerHelper.FindExistingGroup(ciGroups, new GroupDTO(sapiGroup)); Assert.AreEqual(sapiGroup.competitor.Length, matchingGroup.CompetitorsIds.Count()); foreach (var sapiTeam in sapiGroup.competitor) { Assert.IsTrue(matchingGroup.CompetitorsIds.Contains(URN.Parse(sapiTeam.id))); } } }
/// <summary> /// Initializes a new instance of the <see cref="Group"/> class /// </summary> /// <param name="ci">A <see cref="GroupCI"/> used to create new instance</param> /// <param name="cultures">A culture of the current instance of <see cref="GroupDTO"/></param> /// <param name="sportEntityFactory">A <see cref="ISportEntityFactory"/> used to retrieve <see cref="IPlayerProfile"/></param> /// <param name="exceptionStrategy">The exception strategy</param> /// <param name="competitorsReferenceIds">A list of <see cref="ReferenceIdCI"/> for all competitors</param> public Group(GroupCI ci, IEnumerable <CultureInfo> cultures, ISportEntityFactory sportEntityFactory, ExceptionHandlingStrategy exceptionStrategy, IDictionary <URN, ReferenceIdCI> competitorsReferenceIds) { Guard.Argument(ci, nameof(ci)).NotNull(); Id = ci.Id; Name = ci.Name; if (ci.CompetitorsIds != null) { _competitors = ci.CompetitorsIds.Select(t => sportEntityFactory.BuildCompetitor(t, cultures, competitorsReferenceIds, exceptionStrategy)).ToList(); } }
public void GroupTest() { var teamType1En = new team { abbreviation = "ABC", country = "Germany", id = "sr:team:1", name = "Team A", @virtual = true, virtualSpecified = true }; var teamType1De = new team { abbreviation = "ABC", country = "Deutschland", id = "sr:team:1", name = "Team A", @virtual = true, virtualSpecified = true }; var teamType2En = new team { abbreviation = "ABC", country = "Germany", id = "sr:team:2", name = "Team B", @virtual = true, virtualSpecified = true }; var teamType2De = new team { abbreviation = "ABC", country = "Deutschland", id = "sr:team:2", name = "Team B", @virtual = true, virtualSpecified = true }; var groupType1 = new tournamentGroup { name = "Group A", competitor = new[] { teamType1En, teamType2En } }; var groupType2 = new tournamentGroup { name = "Group A", competitor = new[] { teamType1De, teamType2De } }; var groupDTO1 = new GroupDTO(groupType1); var groupDTO2 = new GroupDTO(groupType2); var groupCI = new GroupCI(groupDTO1, _cultureFirst); groupCI.Merge(groupDTO2, _cultureSecond); Assert.IsNotNull(groupCI); Assert.AreEqual(groupType1.name, groupCI.Name); Assert.AreEqual(groupType1.competitor.Length, groupCI.CompetitorsIds.Count()); Assert.AreEqual(groupType1.competitor[0].id, groupCI.CompetitorsIds.ToList()[0].ToString()); Assert.AreEqual(groupType1.competitor[1].id, groupCI.CompetitorsIds.ToList()[1].ToString()); Assert.AreNotEqual(groupCI.CompetitorsIds.ToList()[0].Id, groupCI.CompetitorsIds.ToList()[1]); }