public void CumulativeReportGeneration() { // Create new log for a vending machine that sells only coke TransLog log = new TransLog(); Item coke = new Item("Coca Cola", "drink", 2.35m, "A2", 1); log.ItemsSold.Add(coke.Name, 0); // starts with 0 sold // log a sale decimal balance = 10.00m; log.LogPurchase(balance, coke); // Clear files before writing File.Delete(log.LogPath); // don't need the log file for this test if (File.Exists(log.ReportPath)) { File.Delete(log.ReportPath); } // generate the report log.GenerateReport(); // Does the report exist? Assert.IsTrue(File.Exists(log.ReportPath), "Report file should be created."); // Does it have the expected info and formatting inside? string expected = "Coca Cola|1"; using (StreamReader sr = new StreamReader(log.ReportPath)) { Assert.AreEqual(expected, sr.ReadLine(), "Report should contain the expected output."); } File.Delete(log.ReportPath); }
public void PurchaseLogging() { // Setup new log and the money amounts TransLog log = new TransLog(); File.Delete(log.LogPath); decimal balance = 10.00m; // Add a coke to the log inventory Item coke = new Item("Coca Cola", "drink", 2.35m, "A2", 1); log.ItemsSold.Add(coke.Name, 0); // starts with 0 sold // Log the GIVE CHANGE operation DateTime time = log.Time; log.LogPurchase(balance, coke); using (StreamReader sr = new StreamReader(log.LogPath)) { string expected = $"{time} {coke.Name.PadRight(22)} {coke.Slot} {(balance + coke.Price):C} - {coke.Price:C} = {balance:C}"; Assert.AreEqual(expected, sr.ReadLine(), "Log text should match expected string."); } File.Delete(log.LogPath); }