Skip to content

Commit

Permalink
Merge pull request #59 from M-Zuber/Development
Browse files Browse the repository at this point in the history
Some code fixes and such
  • Loading branch information
M-Zuber committed Dec 7, 2015
2 parents b8111b5 + 1c9c005 commit bb7bf26
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
@@ -1,5 +1,6 @@
VirtualGabbai
=============
[![Build status](https://ci.appveyor.com/api/projects/status/xjbccma7a5yar60h/branch/master?svg=true)](https://ci.appveyor.com/project/M-Zuber/virtualgabbai/branch/master)

[![Join the chat at https://gitter.im/M-Zuber/VirtualGabbai](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/M-Zuber/VirtualGabbai?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down
3 changes: 1 addition & 2 deletions VirtGabbai/DataAccess/AccountAccess.cs
Expand Up @@ -324,8 +324,7 @@ internal static Account ConvertSingleDbAccountToLocalType(DataCache.Models.Accou
lastMonthlyPaymentDate = dbTypeAccount.LastMonthlyPaymentDate.Value;
}

int monthlyTotal = 0;
monthlyTotal = dbTypeAccount.MonthlyPaymentTotal;
decimal monthlyTotal = dbTypeAccount.MonthlyPaymentTotal;
//TODO fix
return null;
//return new Account(dbTypeAccount.ID, monthlyTotal, lastMonthlyPaymentDate, accountDonations);
Expand Down
1 change: 1 addition & 0 deletions VirtGabbai/DataCache/Mapping/AccountsMap.cs
Expand Up @@ -19,6 +19,7 @@ public AccountsMap()
Property(t => t.ID).HasColumnName("ID");
Property(t => t.PersonID).HasColumnName("PersonID");
Property(t => t.LastMonthlyPaymentDate).HasColumnName("LastMonthlyPaymentDate");
Property(t => t.MonthlyPaymentAmount).HasColumnName("MonthlyPaymentAmount");

// Relationships
HasRequired(t => t.Person)
Expand Down
29 changes: 16 additions & 13 deletions VirtGabbai/DataCache/Models/Account.cs
Expand Up @@ -9,22 +9,23 @@ public partial class Account
{
public int ID { get; set; }
public int PersonID { get; set; }
public decimal MonthlyPaymentAmount { get; set; }
public DateTime? LastMonthlyPaymentDate { get; set; }
public virtual Person Person { get; set; }
public virtual ICollection<Donation> Donations { get; set; } = new List<Donation>();
public int MonthlyPaymentTotal
public decimal MonthlyPaymentTotal
{
get
{
//TODO help-wanted/first-timers-only make this calculation more accurate.
//TODO null check this thing
var monthesOwedFor = (int)(DateTime.Now - LastMonthlyPaymentDate)?.TotalDays / 30;

return monthesOwedFor * Globals.MONTHLY_PAYMENT_AMOUNT;
return monthesOwedFor * MonthlyPaymentAmount;
}
}
public List<Donation> UnpaidDonations => GetUnpaidDonations(Donations);
public List<Donation> PaidDonations => GetPaidDonations(Donations);
public List<Donation> UnpaidDonations => GetUnpaidDonations();
public List<Donation> PaidDonations => GetPaidDonations();

public override bool Equals(object obj)
{
Expand All @@ -34,10 +35,12 @@ public override bool Equals(object obj)
return false;
}

return ID == o.ID &&
LastMonthlyPaymentDate.Equals(o.LastMonthlyPaymentDate) &&
PersonID == o.PersonID &&
Enumerable.SequenceEqual(Donations, o.Donations);
return ReferenceEquals(this, o) ||
(ID == o.ID &&
LastMonthlyPaymentDate.Equals(o.LastMonthlyPaymentDate) &&
PersonID == o.PersonID &&
MonthlyPaymentAmount == o.MonthlyPaymentAmount &&
Enumerable.SequenceEqual(Donations, o.Donations));
}

public override string ToString()
Expand All @@ -61,18 +64,18 @@ public override string ToString()

// TODO string should represent whether LastMonthlyPaymentDate is null
// TODO string should relect the absence of any donations
//TODO should include information on amount paying every month

return $"Total owed for the monthly payment: \"{MonthlyPaymentTotal}\"\n" +
$"Last month the monthly payment was made: \"{LastMonthlyPaymentDate?.Month}\"\n" +
$"Donations:\n{donations}";
}

public override int GetHashCode() => base.GetHashCode();
// TODO can i use an anon obej to get smae hashcode - try it - test it
// the reason not to use tostring is the complication of it. - also it is prone to change
public override int GetHashCode() => new {ID, MonthlyPaymentAmount, LastMonthlyPaymentDate, PaidDonations, UnpaidDonations, PersonID}.ToString().GetHashCode();

//TODO maybe these should also take into account the DatePaid prop. - does it make a diff if Paid prop becomes calculated?
private static List<Donation> GetUnpaidDonations(IEnumerable<Donation> allDonations) => allDonations.Where(d => !d.Paid).ToList();
private List<Donation> GetUnpaidDonations() => Donations.Where(d => !d.Paid).ToList();

private static List<Donation> GetPaidDonations(IEnumerable<Donation> allDonations) => allDonations.Where(d => d.Paid).ToList();
private List<Donation> GetPaidDonations() => Donations.Where(d => d.Paid).ToList();
}
}
3 changes: 0 additions & 3 deletions VirtGabbai/Framework/Globals.cs
Expand Up @@ -8,8 +8,5 @@ namespace Framework
public static class Globals
{
public const string DELIMITER = ";";

// TODO make this come from config file/db
public const int MONTHLY_PAYMENT_AMOUNT = 50;
}
}
32 changes: 28 additions & 4 deletions VirtGabbai/Unit Tests/DataCache.Tests/AccountTest.cs
Expand Up @@ -52,20 +52,28 @@ public void Account_Equals_Other_Is_Not_Account_Returns_False()
{
Assert.IsFalse(targetAccount.Equals(1));
}

[TestMethod]
public void Account_Equals_Same_Reference()
{
Assert.IsTrue(targetAccount.Equals(targetAccount));
}

/// <summary>
///Comparing two accounts with a difference in the donations list
///</summary>
[TestMethod()]
public void Account_Equals_DifferenceInDonations()
{
List<Donation> otherDonations = new List<Donation>();
otherDonations.AddRange(allDonations);
List<Donation> otherDonations = new List<Donation>(allDonations);
otherDonations.Add(new Donation { ID = 34, Reason = "reason:6", Amount = 12.5, DonationDate = DateTime.Today, Comments = "comment", DatePaid = DateTime.Today, Paid = true });
otherDonations.Add(new Donation { ID = 7, Reason = "reason:7", Amount = 12.5, DonationDate = DateTime.Today, Comments = "comment", DatePaid = DateTime.Today, Paid = true });
otherDonations.Add(new Donation { ID = 56, Reason = "reason:8", Amount = 12.5, DonationDate = DateTime.Today, Comments = "comment", DatePaid = DateTime.Today, Paid = true });

Account otherAccount = new Account { ID = id, LastMonthlyPaymentDate = lastMonthlyPaymentDate, Donations = otherDonations };

Assert.IsFalse(targetAccount.Equals(otherAccount));
Assert.IsFalse(otherAccount.Equals(targetAccount));
}

/// <summary>
Expand All @@ -75,7 +83,9 @@ public void Account_Equals_DifferenceInDonations()
public void Account_Equals_DifferenceInLastMonthlyPayment()
{
Account otherAccount = new Account { ID = id, LastMonthlyPaymentDate = DateTime.MaxValue, Donations = allDonations };

Assert.IsFalse(targetAccount.Equals(otherAccount));
Assert.IsFalse(otherAccount.Equals(targetAccount));
}

/// <summary>
Expand All @@ -96,7 +106,9 @@ public void Account_Equals_DifferenceInMonthlyPaymentTotal()
public void Account_Equals_DifferenceInId()
{
Account otherAccount = new Account { ID = (id * 2), LastMonthlyPaymentDate = lastMonthlyPaymentDate, Donations = allDonations };

Assert.IsFalse(targetAccount.Equals(otherAccount));
Assert.IsFalse(otherAccount.Equals(targetAccount));
}

/// <summary>
Expand All @@ -106,7 +118,9 @@ public void Account_Equals_DifferenceInId()
public void Account_Equals_NoDifferences()
{
Account otherAccount = new Account { ID = id, LastMonthlyPaymentDate = lastMonthlyPaymentDate, Donations = allDonations };

Assert.IsTrue(targetAccount.Equals(otherAccount));
Assert.IsTrue(otherAccount.Equals(targetAccount));
}

/// <summary>
Expand All @@ -115,17 +129,27 @@ public void Account_Equals_NoDifferences()
[TestMethod()]
public void Account_Equals_DifferenceInEveryField()
{
List<Donation> otherDonation = new List<Donation>();
otherDonation.AddRange(allDonations);
List<Donation> otherDonation = new List<Donation>(allDonations);
otherDonation.Add(new Donation { ID = 6, Reason = "reason:6", Amount = 12.5, DonationDate = DateTime.Today, Comments = "comment", DatePaid = DateTime.Today, Paid = true });
otherDonation.Add(new Donation { ID = 7, Reason = "reason:7", Amount = 12.5, DonationDate = DateTime.Today, Comments = "comment", DatePaid = DateTime.Today, Paid = true });
otherDonation.Add(new Donation { ID = 8, Reason = "reason:8", Amount = 12.5, DonationDate = DateTime.Today, Comments = "comment", DatePaid = DateTime.Today, Paid = true });

Account otherAccount = new Account { ID = (id * 2), LastMonthlyPaymentDate = DateTime.MaxValue, Donations = otherDonation };

Assert.IsFalse(targetAccount.Equals(otherAccount));
Assert.IsFalse(otherAccount.Equals(targetAccount));
}

#endregion

[TestMethod]
public void Account_GetHashCode_Same_Properties_Returns_Same_Value()
{
var otherAccount = new Account { ID = id, LastMonthlyPaymentDate = lastMonthlyPaymentDate, Donations = allDonations };

Assert.AreEqual(targetAccount.GetHashCode(), otherAccount.GetHashCode());
}

#region ToString Tests

/// <summary>
Expand Down

0 comments on commit bb7bf26

Please sign in to comment.