コード例 #1
0
        public void InputFile_NotExcelFile_Throws()
        {
            var options = new Options {InputPath = @"C:\TestDir\TestFile.pdf", OutputPath = @"C:\TestDir\TestFile.txt"};
              var validator = new OptionsValidator();
              Action act = () => validator.ValidateAndThrow(options);

              act.ShouldThrow<ValidationException>().WithMessage("*not Excel*");
        }
コード例 #2
0
        public void TestPickyAllPropertiesAssigned()
        {
            var options = new PickyOptions()
            {
                Option1AtMostOne = "aa",
                Option2AtMostOne = "bb",

                Option1AtLeastOne = "ab",
                Option2AtLeastOne = "kk",

                Option1ExactlyOne = "eee",
                Option2ExactlyOne = "nnn",

                Option1All = "ttt",
                Option2All = "33fdf",
            };

            var s = OptionsValidator.AnalyzeAssignedOptions(options);

            System.Diagnostics.Debug.WriteLine(s);
            Assert.AreEqual(2, s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Length);
        }
コード例 #3
0
ファイル: StoryManager.cs プロジェクト: Wouyoshi/projects
        /// <summary>The get next problem.</summary>
        /// <param name="storyName">The story name.</param>
        /// <param name="options">The options.</param>
        /// <returns>The <see cref="ReadModel.Problem"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when an argument is null.</exception>
        /// <exception cref="BusinessValidationException">Thrown when arguments do not pass validation.</exception>
        /// <exception cref="ArgumentException">Thrown when the story doesn't exist.</exception>
        public Problem GetNextProblem(string storyName, IList<int> options)
        {
            if (string.IsNullOrWhiteSpace(storyName))
            {
                throw new ArgumentNullException("storyName");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Check basic options validity.
            var optionsValidator = new OptionsValidator();
            ValidationResults optionsValidationResults = optionsValidator.Validate(options);
            if (!optionsValidationResults.IsValid)
            {
                throw new BusinessValidationException(optionsValidationResults);
            }

            // Get the story.
            Model.Story story = this.storyRepository.GetStoryByName(storyName);

            if (story == null)
            {
                throw new ArgumentException(string.Format("The story {0} doesn't exist.", storyName));
            }

            var optionsStoryValidator = new OptionsStoryValidator(story);
            ValidationResults optionsStoryvalidationResults = optionsStoryValidator.Validate(options);
            if (!optionsStoryvalidationResults.IsValid)
            {
                throw new BusinessValidationException(optionsStoryvalidationResults);
            }

            Model.Problem firstProblem = story.Steps.First(step => step.Number == 1).Problems.First();
            Problem problem = this.GetProblem(firstProblem, options, 0);
            return problem;
        }
コード例 #4
0
 /// <summary>
 /// Method for validating content of object.
 /// </summary>
 public override void ValidateAndThrow()
 {
     OptionsValidator.ValidateAndThrow(this);
 }
コード例 #5
0
        static void Main(string[] args)
        {
            var options = new Options();

              var extractor = Container.GetInstance<IExtractor<KitLabel>>();
              var settings = Container.GetInstance<ISettingsService>();

              var jobValidator = new JobValidator(settings);
              var columnMapValidator = new ColumnMapValidator();
              var optionsValidator = new OptionsValidator();
              var kitLabels = new List<KitLabel>();
              Job job;

              CommandLine.Parser.Default.ParseArguments(args, options);

              try {
            optionsValidator.ValidateAndThrow(options);

            extractor.Initialize(options.InputPath);
            var columnMap = extractor.GetColumnMap(settings, 1, 1);

            columnMapValidator.ValidateAndThrow(columnMap);

            kitLabels.AddRange(extractor.Extract(columnMap, 1, 2));
            job = new Job(settings.OutputHeaderString, kitLabels);

            jobValidator.ValidateAndThrow(job);
              }

              catch (ValidationException exc) {
            var messages = string.Join("; ", exc.Errors.Select(e => e.ErrorMessage));
            var messageText = string.Format("** Warning! Input data file validation failed:; {0}", messages);

            kitLabels = new List<KitLabel>
            {
              new KitLabel(69) {Attn = "Data errors detected", Sbu = "Error", KitName = messageText}
            };
              }

              catch (ArgumentOutOfRangeException exception) {
            var message = "** Warning! Excel conversion errors occurred:; ";
            var lookup = new Dictionary<string, string>
            {
              {"sheetIndex", "Unable to find a worksheet from which to extract data"},
              {"startRowIndex", "No kit label rows are present in the data file"}
            };

            string errorText;

            if (lookup.TryGetValue(exception.ParamName, out errorText)) {
              message += errorText;
            }

            kitLabels = new List<KitLabel>
            {
              new KitLabel(69) {Attn = "Range error detected", Sbu = "Error",  KitName = message}
            };
              }

              catch (Exception exc) {
            var message = string.Format("** Warning! Excel conversion errors occurred:; {0}", exc.Message);
            kitLabels = new List<KitLabel>
            {
              new KitLabel(70) {Attn = "Unknown Error detected", Sbu = "Error",  KitName = message}
            };
              }

              finally {
            job = new Job(settings.OutputHeaderString, kitLabels);
            File.WriteAllLines(options.OutputPath, job.GetOutputList(), Encoding.Unicode);
              }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: garmstrong11/ImageRenamer
        static void Main(string[] args)
        {
            var options = new Options();
              var extractor = Container.GetInstance<IExtractor<RenameRow>>();
              var settings = Container.GetInstance<ISettingsService>();

              var optionsValidator = new OptionsValidator();
              var columnMapValidator = new ColumnMapValidator(settings);
              var handlerValidator = new ImageHandlerValidator();
              var existingFiles = new List<FileInfo>();
              var messages = new List<string>();

              Parser.Default.ParseArguments(args, options);

              try {
            optionsValidator.ValidateAndThrow(options);
            var sourceDir = new DirectoryInfo(options.InputPath);

            existingFiles.AddRange(sourceDir.EnumerateFiles("*.*", SearchOption.AllDirectories));

            // Throws InvalidOperationException if not found
            var excelFile = existingFiles.Single(f => Regex.IsMatch(f.Extension, @"\.xlsx?"));
            existingFiles.Remove(excelFile);

            extractor.Initialize(excelFile.FullName);
            var columnMap = extractor.GetColumnMap(settings, settings.SheetIndex, settings.HeaderRowIndex);
            columnMapValidator.ValidateAndThrow(columnMap);
            var rows = extractor.Extract(columnMap, settings.SheetIndex, settings.StartRowIndex);

            var handler = new ImageHandler(options.InputPath, options.OutputPath);
            handler.AddRenameRowRange(rows);
            handler.AddArtFileRange(existingFiles.Select(f => new ArtFile(f)));

            var result = handlerValidator.Validate(handler);
            messages.AddRange(result.Errors.Select(e => e.ErrorMessage).OrderBy(e => e));

            handler.CopyValidFiles();
            handler.Cleanup();
              }

              catch (ValidationException exc) {
            messages.AddRange(exc.Errors.Select(f => f.ErrorMessage));
              }

              catch (FlexCelExtractionException exc) {
            messages.Add(exc.Message);
              }

              catch (InvalidOperationException) {
            messages.Add("Unable to find an Excel file for this group.");
              }

              catch (KeyNotFoundException exc) {
            messages.Add(exc.Message);
              }

              catch (Exception exc) {
            messages.Add(exc.Message);
              }

              finally {
            var outputFilename = Path.Combine(options.OutputPath, settings.OutputReportFileName);
            File.WriteAllLines(outputFilename, messages.OrderBy(p => p));
              }
        }