private void CopyPlayerDataIfPlayerExists(PitchingPost pitching, PitchingPostStats pitchingStats)
 {
     if (pitching.Player != null)
     {
         pitchingStats.NameFirst = pitching.Player.NameFirst;
         pitchingStats.NameLast  = pitching.Player.NameLast;
         pitchingStats.NameGiven = pitching.Player.NameGiven;
     }
 }
        public void AssertGetPitchingStatsReturnsStats(PitchingPost expectedPitching)
        {
            var expectedPitchingStats = new PitchingPostStats();

            _mockMapper.Setup(mockPitchingMapper => mockPitchingMapper.Map(expectedPitching)).Returns(expectedPitchingStats);

            var actualPitching = _service.GetPitchingPostStats(expectedPitching.PlayerId);

            Assert.That(actualPitching.ElementAt(0), Is.EqualTo(expectedPitchingStats));
        }
        private void AssertGetPitchingPostStatsByYearReturnsStats(PitchingPost expectedPitching)
        {
            var expectedPitchingPostStats = new PitchingPostStats();

            _mockMapper.Setup(mockPitchingMapper => mockPitchingMapper.Map(expectedPitching)).Returns(expectedPitchingPostStats);

            var actualPitchingLeaderboardStats = _service.GetPitchingPostStatsByYear(expectedPitching.YearId);

            Assert.That(actualPitchingLeaderboardStats.ElementAt(0), Is.EqualTo(expectedPitchingPostStats));
        }
Пример #4
0
        public void MapCopiesDataFromPitchingPostToPitchingPostStats()
        {
            PitchingPost      pitchingPost      = GeneratePitchingPostWithoutNullValues();
            PitchingPostStats pitchingPostStats = _mapper.Map(pitchingPost);

            AssertThatEachElementIsEqual(pitchingPost, pitchingPostStats);

            PitchingPost      pitchingPostWithNull      = GeneratePitchingPostWithNullValues();
            PitchingPostStats pitchingPostStatsWithNull = _mapper.Map(pitchingPostWithNull);

            AssertThatEachElementIsEqual(pitchingPostWithNull, pitchingPostStatsWithNull);
        }
        private void CopyNullableStats(PitchingPost pitching, PitchingPostStats pitchingStats)
        {
            pitchingStats.W = pitching.W;

            pitchingStats.L = pitching.L;

            pitchingStats.G = pitching.G;

            pitchingStats.Gs = pitching.Gs;

            pitchingStats.Cg = pitching.Cg;

            pitchingStats.Sho = pitching.Sho;


            pitchingStats.Sv = pitching.Sv;

            pitchingStats.Ipouts = pitching.Ipouts;

            pitchingStats.H = pitching.H;

            pitchingStats.Er = pitching.Er;

            pitchingStats.Hr = pitching.Hr;

            pitchingStats.Bb = pitching.Bb;

            pitchingStats.So = pitching.So;

            pitchingStats.Baopp = pitching.Baopp;

            pitchingStats.Era = pitching.Era;

            pitchingStats.Ibb = pitching.Ibb;

            pitchingStats.Wp = pitching.Wp;

            pitchingStats.Hbp = pitching.Hbp;

            pitchingStats.Bk = pitching.Bk;

            pitchingStats.Bfp = pitching.Bfp;

            pitchingStats.Gf = pitching.Gf;

            pitchingStats.R = pitching.R;

            pitchingStats.Sh = pitching.Sh;

            pitchingStats.Sf = pitching.Sf;

            pitchingStats.Gidp = pitching.Gidp;
        }
        public void CreateFakeData()
        {
            _firstPerson = new PitchingPost()
            {
                YearId   = 2000,
                Hr       = 20,
                W        = 10,
                PlayerId = "id",
                Round    = "WS"
            };

            _secondPerson = new PitchingPost()
            {
                YearId   = 2000,
                Hr       = 10,
                W        = 3,
                PlayerId = "anotherId",
                Round    = "WS"
            };

            _thirdPerson = new PitchingPost()
            {
                YearId   = 1999,
                Hr       = 18,
                W        = 99,
                PlayerId = "id",
                Round    = "WC"
            };

            _fourthPerson = new PitchingPost()
            {
                YearId   = 1998,
                Hr       = 18,
                W        = 20,
                PlayerId = "fourthId",
                Round    = "WC",

                Player = new People()
                {
                    PlayerId  = "fourthId",
                    NameFirst = "first",
                    NameGiven = "first middle",
                    NameLast  = "last"
                }
            };

            _database.Add(_firstPerson);
            _database.Add(_secondPerson);
            _database.Add(_thirdPerson);
            _database.Add(_fourthPerson);
            _database.SaveChanges();
        }
        public void AssertGetPitchingStatsReturnsStatsWithDuplicateId(PitchingPost firstEntry, PitchingPost secondEntry)
        {
            var firstEntryStats  = new PitchingPostStats();
            var secondEntryStats = new PitchingPostStats();

            _mockMapper.Setup(mockBattingMapper => mockBattingMapper.Map(firstEntry)).Returns(firstEntryStats);
            _mockMapper.Setup(mockBattingMapper => mockBattingMapper.Map(secondEntry)).Returns(secondEntryStats);

            var actualPeople = _service.GetPitchingPostStats(firstEntry.PlayerId);

            Assert.That(actualPeople.ElementAt(0), Is.EqualTo(firstEntryStats));
            Assert.That(actualPeople.ElementAt(1), Is.EqualTo(secondEntryStats));
        }
        public PitchingPostStats Map(PitchingPost pitching)
        {
            var pitchingPostStats = new PitchingPostStats()
            {
                PlayerId = pitching.PlayerId,
                YearId   = pitching.YearId,
                Round    = pitching.Round,
                TeamId   = pitching.TeamId,
                LgId     = pitching.LgId,
            };

            CopyPlayerDataIfPlayerExists(pitching, pitchingPostStats);

            CopyNullableStats(pitching, pitchingPostStats);

            _calculator.CalculateStats(pitchingPostStats);

            return(pitchingPostStats);
        }
Пример #9
0
        private void AssertThatEachElementIsEqualWithPlayerValues(PitchingPost pitching, PitchingPostStats pitchingStats)
        {
            Assert.That(pitchingStats.NameFirst, Is.EqualTo(pitching.Player.NameFirst));
            Assert.That(pitchingStats.NameGiven, Is.EqualTo(pitching.Player.NameGiven));
            Assert.That(pitchingStats.NameLast, Is.EqualTo(pitching.Player.NameLast));
            Assert.That(pitchingStats.PlayerId, Is.EqualTo(pitching.PlayerId));
            Assert.That(pitchingStats.YearId, Is.EqualTo(pitching.YearId));
            Assert.That(pitchingStats.Round, Is.EqualTo(pitching.Round));
            Assert.That(pitchingStats.TeamId, Is.EqualTo(pitching.TeamId));
            Assert.That(pitchingStats.LgId, Is.EqualTo(pitching.LgId));
            Assert.That(pitchingStats.W, Is.EqualTo(pitching.W));
            Assert.That(pitchingStats.L, Is.EqualTo(pitching.L));
            Assert.That(pitchingStats.G, Is.EqualTo(pitching.G));
            Assert.That(pitchingStats.Gs, Is.EqualTo(pitching.Gs));
            Assert.That(pitchingStats.Cg, Is.EqualTo(pitching.Cg));
            Assert.That(pitchingStats.Sho, Is.EqualTo(pitching.Sho));
            Assert.That(pitchingStats.Sv, Is.EqualTo(pitching.Sv));
            Assert.That(pitchingStats.Ipouts, Is.EqualTo(pitching.Ipouts));
            Assert.That(pitchingStats.H, Is.EqualTo(pitching.H));
            Assert.That(pitchingStats.Er, Is.EqualTo(pitching.Er));
            Assert.That(pitchingStats.Hr, Is.EqualTo(pitching.Hr));
            Assert.That(pitchingStats.Bb, Is.EqualTo(pitching.Bb));
            Assert.That(pitchingStats.So, Is.EqualTo(pitching.So));
            var localBaopp = pitching.Baopp / 100 ?? 0;

            Assert.That(pitchingStats.Baopp, Is.EqualTo(Math.Round(localBaopp, 2)));
            var localEra = pitching.Era / 100 ?? 0;

            Assert.That(pitchingStats.Era, Is.EqualTo(Math.Round(localEra, 2)));
            Assert.That(pitchingStats.Ibb, Is.EqualTo(pitching.Ibb));
            Assert.That(pitchingStats.Wp, Is.EqualTo(pitching.Wp));
            Assert.That(pitchingStats.Hbp, Is.EqualTo(pitching.Hbp));
            Assert.That(pitchingStats.Bk, Is.EqualTo(pitching.Bk));
            Assert.That(pitchingStats.Bfp, Is.EqualTo(pitching.Bfp));
            Assert.That(pitchingStats.Gf, Is.EqualTo(pitching.Gf));
            Assert.That(pitchingStats.R, Is.EqualTo(pitching.R));
            Assert.That(pitchingStats.Sh, Is.EqualTo(pitching.Sh));
            Assert.That(pitchingStats.Sf, Is.EqualTo(pitching.Sf));
            Assert.That(pitchingStats.Gidp, Is.EqualTo(pitching.Gidp));
        }
Пример #10
0
 private void loadButton_Click(object sender, RoutedEventArgs e)
 {
     errorMessage.Content = null;
     try
     {
         using (SessionNoServer session = new SessionNoServer(s_systemDir))
         {
             Console.WriteLine($"Running with databases in directory: {session.SystemDirectory}");
             session.BeginUpdate();
             File.Copy(s_licenseDbFile, System.IO.Path.Combine(session.SystemDirectory, "4.odb"), true);
             string line;
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Allstar.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     AllStar allStar = new AllStar(line);
                     session.Persist(allStar);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\AllstarFull.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     AllStarFull allStar = new AllStarFull(line);
                     session.Persist(allStar);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Appearances.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Appearances a = new Appearances(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\AwardsManagers.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     AwardsManagers a = new AwardsManagers(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\AwardsPlayers.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     AwardsPlayers a = new AwardsPlayers(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\AwardsShareManagers.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     AwardsShareManagers a = new AwardsShareManagers(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\AwardsSharePlayers.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     AwardsSharePlayers a = new AwardsSharePlayers(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Batting.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Batting a = new Batting(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\BattingPost.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     BattingPost a = new BattingPost(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Fielding.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Fielding a = new Fielding(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\FieldingOF.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     FieldingOF a = new FieldingOF(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\FieldingPost.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     FieldingPost a = new FieldingPost(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\HallOfFame.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     HallOfFame a = new HallOfFame(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\HOFold.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     HOFold a = new HOFold(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Managers.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Managers a = new Managers(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\ManagersHalf.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     ManagersHalf a = new ManagersHalf(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Master.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Master a = new Master(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Pitching.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Pitching a = new Pitching(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\PitchingPost.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     PitchingPost a = new PitchingPost(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Salaries.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Salaries a = new Salaries(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Schools.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Schools a = new Schools(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\SchoolsPlayers.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     SchoolsPlayers a = new SchoolsPlayers(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\SeriesPost.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     SeriesPost a = new SeriesPost(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Teams.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Teams a = new Teams(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\TeamsFranchises.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     TeamsFranchises a = new TeamsFranchises(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\TeamsHalf.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     TeamsHalf a = new TeamsHalf(line);
                     session.Persist(a);
                 }
             }
             using (StreamReader stream = new StreamReader(lahman58db.Text + "\\Xref_Stats.csv", true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     Xref_Stats a = new Xref_Stats(line);
                     session.Persist(a);
                 }
             }
             session.Commit();
             errorMessage.Content = "Done, databases located in: " + session.SystemDirectory + " View objects using VelocityDBBrowser";
         }
     }
     catch (Exception ex)
     {
         errorMessage.Content = ex.Message == null?ex.ToString() : ex.Message;
     }
 }