コード例 #1
0
        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;
        }
コード例 #2
0
        public void AddGroup(Group group)
        {
            groupCount++;
            group.Id = groupCount;

            groups.Add(groupCount, group);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 protected override float GetTotalExpense(Group group)
 {
     return group.GetAllExpenses().Where(e => e.CreateOn.Year == year).Sum(e => e.Amount);
 }
コード例 #6
0
 protected abstract float GetTotalExpense(Group group);
コード例 #7
0
 protected override float GetTotalExpense(Group group)
 {
     return group.GetAllExpenses().Sum(e => e.Amount);
 }
コード例 #8
0
 public void when_group_name_whitespace_throw_exception()
 {
     string frinedlyName = "  ";
     Group newGroup = new Group(frinedlyName);
 }