public void ThenInSubscriptionsTableBillingAmountsAreCorrect() { var imis = Context <IMIS>(IMIS); var pc = Ctx.PrimaryContact; var coId = imis.NamesByCompanyAndUser(pc.CompanyName, pc.FirstName, pc.LastName).First().CO_ID; Console.WriteLine($"CO_ID={coId}"); int expectedCount; if (Ctx.NewAccount) { expectedCount = 2; } else { var cm = imis.NamesByCoId(coId).Where(o => o.MEMBER_TYPE == "CM").First(); var multiplier = cm.PAID_THRU.Month == DateTime.Now.Month ? 2 : 3; expectedCount = multiplier * Ctx.Capacities.Count(); } var subs = PollUtils.Poll <IEnumerable <Subscription> >( $"Querying subscriptions table for CO_ID={coId}", DB_TIMEOUT, DB_INTERVAL, () => imis.SubscriptionsForCompany(coId), x => { var list = x.Where(o => o.DATE_ADDED >= ImisStartTime); if (!Ctx.NewAccount) { list = list.Where(o => o.PRODUCT_CODE != "PC_AN_CAP"); } return(list.Count() == expectedCount); } ).Where(o => o.DATE_ADDED >= ImisStartTime); var(fee1, fee2, fee3) = Ctx.BillingAmounts(); subs.Where(o => o.PRODUCT_CODE == "PC_AN_CAP" || o.PRODUCT_CODE == "PC_AN_CAP_A") .Select(o => o.BILL_AMOUNT) .Sum() .ShouldBeInRange(fee1 - 0.1, fee1 + 0.1); subs.Where(o => o.PRODUCT_CODE == "PC_AN_CAP1" || o.PRODUCT_CODE == "PC_AN_CAP_A1") .Select(o => o.BILL_AMOUNT) .Sum() .ShouldBeInRange(fee2 - 0.1, fee2 + 0.1); subs.Where(o => o.PRODUCT_CODE == "PC_AN_CAP_A2") .Select(o => o.BILL_AMOUNT) .Sum() .ShouldBeInRange(fee3 - 0.1, fee3 + 0.1); }