public void GetDistinctPreviousMonths_FetchFiveMonthsPrevious_FromFebruary() { var fakeCurrentTime = new Mock<ICurrentTime>(); fakeCurrentTime.Setup(x => x.GetCurrentTime()).Returns(() => new DateTime(2013, 2, 1)); var sut = new DistinctMonthHelper(fakeCurrentTime.Object); List<DateTime> months = sut.GetDistinctPreviousMonths(new DateTime(2013, 2, 1), 5); string[] expected = { "January", "December", "November", "October", "September" }; IEnumerable<string> actual = months.Select(x => x.ToLongDateString().Split(' ').ElementAt(1)); CollectionAssert.AreEqual(expected, actual); }
public void GetDistinctPreviousMonths_FetchFiveMonthsPrevious_FromAugust() { var fakeCurrentTime = new Mock<ICurrentTime>(); fakeCurrentTime.Setup(x => x.GetCurrentTime()).Returns(() => new DateTime(2013, 8, 1)); var sut = new DistinctMonthHelper(fakeCurrentTime.Object); List<DateTime> months = sut.GetDistinctPreviousMonths(new DateTime(2013, 8, 1), 5); string[] expected = { "July", "June", "May", "April", "March" }; IEnumerable<string> actual = months.Select(x => x.ToLongDateString().Split(' ').ElementAt(1)); CollectionAssert.AreEqual(expected, actual); }
public void GetDistinctMonths_FetchFiveMonthsPrevious_WithOverlappingYears() { var fakeCurrentTime = new Mock<ICurrentTime>(); fakeCurrentTime.Setup(x => x.GetCurrentTime()).Returns(() => new DateTime(2013, 12, 1)); var sut = new DistinctMonthHelper(fakeCurrentTime.Object); List<DateTime> months = sut.GetDistinctPreviousMonths(new DateTime(2013, 3, 1), 5); int[] expected = { 2013, 2013, 2012, 2012, 2012 }; IEnumerable<int> actual = months.Select(x => x.Year); CollectionAssert.AreEqual(expected, actual); }
public void GetDistinctPreviousMonths_SetMonthsRequiredParamTo1_IfAZeroValueIsGiven() { var dateTime = new DateTime(2013, 8, 4); var fakeCurrentTime = new Mock<ICurrentTime>(); fakeCurrentTime.Setup(x => x.GetCurrentTime()).Returns(dateTime); var sut = new DistinctMonthHelper(fakeCurrentTime.Object); List<DateTime> result = sut.GetDistinctPreviousMonths(dateTime, 0); Assert.AreEqual(1, result.Count); }
public void GetDistinctPreviousMonths_SetDateParamToCurrentTime_IfItIsGreaterThanCurrentTime() { var dateTime = new DateTime(2014, 8, 4); var fakeCurrentTime = new Mock<ICurrentTime>(); fakeCurrentTime.Setup(x => x.GetCurrentTime()).Returns(() => new DateTime(2013, 8, 4)); var sut = new DistinctMonthHelper(fakeCurrentTime.Object); List<DateTime> result = sut.GetDistinctPreviousMonths(dateTime, 5); Assert.AreEqual(7, result[0].Month); Assert.AreEqual(2013, result[0].Year); }
public void GetDistinctPreviousMonths_ReturnTheMonthCount_AsSpecifiedByMonthsRequiredParam() { var dateTime = new DateTime(2013, 8, 4); var fakeCurrentTime = new Mock<ICurrentTime>(); fakeCurrentTime.Setup(x => x.GetCurrentTime()).Returns(dateTime); var sut = new DistinctMonthHelper(fakeCurrentTime.Object); List<DateTime> result = sut.GetDistinctPreviousMonths(dateTime, 10); Assert.AreEqual(10, result.Count); }