public void TestBadgeProgress()
{
using (_trans)
{
InitializeBadges();
Log("Fetching Steps badge");
BadgeManager.UpdateBadge(_id, Statistic.Steps);
Badge badge = BadgeDAO.GetBadgeFromUserIdAndStatistic(_id, Statistic.Steps);
Log("Verifying progress.");
Assert.AreEqual(0, badge.Progress);
Log("Updating statistic to halfway to the Bronze badge.");
StatisticManager.SetUserStatistic(_id, Statistic.Steps,
BadgeConstants.Steps.REQUIREMENTS[BadgeLevels.Bronze] / 2);
BadgeManager.UpdateBadge(_id, Statistic.Steps);
badge = BadgeDAO.GetBadgeFromUserIdAndStatistic(_id, Statistic.Steps);
Log("Verifying progress.");
Assert.AreEqual(50, badge.Progress);
float delta = BadgeConstants.Steps.REQUIREMENTS[BadgeLevels.Silver] -
BadgeConstants.Steps.REQUIREMENTS[BadgeLevels.Bronze];
Log("Updating statistic to halfway to the Silver badge.");
StatisticManager.SetUserStatistic(_id, Statistic.Steps,
BadgeConstants.Steps.REQUIREMENTS[BadgeLevels.Bronze] + (delta / 2));
BadgeManager.UpdateBadge(_id, Statistic.Steps);
badge = BadgeDAO.GetBadgeFromUserIdAndStatistic(_id, Statistic.Steps);
Log("Verifying progress.");
Assert.AreEqual(50, badge.Progress);
Log("Updating statistic to exactly get the Silver badge.");
StatisticManager.SetUserStatistic(_id, Statistic.Steps,
BadgeConstants.Steps.REQUIREMENTS[BadgeLevels.Silver]);
BadgeManager.UpdateBadge(_id, Statistic.Steps);
badge = BadgeDAO.GetBadgeFromUserIdAndStatistic(_id, Statistic.Steps);
Log("Verifying progress.");
Assert.AreEqual(0, badge.Progress);
}
}