public virtual List<MemberwiseContribution> Generate(Group group) { List<MemberwiseContribution> contributions = new List<MemberwiseContribution>(); int memberCount = group.MemberCount; if (memberCount == 0) { throw new InvalidOperationException("No member added so far."); } float totalExpense = GetTotalExpense(group); float perHeadExpense = totalExpense / memberCount; foreach (Member member in group.GetAllMembers()) { float memberContribution = GetTotalAmountForMember(member); MemberwiseContribution contribution = new MemberwiseContribution(); contribution.Member = member; contribution.Amount = memberContribution - perHeadExpense; contributions.Add(contribution); } return contributions; }
public void AddGroup(Group group) { groupCount++; group.Id = groupCount; groups.Add(groupCount, group); }
public void Execute() { IRepository repo = new InMemoryRepository(); //Validate group prior to adding Validate(repo); Group group = repo.GetGroupByName(friendlyName); group = new Group(friendlyName); repo.AddGroup(group); }
public void when_new_member_added() { string frinedlyName = "newGroup"; string firstName = "newMember"; string lastName = "newMemberLastName"; string emailAddress = "*****@*****.**"; Group newGroup = new Group(frinedlyName); Member newMember = new Member(firstName, lastName, emailAddress); newGroup.AddMember(newMember); }
protected override float GetTotalExpense(Group group) { return group.GetAllExpenses().Where(e => e.CreateOn.Year == year).Sum(e => e.Amount); }
protected abstract float GetTotalExpense(Group group);
protected override float GetTotalExpense(Group group) { return group.GetAllExpenses().Sum(e => e.Amount); }
public void when_group_name_whitespace_throw_exception() { string frinedlyName = " "; Group newGroup = new Group(frinedlyName); }