Loading StockAdvisory.Tests/StockTextFormatterTests.cs +28 −34 Original line number Original line Diff line number Diff line Loading @@ -9,50 +9,56 @@ namespace StockAdvisory.Tests; public class StockTextFormatterTests public class StockTextFormatterTests { { public StockEntryRecord TeslaRecord = new StockEntryRecord() private readonly StockEntryRecord _teslaRecord = new() { { Date = new DateTime(2022, 3, 28), Company = "TESLA INC", Ticker = "TSLA", Date = new DateTime(2022, 3, 28), Company = "TESLA INC", Ticker = "TSLA", CuspId = "88160R101", Shares = 1_166_661, MarketValue = 1_179_074_273.04M, Weight = 100.00M CuspId = "88160R101", Shares = 1_166_661, MarketValue = 1_179_074_273.04M, Weight = 100.00M }; }; public StockDifferenceRecord SpotifyDiffRecord = new StockDifferenceRecord() private readonly StockDifferenceRecord _spotifyDiffRecord = new() { { Company = "SPOTIFY TECHNOLOGY SA", Ticker = "SPOT", CuspId = "L8681T102", Company = "SPOTIFY TECHNOLOGY SA", Ticker = "SPOT", CuspId = "L8681T102", Shares = 3_229_198, SharesPercentChange = (float) 4.01, Weight = 504_271_559 Shares = 3_229_198, SharesPercentChange = (float) 4.01, Weight = 504_271_559 }; }; private static void CheckStringRecordContainingAllInformation(StockRecord expected, string formattedRecord) { StringAssert.Contains(expected.Company, formattedRecord); StringAssert.Contains(expected.Ticker, formattedRecord); StringAssert.Contains(expected.Shares.ToString(), formattedRecord); StringAssert.Contains(expected.Weight.ToString(CultureInfo.InvariantCulture), formattedRecord); } private static void CheckStringRecordWithAdditionalInfo(StockDifferenceRecord expected, string formattedRecord) { CheckStringRecordContainingAllInformation(expected, formattedRecord); StringAssert.Contains(expected.SharesPercentChange.ToString(CultureInfo.InvariantCulture), formattedRecord); } [Test] [Test] public void Test_When_SingleStockEntryRecordIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_SingleStockEntryRecordIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var formattedString = formatter.Format(TeslaRecord); var formattedString = formatter.Format(_teslaRecord); StringAssert.Contains(TeslaRecord.Company, formattedString); CheckStringRecordContainingAllInformation(_teslaRecord, formattedString); StringAssert.Contains(TeslaRecord.Ticker, formattedString); StringAssert.Contains(TeslaRecord.Shares.ToString(), formattedString); StringAssert.Contains(TeslaRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); // what is contained is up for debate, right now everything except date } } [Test] [Test] public void Test_When_CollectionWithSingleStockEntryIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_CollectionWithSingleStockEntryIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var records = new List<StockEntryRecord>() {TeslaRecord}; var records = new List<StockEntryRecord>() {_teslaRecord}; var formattedString = formatter.Format(records); var formattedString = formatter.Format(records); StringAssert.Contains(TeslaRecord.Company, formattedString); CheckStringRecordContainingAllInformation(_teslaRecord, formattedString); StringAssert.Contains(TeslaRecord.Ticker, formattedString); StringAssert.Contains(TeslaRecord.Shares.ToString(), formattedString); StringAssert.Contains(TeslaRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); // what is contained is up for debate, right now everything except date } } [Test] [Test] public void Test_When_CollectionOfStockEntriesIsProvided_Then_OutputDoesNotStartWithEmptyLine() public void Test_When_CollectionOfStockEntriesIsProvided_Then_OutputDoesNotStartWithEmptyLine() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var records = new List<StockEntryRecord>() {TeslaRecord}; var records = new List<StockEntryRecord>() {_teslaRecord}; var formattedString = formatter.Format(records); var formattedString = formatter.Format(records); var stringReader = new StringReader(formattedString); var stringReader = new StringReader(formattedString); var line = stringReader.ReadLine(); var line = stringReader.ReadLine(); Loading @@ -64,28 +70,16 @@ public class StockTextFormatterTests public void Test_When_StockDifferenceRecordIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_StockDifferenceRecordIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var formattedString = formatter.Format(SpotifyDiffRecord); var formattedString = formatter.Format(_spotifyDiffRecord); StringAssert.Contains(SpotifyDiffRecord.Company, formattedString); CheckStringRecordWithAdditionalInfo(_spotifyDiffRecord, formattedString); StringAssert.Contains(SpotifyDiffRecord.Ticker, formattedString); StringAssert.Contains(SpotifyDiffRecord.Shares.ToString(), formattedString); StringAssert.Contains(SpotifyDiffRecord.SharesPercentChange.ToString(CultureInfo.InvariantCulture), formattedString); StringAssert.Contains(SpotifyDiffRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); } } [Test] [Test] public void Test_When_CollectionWithSingleStockDiffRecordIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_CollectionWithSingleStockDiffRecordIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var records = new List<StockDifferenceRecord>() { SpotifyDiffRecord }; var records = new List<StockDifferenceRecord>() {_spotifyDiffRecord}; var formattedString = formatter.Format(records); var formattedString = formatter.Format(records); StringAssert.Contains(SpotifyDiffRecord.Company, formattedString); CheckStringRecordWithAdditionalInfo(_spotifyDiffRecord, formattedString); StringAssert.Contains(SpotifyDiffRecord.Ticker, formattedString); StringAssert.Contains(SpotifyDiffRecord.Shares.ToString(), formattedString); StringAssert.Contains(SpotifyDiffRecord.SharesPercentChange.ToString(CultureInfo.InvariantCulture), formattedString); StringAssert.Contains(SpotifyDiffRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); } } } } No newline at end of file Loading
StockAdvisory.Tests/StockTextFormatterTests.cs +28 −34 Original line number Original line Diff line number Diff line Loading @@ -9,50 +9,56 @@ namespace StockAdvisory.Tests; public class StockTextFormatterTests public class StockTextFormatterTests { { public StockEntryRecord TeslaRecord = new StockEntryRecord() private readonly StockEntryRecord _teslaRecord = new() { { Date = new DateTime(2022, 3, 28), Company = "TESLA INC", Ticker = "TSLA", Date = new DateTime(2022, 3, 28), Company = "TESLA INC", Ticker = "TSLA", CuspId = "88160R101", Shares = 1_166_661, MarketValue = 1_179_074_273.04M, Weight = 100.00M CuspId = "88160R101", Shares = 1_166_661, MarketValue = 1_179_074_273.04M, Weight = 100.00M }; }; public StockDifferenceRecord SpotifyDiffRecord = new StockDifferenceRecord() private readonly StockDifferenceRecord _spotifyDiffRecord = new() { { Company = "SPOTIFY TECHNOLOGY SA", Ticker = "SPOT", CuspId = "L8681T102", Company = "SPOTIFY TECHNOLOGY SA", Ticker = "SPOT", CuspId = "L8681T102", Shares = 3_229_198, SharesPercentChange = (float) 4.01, Weight = 504_271_559 Shares = 3_229_198, SharesPercentChange = (float) 4.01, Weight = 504_271_559 }; }; private static void CheckStringRecordContainingAllInformation(StockRecord expected, string formattedRecord) { StringAssert.Contains(expected.Company, formattedRecord); StringAssert.Contains(expected.Ticker, formattedRecord); StringAssert.Contains(expected.Shares.ToString(), formattedRecord); StringAssert.Contains(expected.Weight.ToString(CultureInfo.InvariantCulture), formattedRecord); } private static void CheckStringRecordWithAdditionalInfo(StockDifferenceRecord expected, string formattedRecord) { CheckStringRecordContainingAllInformation(expected, formattedRecord); StringAssert.Contains(expected.SharesPercentChange.ToString(CultureInfo.InvariantCulture), formattedRecord); } [Test] [Test] public void Test_When_SingleStockEntryRecordIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_SingleStockEntryRecordIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var formattedString = formatter.Format(TeslaRecord); var formattedString = formatter.Format(_teslaRecord); StringAssert.Contains(TeslaRecord.Company, formattedString); CheckStringRecordContainingAllInformation(_teslaRecord, formattedString); StringAssert.Contains(TeslaRecord.Ticker, formattedString); StringAssert.Contains(TeslaRecord.Shares.ToString(), formattedString); StringAssert.Contains(TeslaRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); // what is contained is up for debate, right now everything except date } } [Test] [Test] public void Test_When_CollectionWithSingleStockEntryIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_CollectionWithSingleStockEntryIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var records = new List<StockEntryRecord>() {TeslaRecord}; var records = new List<StockEntryRecord>() {_teslaRecord}; var formattedString = formatter.Format(records); var formattedString = formatter.Format(records); StringAssert.Contains(TeslaRecord.Company, formattedString); CheckStringRecordContainingAllInformation(_teslaRecord, formattedString); StringAssert.Contains(TeslaRecord.Ticker, formattedString); StringAssert.Contains(TeslaRecord.Shares.ToString(), formattedString); StringAssert.Contains(TeslaRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); // what is contained is up for debate, right now everything except date } } [Test] [Test] public void Test_When_CollectionOfStockEntriesIsProvided_Then_OutputDoesNotStartWithEmptyLine() public void Test_When_CollectionOfStockEntriesIsProvided_Then_OutputDoesNotStartWithEmptyLine() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var records = new List<StockEntryRecord>() {TeslaRecord}; var records = new List<StockEntryRecord>() {_teslaRecord}; var formattedString = formatter.Format(records); var formattedString = formatter.Format(records); var stringReader = new StringReader(formattedString); var stringReader = new StringReader(formattedString); var line = stringReader.ReadLine(); var line = stringReader.ReadLine(); Loading @@ -64,28 +70,16 @@ public class StockTextFormatterTests public void Test_When_StockDifferenceRecordIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_StockDifferenceRecordIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var formattedString = formatter.Format(SpotifyDiffRecord); var formattedString = formatter.Format(_spotifyDiffRecord); StringAssert.Contains(SpotifyDiffRecord.Company, formattedString); CheckStringRecordWithAdditionalInfo(_spotifyDiffRecord, formattedString); StringAssert.Contains(SpotifyDiffRecord.Ticker, formattedString); StringAssert.Contains(SpotifyDiffRecord.Shares.ToString(), formattedString); StringAssert.Contains(SpotifyDiffRecord.SharesPercentChange.ToString(CultureInfo.InvariantCulture), formattedString); StringAssert.Contains(SpotifyDiffRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); } } [Test] [Test] public void Test_When_CollectionWithSingleStockDiffRecordIsProvided_Then_AllRelevantInformationIsContained() public void Test_When_CollectionWithSingleStockDiffRecordIsProvided_Then_AllRelevantInformationIsContained() { { var formatter = new StockTextFormatter(); var formatter = new StockTextFormatter(); var records = new List<StockDifferenceRecord>() { SpotifyDiffRecord }; var records = new List<StockDifferenceRecord>() {_spotifyDiffRecord}; var formattedString = formatter.Format(records); var formattedString = formatter.Format(records); StringAssert.Contains(SpotifyDiffRecord.Company, formattedString); CheckStringRecordWithAdditionalInfo(_spotifyDiffRecord, formattedString); StringAssert.Contains(SpotifyDiffRecord.Ticker, formattedString); StringAssert.Contains(SpotifyDiffRecord.Shares.ToString(), formattedString); StringAssert.Contains(SpotifyDiffRecord.SharesPercentChange.ToString(CultureInfo.InvariantCulture), formattedString); StringAssert.Contains(SpotifyDiffRecord.Weight.ToString(CultureInfo.InvariantCulture), formattedString); } } } } No newline at end of file