Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayerProfile"/> class
        /// </summary>
        /// <param name="ci">A <see cref="PlayerProfileCI"/> representing cached player profile info</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying supported languages of the constructed instance</param>
        public PlayerProfile(PlayerProfileCI ci, IEnumerable <CultureInfo> cultures)
            : base(ci.Id, cultures.Where(c => ci.GetName(c) != null).ToDictionary(c => c, ci.GetName))
        {
            Guard.Argument(ci, nameof(ci)).NotNull();
            Guard.Argument(cultures, nameof(cultures)).NotNull().NotEmpty();

            _playerProfileCI = ci;
            _cultures        = cultures.ToList();
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="PlayerProfile" /> class
        /// </summary>
        /// <param name="ci">A <see cref="PlayerProfileCI" /> representing cached player profile info</param>
        /// <param name="cultures">
        ///     A <see cref="IEnumerable{CultureInfo}" /> specifying supported languages of the constructed
        ///     instance
        /// </param>
        public PlayerProfile(PlayerProfileCI ci, IEnumerable <CultureInfo> cultures)
            : base(ci.Id, cultures.Where(c => ci.GetName(c) != null).ToDictionary(c => c, ci.GetName))
        {
            Contract.Requires(ci != null);
            Contract.Requires(cultures != null && cultures.Any());

            _playerProfileCI = ci;
            _cultures        = cultures.ToList();
        }
Example #5
0
        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);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayerProfile"/> class
        /// </summary>
        /// <param name="ci">A <see cref="PlayerProfileCI"/> representing cached player profile info</param>
        /// <param name="cultures">A <see cref="IEnumerable{CultureInfo}"/> specifying supported languages of the constructed instance</param>
        public PlayerProfile(PlayerProfileCI ci, IEnumerable <CultureInfo> cultures)
            : base(ci.Id, cultures.Where(c => ci.GetName(c) != null).ToDictionary(c => c, ci.GetName))
        {
            Guard.Argument(ci, nameof(ci)).NotNull();
            Guard.Argument(cultures, nameof(cultures)).NotNull();//.NotEmpty();
            if (!cultures.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(cultures));
            }

            _playerProfileCI = ci;
            _cultures        = cultures.ToList();
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        public void PlayerCompetitorCreateTest()
        {
            var playerCompetitorDTO = new PlayerCompetitorDTO(_defaultPlayerCompetitor);

            Assert.IsNotNull(playerCompetitorDTO);

            var playerProfileCI = new PlayerProfileCI(playerCompetitorDTO, _competitorId, _cultureFirst, _dataRouterManager);

            Assert.IsNotNull(playerProfileCI);

            Assert.AreEqual(_defaultPlayerCompetitor.id, playerProfileCI.Id.ToString());
            Assert.AreEqual(_defaultPlayerCompetitor.name, playerProfileCI.GetName(_cultureFirst));
            Assert.AreEqual(_defaultPlayerCompetitor.nationality, playerProfileCI.GetNationality(_cultureFirst));
            Assert.AreEqual(_defaultPlayerCompetitor.abbreviation, playerProfileCI.Abbreviation);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
 private void Compare(PlayerProfileCI playerCI, PlayerProfileCI playerCI2)
 {
     Assert.AreEqual(playerCI.Id, playerCI2.Id);
     Assert.AreEqual(playerCI.Abbreviation, playerCI2.Abbreviation);
     Assert.AreEqual(playerCI.CompetitorId, playerCI2.CompetitorId);
     Assert.AreEqual(playerCI.CountryCode, playerCI2.CountryCode);
     Assert.AreEqual(playerCI.DateOfBirth, playerCI2.DateOfBirth);
     Assert.AreEqual(playerCI.FullName, playerCI2.FullName);
     Assert.AreEqual(playerCI.Gender, playerCI2.Gender);
     Assert.AreEqual(playerCI.Names.Count, playerCI2.Names.Count);
     foreach (var culture in playerCI.Names.Keys)
     {
         Assert.AreEqual(playerCI.GetName(culture), playerCI2.GetName(culture));
         Assert.AreEqual(playerCI.GetNationality(culture), playerCI2.GetNationality(culture));
     }
     Assert.AreEqual(playerCI.Height, playerCI2.Height);
     Assert.AreEqual(playerCI.Nickname, playerCI2.Nickname);
     Assert.AreEqual(playerCI.Weight, playerCI2.Weight);
     Assert.AreEqual(playerCI.Type, playerCI2.Type);
 }
Example #13
0
        private void Compare(PlayerProfileCI playerCI, playerExtended player, CultureInfo culture)
        {
            Assert.IsNotNull(playerCI);
            Assert.IsNotNull(player);

            Assert.AreEqual(player.id, playerCI.Id.ToString());
            Assert.AreEqual(_competitorId, playerCI.CompetitorId);
            if (player.type == null)
            {
                Assert.IsNull(playerCI.Type);
            }
            else
            {
                Assert.AreEqual(player.type, playerCI.Type);
            }
            if (player.country_code == null)
            {
                Assert.IsNull(playerCI.CountryCode);
            }
            else
            {
                Assert.AreEqual(player.country_code, playerCI.CountryCode);
            }
            if (player.date_of_birth == null)
            {
                Assert.IsNull(playerCI.DateOfBirth);
            }
            else
            {
                Assert.AreEqual(player.date_of_birth, playerCI.DateOfBirth.Value.ToString("yyyy-MM-dd"));
            }
            if (player.full_name == null)
            {
                Assert.IsNull(playerCI.FullName);
            }
            else
            {
                Assert.AreEqual(player.full_name, playerCI.FullName);
            }
            if (player.gender == null)
            {
                Assert.IsNull(playerCI.Gender);
            }
            else
            {
                Assert.AreEqual(player.gender, playerCI.Gender);
            }
            if (!player.heightSpecified)
            {
                Assert.IsNull(playerCI.Height);
            }
            else
            {
                Assert.IsTrue(player.height > 0);
                Assert.AreEqual(player.height, playerCI.Height);
            }
            if (!player.weightSpecified)
            {
                Assert.IsNull(playerCI.Weight);
            }
            else
            {
                Assert.IsTrue(player.weight > 0);
                Assert.AreEqual(player.weight, playerCI.Weight);
            }
            if (player.type == null)
            {
                Assert.IsNull(playerCI.Type);
            }
            else
            {
                Assert.AreEqual(player.type, playerCI.Type);
            }
            //if (!player.jersey_numberSpecified)
            //{
            //    Assert.IsNull(playerCI.);
            //}
            //else
            //{
            //    Assert.IsTrue(player.height > 0);
            //    Assert.AreEqual(player.height, playerCI.Height);
            //}
            if (player.name == null)
            {
                Assert.IsNull(playerCI.GetName(culture));
            }
            else
            {
                Assert.AreEqual(player.name, playerCI.GetName(culture));
            }
            if (player.nationality == null)
            {
                Assert.IsNull(playerCI.GetNationality(culture));
            }
            else
            {
                Assert.AreEqual(player.nationality, playerCI.GetNationality(culture));
            }
            if (player.nickname == null)
            {
                Assert.IsNull(playerCI.Nickname);
            }
            else
            {
                Assert.AreEqual(player.nickname, playerCI.Nickname);
            }
            if (player.name == null)
            {
                Assert.IsNull(playerCI.Abbreviation);
            }
            else
            {
                Assert.AreEqual(SdkInfo.GetAbbreviationFromName(player.name), playerCI.Abbreviation);
            }
        }