public void PlayerProfileMergeNoDataTest() { _defaultPlayer.nationality = null; _defaultPlayer.nickname = null; _defaultPlayer.weightSpecified = false; _defaultPlayer.jersey_numberSpecified = false; _defaultPlayer.country_code = null; var playerProfileDTO = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); Assert.IsNotNull(playerProfileDTO); var playerProfileCI = new PlayerProfileCI(playerProfileDTO, _competitorId, _cultureFirst, new TestDataRouterManager(new CacheManager())); Assert.IsNotNull(playerProfileCI); Compare(playerProfileCI, _defaultPlayer, _cultureFirst); _defaultPlayer.name = "John Second Name"; _defaultPlayer.nationality = "uk 2"; var playerProfileDTO2 = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); Assert.IsNotNull(playerProfileDTO2); playerProfileCI.Merge(playerProfileDTO2, _competitorId, _cultureSecond); Compare(playerProfileCI, _defaultPlayer, _cultureSecond); }
/// <summary> /// Merges the specified <see cref="PlayerProfileDTO"/> into instance /// </summary> /// <param name="profile">The <see cref="PlayerProfileDTO"/> used to merge into instance</param> /// <param name="competitorId">The competitor id this player belongs to</param> /// <param name="culture">The culture of the <see cref="PlayerProfileDTO"/> used to merge</param> internal void Merge(PlayerProfileDTO profile, URN competitorId, CultureInfo culture) { Guard.Argument(profile, nameof(profile)).NotNull(); Guard.Argument(culture, nameof(culture)).NotNull(); _type = profile.Type; _dateOfBirth = profile.DateOfBirth; Names[culture] = profile.Name; _nationalities[culture] = profile.Nationality; _height = profile.Height; _weight = profile.Weight; _gender = profile.Gender; CountryCode = profile.CountryCode; FullName = profile.FullName; Nickname = profile.Nickname; if (string.IsNullOrEmpty(_abbreviation)) { _abbreviation = SdkInfo.GetAbbreviationFromName(profile.Name); } if (competitorId != null) { _competitorId = competitorId; } ((List <CultureInfo>)_fetchedCultures).Add(culture); }
private async Task AddPlayerProfileAsync(PlayerProfileDTO item, URN competitorId, CultureInfo culture, bool useSemaphore) { if (item == null) { return; } if (_cache.Contains(item.Id.ToString())) { try { var ci = (PlayerProfileCI)_cache.Get(item.Id.ToString()); if (useSemaphore) { await WaitTillIdIsAvailableAsync(_mergeUrns, item.Id).ConfigureAwait(false); } ci?.Merge(item, competitorId, culture); } catch (Exception ex) { ExecutionLog.LogError(ex, $"Error adding player profile for id={item.Id}, dto type={item.GetType().Name} and lang={culture.TwoLetterISOLanguageName}."); } finally { if (useSemaphore && !_isDisposed) { await ReleaseIdAsync(_mergeUrns, item.Id).ConfigureAwait(false); } } } else { _cache.Add(item.Id.ToString(), new PlayerProfileCI(item, competitorId, culture, _dataRouterManager), GetCorrectCacheItemPolicy(item.Id)); } }
public void PlayerProfileDTOTest() { var msg = RMF.GetPlayerExtended(); var dto = new PlayerProfileDTO(msg, null); ValidatePlayerExtended(msg, dto); }
private void AddPlayerProfile(PlayerProfileDTO item, URN competitorId, CultureInfo culture, bool useSemaphore) { if (item == null) { return; } if (_cache.Contains(item.Id.ToString())) { try { var ci = (PlayerProfileCI)_cache.Get(item.Id.ToString()); if (useSemaphore) { _semaphoreCacheMerge.Wait(); } ci?.Merge(item, competitorId, culture); } catch (Exception ex) { ExecutionLog.LogError($"Error adding player profile for id={item.Id}, dto type={item.GetType().Name} and lang={culture.TwoLetterISOLanguageName}.", ex); } finally { if (useSemaphore && !_isDisposed) { _semaphoreCacheMerge.Release(); } } } else { _cache.Add(item.Id.ToString(), new PlayerProfileCI(item, competitorId, culture, _dataRouterManager), GetCorrectCacheItemPolicy(item.Id)); } }
public void PlayerProfileMergeTest() { var playerProfileDTO = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); Assert.IsNotNull(playerProfileDTO); var playerProfileCI = new PlayerProfileCI(playerProfileDTO, _competitorId, _cultureFirst, new TestDataRouterManager(new CacheManager())); Assert.IsNotNull(playerProfileCI); Compare(playerProfileCI, _defaultPlayer, _cultureFirst); _defaultPlayer.name = "John SecondName"; _defaultPlayer.nationality = "uk 2"; var playerProfileDTO2 = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); Assert.IsNotNull(playerProfileDTO2); playerProfileCI.Merge(playerProfileDTO2, _competitorId, _cultureSecond); Assert.AreNotEqual(_defaultPlayer.name, playerProfileCI.GetName(_cultureFirst)); Assert.AreNotEqual(_defaultPlayer.nationality, playerProfileCI.GetNationality(_cultureFirst)); Compare(playerProfileCI, _defaultPlayer, _cultureSecond); }
private static void ValidatePlayerExtended(playerExtended msg, PlayerProfileDTO dto) { Assert.AreEqual(msg.id, dto.Id.ToString()); Assert.AreEqual(msg.name, dto.Name); Assert.AreEqual(msg.date_of_birth, dto.DateOfBirth?.ToString("yyyy-MM-dd")); Assert.AreEqual(msg.height, dto.Height); Assert.AreEqual(msg.nationality, dto.Nationality); Assert.AreEqual(msg.type, dto.Type); Assert.AreEqual(msg.weight, dto.Weight); //TODO: missing jersey size }
internal PlayerProfileDTO CreateDTO() { PlayerProfileDTO dto = new PlayerProfileDTO(); dto.Address = this.Address; dto.DateOfBirth = this.DateOfBirth; dto.Picture = this.Picture != null?this.Picture.CreateDTO() : null; return(dto); }
public void PlayerProfileCreateTest() { var playerProfileDTO = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); Assert.IsNotNull(playerProfileDTO); var playerProfileCI = new PlayerProfileCI(playerProfileDTO, _competitorId, _cultureFirst, new TestDataRouterManager(new CacheManager())); Assert.IsNotNull(playerProfileCI); Compare(playerProfileCI, _defaultPlayer, _cultureFirst); }
public void PlayerProfileExportImportTest() { var playerProfileDTO = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); var playerProfileCI = new PlayerProfileCI(playerProfileDTO, _competitorId, _cultureFirst, new TestDataRouterManager(new CacheManager())); var exportable = (ExportablePlayerProfileCI)playerProfileCI.ExportAsync().Result; playerProfileCI.Import(exportable); var playerProfileCI2 = new PlayerProfileCI(exportable, _dataRouterManager); Assert.IsNotNull(playerProfileCI2); Compare(playerProfileCI, playerProfileCI2); }
public void PlayerCompetitorAddProfileTest() { _defaultPlayerCompetitor.nationality = null; var playerCompetitorDTO = new PlayerCompetitorDTO(_defaultPlayerCompetitor); var playerProfileCI = new PlayerProfileCI(playerCompetitorDTO, _competitorId, _cultureFirst, _dataRouterManager); var playerProfileDTO = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); Assert.IsNotNull(playerProfileDTO); playerProfileCI.Merge(playerProfileDTO, _competitorId, _cultureSecond); Compare(playerProfileCI, _defaultPlayer, _cultureSecond); }
/// <summary> /// Initializes a new instance of the <see cref="PlayerProfileCI"/> class /// </summary> /// <param name="profile">The <see cref="PlayerProfileDTO"/> used to create instance</param> /// <param name="culture">The culture of the <see cref="PlayerProfileDTO"/> used to create new instance</param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to fetch <see cref="PlayerProfileDTO"/></param> internal PlayerProfileCI(PlayerProfileDTO profile, CultureInfo culture, IDataRouterManager dataRouterManager) : base(profile) { Contract.Requires(profile != null); Contract.Requires(culture != null); Contract.Requires(dataRouterManager != null); _fetchedCultures = new List <CultureInfo>(); _primaryCulture = culture; _dataRouterManager = dataRouterManager; Names = new Dictionary <CultureInfo, string>(); _nationalities = new Dictionary <CultureInfo, string>(); Merge(profile, culture); }
public async Task <PlayerProfileDTO> FetchPlayerProfileAsync(uint id) { using HttpRequestMessage request = new(HttpMethod.Get, $"{playerEndpointCategory}/{id}?includeClanInfo=true"); using HttpResponseMessage response = await Client.SendAsync(request); if (response.StatusCode is HttpStatusCode.NotFound or HttpStatusCode.NoContent) { return(null); } await EnsureSuccessfulResponseAsync(response); PlayerProfileDTO player = await response.Content.ReadFromJsonAsync <PlayerProfileDTO>(SerializerOptions); return(player); }
/// <summary> /// Initializes a new instance of the <see cref="PlayerProfileCI"/> class /// </summary> /// <param name="profile">The <see cref="PlayerProfileDTO"/> used to create instance</param> /// <param name="competitorId">The competitor id this player belongs to</param> /// <param name="culture">The culture of the <see cref="PlayerProfileDTO"/> used to create new instance</param> /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to fetch <see cref="PlayerProfileDTO"/></param> internal PlayerProfileCI(PlayerProfileDTO profile, URN competitorId, CultureInfo culture, IDataRouterManager dataRouterManager) : base(profile) { Guard.Argument(profile, nameof(profile)).NotNull(); Guard.Argument(culture, nameof(culture)).NotNull(); Guard.Argument(dataRouterManager, nameof(dataRouterManager)).NotNull(); _fetchedCultures = new List <CultureInfo>(); _primaryCulture = culture; _dataRouterManager = dataRouterManager; Names = new Dictionary <CultureInfo, string>(); _nationalities = new Dictionary <CultureInfo, string>(); Merge(profile, competitorId, culture); }
public void PlayerProfileExportImportCreateTest() { var playerProfileDTO = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); var playerProfileCI = new PlayerProfileCI(playerProfileDTO, _competitorId, _cultureFirst, new TestDataRouterManager(new CacheManager())); var exportable = playerProfileCI.ExportAsync().Result; Assert.IsNotNull(exportable); var json = JsonConvert.SerializeObject(exportable, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); var importable = JsonConvert.DeserializeObject <ExportablePlayerProfileCI>(json); var playerProfileCI2 = new PlayerProfileCI(importable, _dataRouterManager); Assert.IsNotNull(playerProfileCI2); Compare(playerProfileCI, playerProfileCI2); }
/// <summary> /// Merges the specified <see cref="PlayerProfileDTO"/> into instance /// </summary> /// <param name="profile">The <see cref="PlayerProfileDTO"/> used to merge into instance</param> /// <param name="culture">The culture of the <see cref="PlayerProfileDTO"/> used to merge</param> internal void Merge(PlayerProfileDTO profile, CultureInfo culture) { Contract.Requires(profile != null); Contract.Requires(culture != null); _type = profile.Type; _dateOfBirth = profile.DateOfBirth; Names[culture] = profile.Name; _nationalities[culture] = profile.Nationality; _height = profile.Height; _weight = profile.Weight; if (string.IsNullOrEmpty(_abbreviation)) { _abbreviation = SdkInfo.GetAbbreviationFromName(profile.Name); } ((List <CultureInfo>)_fetchedCultures).Add(culture); }
private static void ValidatePlayerExtended(playerExtended msg, PlayerProfileDTO dto) { Assert.AreEqual(msg.id, dto.Id.ToString()); Assert.AreEqual(msg.name, dto.Name); Assert.AreEqual(msg.date_of_birth, dto.DateOfBirth?.ToString("yyyy-MM-dd")); Assert.AreEqual(msg.height, dto.Height); Assert.AreEqual(msg.nationality, dto.Nationality); Assert.AreEqual(msg.type, dto.Type); Assert.AreEqual(msg.weight, dto.Weight); //TODO: missing jersey size if (msg.jersey_numberSpecified) { Assert.AreEqual(msg.jersey_number, dto.JerseyNumber.Value); } else { Assert.IsFalse(dto.JerseyNumber.HasValue); } Assert.AreEqual(msg.gender, dto.Gender); }
public void PlayerProfileExportImportMissingDataTest() { _defaultPlayer.nationality = null; _defaultPlayer.nickname = null; _defaultPlayer.weightSpecified = false; _defaultPlayer.jersey_numberSpecified = false; _defaultPlayer.country_code = null; var playerProfileDTO = new PlayerProfileDTO(_defaultPlayer, DateTime.Now); var playerProfileCI = new PlayerProfileCI(playerProfileDTO, _competitorId, _cultureFirst, new TestDataRouterManager(new CacheManager())); var exportable = (ExportablePlayerProfileCI)playerProfileCI.ExportAsync().Result; playerProfileCI.Import(exportable); var playerProfileCI2 = new PlayerProfileCI(exportable, _dataRouterManager); Assert.IsNotNull(playerProfileCI2); Compare(playerProfileCI, playerProfileCI2); }
internal static PlayerProfile FromDTO(PlayerProfileDTO x) { throw new NotImplementedException(); }