public void PlayerAwardMappingSucceeds() { var uri = new Uri("https://rprcorporate.blob.core.windows.net/media/sampletrophy.png?sp=rl&st=2021-03-28T19:06:34Z&se=2025-03-29T19:06:00Z&sv=2020-02-10&sr=b&sig=M3oKCysFeKGWw7jDnn1kCFNTFHdqxoOtKVzVFIYXXZs%3D"); var a = new PlayerAward().ToMock(uri); var ad = new PlayerAwardDisplay().Map(a); Assert.IsTrue(a.Value == ad.Value); }
public static PlayerAwardDisplay Map(this PlayerAwardDisplay to, PlayerAward from) { var config = new MapperConfiguration(cfg => { cfg.AddProfile <PlayerAwardProfile>(); }); IMapper mapper = new Mapper(config); mapper.Map(from, to); return(to); }
public static PlayerAward ToMock(this PlayerAward pad, Uri uri) { string rawText = Lipsums.LoremIpsum; LipsumGenerator lipsum = new LipsumGenerator(rawText, false); return(new PlayerAward() { Description = $"{lipsum.GenerateWords(1)[0]}", Value = 400, ActionRefId = Guid.NewGuid(), AchievementRefId = Guid.NewGuid(), CoinRefId = Guid.NewGuid(), GoalRefId = Guid.NewGuid(), OccurredOn = DateTimeOffset.UtcNow }); }
public PlayerAchievement(Dictionary<string,object> data) { foreach(string x in data.Keys) { if (x == "player") { player = new PlayerAward ((Dictionary<string,object>)data["player"]); continue; } if( x == "friends") { var frarr = (List<object>)data [x]; var fawards = new List<PlayerAward> (); fawards.AddRange(from object t in frarr select new PlayerAward((Dictionary<string,object>) t)); friends = fawards; continue; } this[x] = data[x]; } }
public PlayerAchievement(Dictionary <string, object> data) { foreach (string x in data.Keys) { if (x == "player") { player = new PlayerAward((Dictionary <string, object>)data["player"]); continue; } if (x == "friends") { var frarr = (List <object>)data [x]; var fawards = new List <PlayerAward> (); fawards.AddRange(from object t in frarr select new PlayerAward((Dictionary <string, object>)t)); friends = fawards; continue; } this[x] = data[x]; } }
public static PlayerDetails Parse(string url) { Dictionary <string, string> tokens = Tokenize(url); if (tokens.Count > 0) { PlayerDetails player = new PlayerDetails(); foreach (string key in tokens.Keys) { string value = tokens[key]; switch (key) { case "Full name:": player.FullName = value; break; case "Known As": player.KnownAs = value; break; case "Born:": player.Born = value; break; case "Died:": player.Died = value; break; case "Batting:": player.Batting = value; break; case "Bowling:": player.Bowling = value; break; case "Occasional wicket-keeper": case "Wicket-keeper": player.WicketKeeper = true; break; case "Somerset cap:": player.SomersetCap = int.Parse(value); break; case "Somerset benefit season:": if (value.EndsWith(" (Testimonial)")) { value = value.Substring(0, value.Length - 14).Trim(); } player.Benefit = int.Parse(value); break; case "Relations:": case "Teams:": case "Biography:": case "Christened:": case "Buried:": case "Articles:": case "Pictures:": case "Education:": case "Other Sports:": case "External link:": case "Clubs:": case "Disability:": case "Other Relations:": case "Galleries:": case "Audio-Video:": break; default: if (Regex.IsMatch(value, @"^\d{4}(?:/\d{2})?$")) { PlayerAward award = new PlayerAward { Award = key, Season = value }; if (player.Awards == null) { player.Awards = new List <PlayerAward>(); } player.Awards.Add(award); } else if (value.Contains(',')) { // Could be a multi-year award string[] seasons = Regex.Split(value, @"\s*,\s*"); foreach (string season in seasons) { if (!Regex.IsMatch(value, @"\d{4}(?:/\d{2})?")) { Log.WarnFormat("Player {0} has previously unseen token '{1}'", player.FullName, key); break; } PlayerAward award = new PlayerAward { Award = key, Season = season }; if (player.Awards == null) { player.Awards = new List <PlayerAward>(); } player.Awards.Add(award); } } else { Log.WarnFormat("Player {0} has previously unseen token '{1}'", player.FullName, key); } break; } } return(player); } return(null); }