///<summary> Faction data from EliteBGS (allows search by faction name - EDSM can only search by system name). /// If a systemName is provided, we can filter factions that share a name according to whether they have a presence in a known system </summary> public Faction GetFactionByName(string factionName, string systemName = null) { if (string.IsNullOrEmpty(factionName)) { return(null); } List <KeyValuePair <string, object> > queryList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>(BgsService.FactionParameters.factionName, factionName) }; List <Faction> factions = BgsService.GetFactions(BgsService.factionEndpoint, queryList); // If a systemName is provided, we can filter factions that share a name according to whether they have a presence in a known system if (systemName != null && factions.Count > 1) { foreach (Faction faction in factions) { faction.presences = faction.presences.Where(f => f.systemName == systemName)?.ToList(); } } return(factions?.FirstOrDefault() ?? new Faction() { name = factionName }); }
public void TestParseNoFactions() { // Setup string endpoint = "v4/factions?"; string json = ""; RestRequest data = new RestRequest(); fakeBgsRestClient.Expect(endpoint, json, data); var queryList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>(BgsService.FactionParameters.factionName, "") }; // Act List <Faction> factions = fakeBgsService.GetFactions(endpoint, queryList); // Assert Assert.IsNull(factions); }