public void ReadPricesForCusips_LeadingLineIsBalnk_Failure() { // Arrange const string expectedMsg = "First line of Feed is not a cusip"; const int expectedLineCount = 1; var feed = @" A2345678 123.456 "; var byteArray = Encoding.UTF8.GetBytes(feed); using (var feedMem = new MemoryStream(byteArray)) using (var feedStream = new StreamReader(feedMem)) { var proc = new CusipProcessor(feedStream); // Act var ex = Assert.Throws <FeedException>(() => proc.ReadCusip()); // Assert Assert.Equal(expectedMsg, ex.Message); Assert.Equal(expectedLineCount, ex.CurrentLineCountOfException); Assert.True(string.IsNullOrEmpty(ex.LineOfException)); } }
public void ReadPricesForCusips_LastLineIsNotBalnk_Successful() { // Arrange var feed = @"A2345678 123.456 B2345678 234.567 235.678 C2345678 345.678 346.789 347.89 348.901"; var byteArray = Encoding.UTF8.GetBytes(feed); var cusipPricesDic = new Dictionary <string, decimal>(); using (var feedMem = new MemoryStream(byteArray)) using (var feedStream = new StreamReader(feedMem)) { var proc = new CusipProcessor(feedStream); var cusip = proc.ReadCusip(); // Act var cusipPrices = proc.ReadPricesForCusips(cusip); foreach (var clp in cusipPrices) { cusipPricesDic.Add(clp.Cusip, clp.Price); } // Assert Assert.Equal(123.456m, cusipPricesDic["A2345678"]); Assert.Equal(235.678m, cusipPricesDic["B2345678"]); Assert.Equal(348.901m, cusipPricesDic["C2345678"]); } }
public void ReadPricesForCusips_FeedFileContainsOneCusipAndNoPrices_Failure() { // Arrange var feed = "A2345678"; var byteArray = Encoding.UTF8.GetBytes(feed); using (var feedMem = new MemoryStream(byteArray)) using (var feedStream = new StreamReader(feedMem)) { var proc = new CusipProcessor(feedStream); var cusip = proc.ReadCusip(); // Act var cusipPrices = proc.ReadPricesForCusips(cusip); var isCusipPrice = cusipPrices.GetEnumerator().MoveNext(); // Assert Assert.False(isCusipPrice); } }
public void Readcusip_FileIsEmptyError_Failure() { // Arrange var feed = " "; var byteArray = Encoding.UTF8.GetBytes(feed); using (var feedMem = new MemoryStream(byteArray)) using (var feedStream = new StreamReader(feedMem)) { var proc = new CusipProcessor(feedStream); // Act var ex = Assert.Throws <FeedException>(proc.ReadCusip); // Assert Assert.Equal("First line of Feed is not a cusip", ex.Message); Assert.Equal(1, ex.CurrentLineCountOfException); Assert.Equal(feed, ex.LineOfException); } }
public void ReadPricesForCusips_MiddleLineIsBalnk_Failure() { // Arrange var feed = @"A2345678 123.456 B2345678 234.567 235.678 C2345678 345.678 346.789 347.89 348.901 "; var byteArray = Encoding.UTF8.GetBytes(feed); var cusipPricesDic = new Dictionary <string, decimal>(); using (var feedMem = new MemoryStream(byteArray)) using (var feedStream = new StreamReader(feedMem)) { var proc = new CusipProcessor(feedStream); var cusip = proc.ReadCusip(); var cusipPrices = proc.ReadPricesForCusips(cusip); // Act var ex = Assert.Throws <FeedException>(() => { foreach (var clp in cusipPrices) { cusipPricesDic.Add(clp.Cusip, clp.Price); } }); // Assert Assert.Equal("A blank line in the middle of the file indicates a corrupt Feed file", ex.Message); Assert.Equal(7, ex.CurrentLineCountOfException); Assert.True(string.IsNullOrEmpty(ex.LineOfException)); } }
static void Main(string[] args) { var dataFile1 = @"Data\Feed1Good.txt"; using (var cusipPriceSr = new StreamReader(dataFile1)) { try { var proc = new CusipProcessor(cusipPriceSr); proc.CusipPriceHandler += ProcCusipPriceHandler; var t = proc.ProcessFeedFile(); // Something else can be done here _ = t.Result; // Wait for the feed file to complete processesing } catch (FeedException ex) { Console.WriteLine(); Console.WriteLine($"System threw and exception. Problem in line in input file: {ex.CurrentLineCountOfException}"); if (!string.IsNullOrEmpty(ex.LineOfException)) { Console.WriteLine($"Input Line of exception: \"{ex.LineOfException}\""); } Console.WriteLine(ex.Message); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine(); Console.WriteLine($"{ex.GetType().Name}. {ex.Message}"); Console.WriteLine(); } } Console.WriteLine("Press the Enter key to exit"); Console.ReadKey(); }
public void ReadPricesForCusips_FeedFileContainsTwoCusipAndNoPrices_Failure() { // Arrange var feed = @"A2345678 B2345678"; var byteArray = Encoding.UTF8.GetBytes(feed); using (var feedMem = new MemoryStream(byteArray)) using (var feedStream = new StreamReader(feedMem)) { var proc = new CusipProcessor(feedStream); var cusip = proc.ReadCusip(); // Act var cusipPrices = proc.ReadPricesForCusips(cusip); var ex = Assert.Throws <FeedException>(() => cusipPrices.GetEnumerator().MoveNext()); // Assert Assert.Equal("Cusip A2345678 contains no price value", ex.Message); Assert.Equal(2, ex.CurrentLineCountOfException); Assert.Equal("B2345678", ex.LineOfException); } }