public void GetReport_Returns_5_Elements_For_5_Input() { string skill1 = "C#"; string skill2 = "JavaScript"; string skill3 = "C"; DateTime date1 = new DateTime(year: 2016, month: 2, day: 8); IQueryable<CandidateInformation> _CandidateInfoColl = new List<CandidateInformation>() { new CandidateInformation() { SkillSet = skill1, SavedOn = date1 }, new CandidateInformation() { SkillSet = skill1, SavedOn = date1 }, new CandidateInformation() { SkillSet = skill2, SavedOn = date1 }, new CandidateInformation() { SkillSet = skill3, SavedOn = date1 }, new CandidateInformation() { SkillSet = skill3, SavedOn = date1 }, }.AsQueryable(); DateTime reportDate = date1; IRepository<CandidateInformation> mockCandidateInfoRepository = MockRepository.GenerateMock<IRepository<CandidateInformation>>(); mockCandidateInfoRepository.Stub(x => x.Find(Arg<Expression<Func<CandidateInformation, bool>>>.Is.Anything)).Return(_CandidateInfoColl); IReportGenerator reportGenerator = new ReportGenerator(reportDate, mockCandidateInfoRepository); IEnumerable<string> actualOutput = reportGenerator.GetReport(); IEnumerable<string> expectedOutput = _CandidateInfoColl.GroupBy(x => x.SkillSet) .OrderBy(x => x.Key) .Select(x => string.Format("{0},{1}", x.Key, x.Count())); mockCandidateInfoRepository.AssertWasCalled(x => x.Find(Arg<Expression<Func<CandidateInformation, bool>>>.Is.Anything)); Assert.AreEqual(expectedOutput.Count() + 1, actualOutput.Count()); //Added 1 to compensate for the header row. foreach (string expectedString in expectedOutput) { Assert.IsTrue(actualOutput.Contains(expectedString)); } }
public void GetReport_DLIsInvoked() { DateTime date1 = new DateTime(year: 2016, month: 2, day: 8); IQueryable<CandidateInformation> _CandidateInfoColl = new List<CandidateInformation>().AsQueryable(); DateTime reportDate = date1; IRepository<CandidateInformation> mockCandidateInfoRepository = MockRepository.GenerateMock<IRepository<CandidateInformation>>(); mockCandidateInfoRepository.Stub(x => x.Find(Arg<Expression<Func<CandidateInformation, bool>>>.Is.Anything)).Return(_CandidateInfoColl); IReportGenerator reportGenerator = new ReportGenerator(reportDate, mockCandidateInfoRepository); IEnumerable<string> actualOutput = reportGenerator.GetReport(); mockCandidateInfoRepository.AssertWasCalled(x => x.Find(Arg<Expression<Func<CandidateInformation, bool>>>.Is.Anything)); }