private static IList <PayrunInvoice> CreatePayRunInvoices(Payrun payrun, IList <Invoice> invoices, bool hasHeldInvoices, bool hasReleasedInvoices) { if (!hasHeldInvoices && !hasReleasedInvoices) { return(invoices.Select(invoice => TestDataHelper.CreatePayrunInvoice(payrun.Id, invoice)).ToList()); } var payrunInvoices = new List <PayrunInvoice>(); var half = invoices.Count / 2; if (hasHeldInvoices) { payrunInvoices.AddRange(invoices.GetPage(1, half).ToList() .Select(invoice => TestDataHelper.CreatePayrunInvoice(payrun.Id, invoice, InvoiceStatus.Held))); } if (hasReleasedInvoices) { payrunInvoices.AddRange(invoices.GetPage(1, half).ToList() .Select(invoice => TestDataHelper.CreatePayrunInvoice(payrun.Id, invoice, InvoiceStatus.Released))); } payrunInvoices.AddRange(invoices.GetPage(2, half).ToList() .Select(invoice => TestDataHelper.CreatePayrunInvoice(payrun.Id, invoice))); return(payrunInvoices); }