public void Profits_Empty_Returns_Statement_With_Expected_Null_Object_Pattern_Values() { var empty = ProfitAndLossStatement.Empty(); Assert.IsNotNull(empty); Assert.AreEqual(empty.Denomination.Code, "GBP"); Assert.AreEqual(empty.Costs.Value, 0); Assert.AreEqual(empty.Costs.Currency.Code, "GBP"); Assert.AreEqual(empty.Revenue.Value, 0); Assert.AreEqual(empty.Revenue.Currency.Code, "GBP"); }
public void Profits_Returns_Revenue_Minus_Costs(decimal revenue, decimal costs, decimal expectedResult) { var currency = new Currency("GBP"); var revenueMoney = new Money(revenue, currency); var costMoney = new Money(costs, currency); var statement = new ProfitAndLossStatement(currency, revenueMoney, costMoney); var profits = statement.Profits(); Assert.IsNotNull(profits); Assert.AreEqual(profits.Currency, currency); Assert.AreEqual(profits.Value, expectedResult); }
public void Profits_Returns_Revenue_Minus_Costs_Percentages( decimal revenue, decimal costs, decimal?expectedResult) { var currency = new Currency("GBP"); var revenueMoney = new Money(revenue, currency); var costMoney = new Money(costs, currency); var statement = new ProfitAndLossStatement(currency, revenueMoney, costMoney); var profits = statement.PercentageProfits(); Assert.AreEqual(profits.HasValue, expectedResult.HasValue); if (expectedResult.HasValue) { Assert.AreEqual(profits.Value, expectedResult); } }
/// <summary> /// Beware some of the titles have leading spaces so if Xero fixes them the method will break. /// </summary> /// <param name="repo"></param> /// <returns></returns> private ProfitAndLossStatement ExtractProfitAndLossStatement(Repository repo) { //Can add a date here in declaration var report = new XeroApi.Model.Reporting.ProfitAndLossReport(); var profitAndLossReport = repo.Reports.RunDynamicReport(report); var sectionRows = profitAndLossReport.Rows.Where(r => r.RowType == "Section"); //Income var operatingIncomeEntries = ExtractPLSectionData(sectionRows.First(r => r.Title == " Income"), ProfitAndLossType.Income); var nonOperatingIncome = ExtractPLSectionData(sectionRows.First(r => r.Title == " Non-operating Income"), ProfitAndLossType.OtherIncome); //Leading space in title //Expenses var costOfSalesEntries = ExtractPLSectionData(sectionRows.First(r => r.Title == " Less Cost Of Sales"), ProfitAndLossType.CostOfSales); var operatingExpenseEntries = ExtractPLSectionData(sectionRows.First(r => r.Title == " Less Operating Expenses"), ProfitAndLossType.Expense); var latestProfitAndLossStatement = new ProfitAndLossStatement(); latestProfitAndLossStatement.ProfitAndLossStatementEntries = new List<ProfitAndLossStatementEntry>(); latestProfitAndLossStatement.ProfitAndLossStatementEntries.AddRange(operatingIncomeEntries); latestProfitAndLossStatement.ProfitAndLossStatementEntries.AddRange(nonOperatingIncome); latestProfitAndLossStatement.ProfitAndLossStatementEntries.AddRange(costOfSalesEntries); latestProfitAndLossStatement.ProfitAndLossStatementEntries.AddRange(operatingExpenseEntries); return latestProfitAndLossStatement; }