public void CsvFileAppend_WhenThereIsData_Appends()
        {
            var sut = new CsvFile(@"./Data/")
            {
                FilePath = "GameLog",
                StartNew = true,
            };
            var createResult = sut.Create();

            Assert.IsTrue(createResult.IsSuccess);
            var metrics = new string[11];

            metrics[0]  = "2019-06-22";
            metrics[1]  = "mlb-josh-bell";
            metrics[2]  = "2";
            metrics[3]  = "4";
            metrics[4]  = "1";
            metrics[5]  = "1";
            metrics[6]  = "6";
            metrics[7]  = "3";
            metrics[8]  = "0";
            metrics[9]  = "1";
            metrics[10] = "0";
            var result = sut.AppendLine(metrics);

            result.OnFailure(() => Console.WriteLine(
                                 $"Error:{result.Error}"));
            Assert.IsTrue(result.IsSuccess);
            Assert.IsTrue(File.Exists(@".\Data\GameLog.csv"));
        }
Exemple #2
0
        private void WriteToCsv(
            CsvFile csv,
            Result <PlayerGameLogViewModel> result)
        {
            var gamelog = result.Value;
            var metrics = new string[11];

            metrics[0]  = $"{Utility.UniversalDate(gamelog.AsOf)}";
            metrics[1]  = PlayerSlug;
            metrics[2]  = gamelog.Hits.ToString();
            metrics[3]  = gamelog.AtBats.ToString();
            metrics[4]  = gamelog.Runs.ToString();
            metrics[5]  = gamelog.HomeRuns.ToString();
            metrics[6]  = gamelog.TotalBases.ToString();
            metrics[7]  = gamelog.RunsBattedIn.ToString();
            metrics[8]  = gamelog.Walks.ToString();
            metrics[9]  = gamelog.StrikeOuts.ToString();
            metrics[10] = gamelog.NetSteals().ToString();
            csv.AppendLine(metrics);
        }