public void TransactionFileReader_ShouldReadTransaction_WhenIncorrectDataProvided(string entry) { // Arrange var merchants = new Dictionary <string, Merchant>(); merchants.Add("7-ELEVEN", new Merchant() { DiscountPercentage = 0, Name = sevenEleven, FeeAsPercentage = 1 }); var exceptionTrhown = false; var transactionReader = new TransactionFileReader(); // Incorrect date format var memoryStream = GenerateStreamFromString(entry); StreamReader reader = new StreamReader(memoryStream); // Act try { var transaction = transactionReader.ReadSingleEntry(reader, merchants, new TransactionParser()); } catch (Exception exception) { exceptionTrhown = true; Assert.Equal("Improper format of transaction date", exception.Message); } // Assert Assert.True(exceptionTrhown); }
public void enqueued_item_exists_when_dequeued() { var writer = new TransactionFileWriter<object>(Filename, new BinaryFormatter()); writer.Enqueue(new object()); var reader = new TransactionFileReader<object>(Filename, new BinaryFormatter()); var item = reader.Dequeue(); Assert.IsNotNull(item); }
public void TransactionFileReader_ShouldReadTransaction_WhenCorrectDataProvided() { // Arrange var merchants = new Dictionary <string, Merchant>(); merchants.Add("7-ELEVEN", new Merchant() { DiscountPercentage = 0, Name = sevenEleven, FeeAsPercentage = 1 }); merchants.Add("CIRCLE_K", new Merchant() { DiscountPercentage = 20, Name = circleK, FeeAsPercentage = 1 }); merchants.Add("TELIA", new Merchant() { DiscountPercentage = 10, Name = telia, FeeAsPercentage = 1 }); merchants.Add("NETTO", new Merchant() { DiscountPercentage = 0, Name = netto, FeeAsPercentage = 1 }); var transactionReader = new TransactionFileReader(); var text = @"2018-09-01 7-ELEVEN 100 2018-09-04 CIRCLE_K 200"; var memoryStream = GenerateStreamFromString(text); StreamReader reader = new StreamReader(memoryStream); // Act var transaction = transactionReader.ReadSingleEntry(reader, merchants, new TransactionParser()); // Assert Assert.Equal(sevenEleven, transaction.Owner.Name); Assert.Equal(new DateTime(2018, 9, 1), transaction.DoneOn); Assert.Equal(100M, transaction.Amount); }
public void filestream_is_disposed() { var reader = new TransactionFileReader<object>("When_disposing_a_writer", new BinaryFormatter()); reader.Dispose(); Assert.IsNull(reader.FileStream); }