public void GeneratePdfDocumentFilename_NullIAttendanceListData_ThrowsArgumentNullException()
        {
            FilenameGenerator fileNameProvider = new FilenameGenerator(Mock.Of <ILocalizedNames>(), Mock.Of <IDateTimeProvider>());

            TestDelegate executeGeneratePdfDocumentFilename = () => fileNameProvider.GeneratePdfDocumentFilename(null);

            Assert.That(executeGeneratePdfDocumentFilename, Throws.ArgumentNullException);
        }
        public void GeneratePdfDocumentFilename_GivenData_ReturnsCorrectFileName(Month month, int year, DateTime dateTime, string expectedResult)
        {
            ILocalizedNames localizedNames = Mock.Of <ILocalizedNames>(l => l.GetMonthName(Month.January) == "January" &&
                                                                       l.GetMonthName(Month.February) == "February" &&
                                                                       l.GetMonthName(Month.March) == "March" &&
                                                                       l.GetMonthName(Month.April) == "April" &&
                                                                       l.GetMonthName(Month.May) == "May" &&
                                                                       l.GetMonthName(Month.June) == "June" &&
                                                                       l.GetMonthName(Month.July) == "July" &&
                                                                       l.GetMonthName(Month.September) == "September" &&
                                                                       l.GetMonthName(Month.October) == "October" &&
                                                                       l.GetMonthName(Month.November) == "November" &&
                                                                       l.GetMonthName(Month.December) == "December");
            IAttendanceListData attendanceListData = Mock.Of <IAttendanceListData>(a => a.Month == month && a.Year == year);
            IDateTimeProvider   dateTimeProvider   = Mock.Of <IDateTimeProvider>(d => d.Now == dateTime);
            FilenameGenerator   fileNameGenerator  = new FilenameGenerator(localizedNames, dateTimeProvider);

            string fileName = fileNameGenerator.GeneratePdfDocumentFilename(attendanceListData);

            Assert.That(fileName, Is.EqualTo(expectedResult));
        }
Exemple #3
0
        private void Generate()
        {
            IList <IPerson> people = GetPeopleList();

            // Generate data
            DaysOffData        daysOff  = new DaysOffData(Year);
            AttendanceListData listData = new AttendanceListData(daysOff, people, Month, Year);

            // Create document generator
            LocalizedNames localizedNames = new LocalizedNames();
            AttendanceListDocumentGenerator documentGenerator = new AttendanceListDocumentGenerator(listData, localizedNames);

            // Set document generator settings
            documentGenerator.EnableColors          = EnableColors;
            documentGenerator.EnableHolidaysTexts   = EnableHolidaysTexts;
            documentGenerator.EnableSundaysTexts    = EnableSundaysTexts;
            documentGenerator.EnableTableStretching = EnableTableStretching;

            // Generate a document
            Document document = documentGenerator.GenerateDocument();

            // Get directory path and filename
            DirectoryProvider directoryProvider = new DirectoryProvider(localizedNames);
            FilenameGenerator filenameGenerator = new FilenameGenerator(localizedNames, _dateTimeProvider);
            string            path     = directoryProvider.GetDocumentsDirectoryPath();
            string            filename = filenameGenerator.GeneratePdfDocumentFilename(listData);

            // Save document
            FileSaver fileSaver = new FileSaver();

            fileSaver.SavePdfDocument(document, path, filename);

            // And open it
            FileOpener fileOpener = new FileOpener();

            fileOpener.OpenFile(path, filename);

            SerializeSettings(directoryProvider, filenameGenerator, fileSaver);
        }