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)); }
static void Main(string[] args) { Console.WriteLine("Starting the service"); List<Task> allTasks = new List<Task>(); DateTime reportDate = DateTime.Today.AddDays(-1); string reportFileFullName = string.Format(@"{0}\{1}.txt", ConfigReader.ReadFromApplicationConfiguration("ReportBaseLocation"), reportDate.ToString("yyyyMMdd")); string hostName = ConfigReader.ReadFromApplicationConfiguration("HostName"); int port = Convert.ToInt32(ConfigReader.ReadFromApplicationConfiguration("Port")); string networkUsername = ConfigReader.ReadFromApplicationConfiguration("NetworkUsername"); string networkPassword = ConfigReader.ReadFromApplicationConfiguration("NetworkPassword"); string fromMailId = ConfigReader.ReadFromApplicationConfiguration("FromMailId"); string[] allEmailRecipients = ConfigReader.ReadFromApplicationConfiguration("EmailRecipients").Split(';'); string mailBody = string.Format(_mailBody, reportDate.ToShortDateString(), reportFileFullName); using (DbContext candidateInfoDbContext = new DL.DataStore(ConfigReader.GetConnectionString("DefaultConnection"))) { IRepository<CandidateInformation> candidateInfoRepo = new DL.CandidateInformationRepository(candidateInfoDbContext); IReportGenerator reportGenerator = new ReportGenerator(reportDate, candidateInfoRepo); IReportWriter reportFileWriter = new ReportFileWriter(reportFileFullName, reportGenerator); allTasks.Add(reportFileWriter.WriteAsync()); ISmtpClientBuilder smtpClientBuilder = new SmtpClientBuilder(hostName, port, new System.Net.NetworkCredential(networkUsername, networkPassword), enableSsl: true); IMailMessageBuilder mailMessageBuilder = new MailMessageBuilder(fromMailId, allEmailRecipients, "Report generated", mailBody); INotifier mailNotifier = new EmailNotifier(smtpClientBuilder, mailMessageBuilder); allTasks.Add(mailNotifier.SendAsync()); try { Task.WaitAll(allTasks.ToArray()); } catch (AggregateException aEx) { foreach (var e in aEx.InnerExceptions) { Console.WriteLine(e.ToString()); } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } } Console.WriteLine("Completed the service."); }