public void CalculateProfit() { IAccountingCalculator calc = new AccountingCalculator(); decimal net = calc.CalculateNet(1000m, 1000m); Assert.AreEqual(0m, net); }
protected void btnDisplayTotals_Click(object sender, EventArgs e) { try { decimal revenue = decimal.Parse(txtRevenue.Text); decimal expenses = decimal.Parse(txtExpenses.Text); IAccountingCalculator calculator = new AccountingCalculator(); decimal net = calculator.CalculateNet(revenue, expenses); litNet.Text = net.ToString("C"); decimal oer = calculator.CalculateOER(revenue, expenses); litOer.Text = oer.ToString("P2"); var maxOer = Convert.ToDecimal(ConfigurationManager.AppSettings["MaxAcceptableOER"]); if (oer > maxOer) { litOer.CssClass = "badOer"; } else { litOer.CssClass = "goodOer"; } pnlError.Visible = false; } catch { pnlError.Visible = true; } }
protected void btnDisplayTotals_Click(object sender, EventArgs e) { try { decimal revenue = decimal.Parse(txtRevenue.Text); decimal expenses = decimal.Parse(txtExpenses.Text); IAccountingCalculator calculator = new AccountingCalculator(); decimal net = calculator.CalculateNet(revenue, expenses); litNet.Text = net.ToString("C"); pnlError.Visible = false; } catch { pnlError.Visible = true; } }
static void Main(string[] args) { decimal?revenue = null; decimal?expenses = null; if (args.Length == 2) { decimal r, e; revenue = decimal.TryParse(args[0], out r) ? (decimal?)r : null; expenses = decimal.TryParse(args[1], out e) ? (decimal?)e : null; } if (revenue == null || expenses == null) { revenue = PromptDecimal("Enter revenue: "); expenses = PromptDecimal("Enter expenses: "); } var calculator = new AccountingCalculator(); decimal profit = calculator.CalculateNet(revenue.Value, expenses.Value); System.Console.WriteLine("Profit: " + profit.ToString("C2")); }
public void NegativeExpenses() { IAccountingCalculator calc = new AccountingCalculator(); decimal net = calc.CalculateNet(1000m, -1000m); }
public void NegativeRevenue() { IAccountingCalculator calc = new AccountingCalculator(); decimal net = calc.CalculateNet(-1000m, 1000m); }