public void Init()
 {
     _helper = this.GetFixture().Create<IValidationHelper>();
     _localization = TestHelper.CreateStubLocalization();
     _sut = new TierFormFieldSheetShouldHaveCorrectFieldFormMapping(_helper, _localization);
     _loader = this.GetFixture().Create<IExcelLoader>();
 }
 private void StubTierFormFieldSheetData(IExcelLoader loader, string formOid, string fieldOid)
 {
     loader.Stub(x => x.Sheet<TierFormField>())
           .Return(this.GetFixture().Create<ISheetInfo<TierFormField>>());
     var items = new[] { new TierFormField { FormOid = formOid, FieldOid = fieldOid } }.ToList();
     loader.Sheet<TierFormField>().Stub(x => x.Data).Return(items);
 }
 private void StubCustomTierSheetData(IExcelLoader loader, params string[] tierNames)
 {
     loader.Stub(x => x.Sheet<CustomTier>())
           .Return(this.GetFixture().Create<ISheetInfo<CustomTier>>());
     var items = tierNames.Select(x => new CustomTier {TierName = x}).ToList();
     loader.Sheet<CustomTier>().Stub(x => x.Data).Return(items);
 }
 public void Init()
 {
     _helper = this.GetFixture().Create<IValidationHelper>();
     _localization = TestHelper.CreateStubLocalization();
     _sut = new TierFormFolderSheetShouldHaveAllFoldersExisting(_helper, _localization);
     _loader = this.GetFixture().Create<IExcelLoader>();
 }
        public IValidationResult Validate(IExcelLoader excelLoader, IDictionary<string, object> context)
        {
            if (excelLoader == null) throw new ArgumentNullException("excelLoader");

            var messages = new List<IValidationMessage>();
            var result = new ValidationResult {ValidationTarget = excelLoader, Messages = messages };
            var contextDic = context ?? new Dictionary<string, object>();

            try
            {
                foreach (var ruleResult in _rules.Select(r => r.Check(excelLoader, contextDic)))
                {
                    messages.AddRange(ruleResult.Messages);
                    if (_earlyExit && !ruleResult.ShouldContinue)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                var error = e.ToString().ToValidationError();
                messages.Add(error);
            }

            return result;
        }
 private void StubTierFormFieldSheetData(IExcelLoader loader, params string[] tierNames)
 {
     loader.Stub(x => x.Sheet<TierFormField>())
           .Return(this.GetFixture().Create<ISheetInfo<TierFormField>>());
     var items = tierNames.Select(x => new TierFormField {TierName = x}).ToList();
     loader.Sheet<TierFormField>().Stub(x => x.Data).Return(items);
 }
        public IValidationResult Validate(IExcelLoader excelLoader)
        {
            if (excelLoader == null) throw new ArgumentNullException("excelLoader");

            var result = new ValidationResult {ValidationTarget = excelLoader};

            try
            {
                foreach (var ruleResult in _rules.Select(r => r.Check(excelLoader)))
                {
                    result.Messages.AddRange(ruleResult.Messages);
                    if (!ruleResult.ShouldContinue)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                var error = e.ToString().ToValidationError();
                result.Messages.Add(error);
            }

            return result;
        }
        public void Init()
        {
            var localization = TestHelper.CreateStubLocalization();
            _sut = new BlockPlanSettingSheetShouldHaveCustomTierNamesDefinedInCustomTierSheet(localization);
            _loader = this.GetFixture().Create<IExcelLoader>();

            StubCustomTierSheetData(_loader);
        }
 private void StubTierFormFolderSheetData(IExcelLoader loader, params string[] folderOids)
 {
     loader.Stub(x => x.Sheet<TierFormFolder>())
           .Return(this.GetFixture().Create<ISheetInfo<TierFormFolder>>());
     loader.Sheet<TierFormFolder>().Stub(x => x.Definition).Return(this.GetFixture().Create<ISheetDefinition>());
     var colDefs = folderOids.Select(x => new ColumnDefinition { PropertyName = x, ExtraProperty = true });
     loader.Sheet<TierFormFolder>().Definition.Stub(x => x.ColumnDefinitions).Return(colDefs);
 }
 protected override IEnumerable<IValidationMessage> Validate(IExcelLoader excelLoader,
                                                             IDictionary<string, object> context,
                                                             out bool shouldContinue)
 {
     var namesInCustomTier = excelLoader.Sheet<CustomTier>().Data.Select(x => x.TierName);
     var namesInTierFormFolder = excelLoader.Sheet<TierFormFolder>().Data.Select(x => x.TierName);
     var orphanNames = namesInTierFormFolder.Except(namesInCustomTier).ToArray();
     shouldContinue = orphanNames.Length == 0;
     return
         orphanNames.Select(x => CreateErrorMessage("'{0}' tier in TierForms is not defined in CustomTier.", x));
 }
        protected override IExcelLoader DefineTsdvSheets(TsdvLoaderSupportedVersion version, IExcelLoader loader)
        {
            if (version != TsdvLoaderSupportedVersion.V1) return base.DefineTsdvSheets(version, loader);

            loader.Sheet<BlockPlanSetting>().Definition.HeaderRowCount = 1;
            loader.Sheet<CustomTier>().Definition.HeaderRowCount = 1;
            loader.Sheet<TierFormField>().Definition.HeaderRowCount = 1;
            loader.Sheet<TierFormFolder>().Definition.HeaderRowCount = 1;
            loader.Sheet<Rule>().Definition.HeaderRowCount = 1;
            return loader;
        }
 private IExcelLoader DefineTsdvSheets(IExcelLoader loader)
 {
     loader.Sheet<BlockPlan>();
     loader.Sheet<BlockPlanSetting>();
     loader.Sheet<CustomTier>();
     loader.Sheet<TierField>();
     loader.Sheet<TierForm>();
     loader.Sheet<TierFolder>();
     loader.Sheet<ExcludedStatus>();
     loader.Sheet<Rule>();
     return loader;
 }
 protected override IEnumerable<IValidationMessage> Validate(IExcelLoader excelLoader,
                                                             IDictionary<string, object> context,
                                                             out bool shouldContinue)
 {
     var messages = (from tierField in excelLoader.Sheet<TierFormField>().Data
                     let formOid = tierField.FormOid
                     let fieldOid = tierField.FieldOid
                     where !_helper.ExistsFormField(formOid, fieldOid, context)
                     select CreateErrorMessage("Cannot find field OID '{0}' in form '{1}'.", fieldOid, formOid))
         .ToArray();
     shouldContinue = messages.Length == 0;
     return messages;
 }
        public IValidationResult Validate(IExcelLoader excelLoader, IDictionary<string, object> context)
        {
            if (excelLoader == null) throw new ArgumentNullException("excelLoader");

            var messages = new ConcurrentBag<IValidationMessage>();
            var result = new ValidationResult {ValidationTarget = excelLoader, Messages = messages };
            var contextDic = context ?? new Dictionary<string, object>();

            try
            {
                using (var cts = new CancellationTokenSource())
                {
                    _rules.AsParallel()
                          .WithCancellation(cts.Token)
                          .ForAll(r =>
                          {
                              var ruleResult = r.Check(excelLoader, contextDic);
                              foreach (var msg in ruleResult.Messages)
                              {
                                  messages.Add(msg);
                              }
                              if (_earlyExit && !ruleResult.ShouldContinue)
                              {
                                  cts.Cancel();
                              }
                          });
                }
            }
            catch (AggregateException ex)
            {
                var errors = ex.Flatten()
                               .InnerExceptions
                               .Select(x => x.ToString().ToValidationError());
                foreach (var error in errors)
                {
                    messages.Add(error);
                }
            }
            catch (OperationCanceledException)
            {
                // Intentionally swallow this exception.
            }

            catch (Exception ex)
            {
                var error = ex.ToString().ToValidationError();
                messages.Add(error);
            }

            return result;
        }
        protected override IEnumerable<IValidationMessage> Validate(IExcelLoader excelLoader,
                                                                    IDictionary<string, object> context,
                                                                    out bool shouldContinue)
        {
            var messages = (from tierFolder in excelLoader.Sheet<TierFormFolder>().Definition.ColumnDefinitions
                            where tierFolder.ExtraProperty
                            let folderOid = tierFolder.PropertyName
                            where !_helper.ExistsFolderOid(folderOid, context)
                            select CreateErrorMessage("Cannot find folder OID '{0}'.", folderOid))
                .ToArray();

            shouldContinue = messages.Length == 0;
            return messages;
        }
        protected virtual IExcelLoader DefineTsdvSheets(TsdvLoaderSupportedVersion version, IExcelLoader loader)
        {
            if(version != TsdvLoaderSupportedVersion.Presentation)
                throw new NotSupportedException(string.Format("'{0}' isn't a supported name", version));

            loader.Sheet<BlockPlan>().Definition.HeaderRowCount = 1;
            loader.Sheet<BlockPlanSetting>().Definition.HeaderRowCount = 1;
            loader.Sheet<CustomTier>().Definition.HeaderRowCount = 1;
            loader.Sheet<TierField>().Definition.HeaderRowCount = 1;
            loader.Sheet<TierForm>().Definition.HeaderRowCount = 1;
            loader.Sheet<TierFolder>().Definition.HeaderRowCount = 1;
            loader.Sheet<ExcludedStatus>().Definition.HeaderRowCount = 1;
            loader.Sheet<Rule>().Definition.HeaderRowCount = 1;
            return loader;
        }
 protected override IEnumerable<IValidationMessage> Validate(IExcelLoader excelLoader,
                                                             IDictionary<string, object> context,
                                                             out bool shouldContinue)
 {
     var tierNamesInBlockPlanSettings = excelLoader.Sheet<BlockPlanSetting>()
                                                   .Definition
                                                   .ColumnDefinitions
                                                   .Where(x => x.ExtraProperty)
                                                   .Select(x => x.PropertyName);
     var tierNamesInCustomTiers = excelLoader.Sheet<CustomTier>()
                                             .Data
                                             .Select(x => x.TierName);
     var badTierNames = tierNamesInBlockPlanSettings.Except(DefaultTiers)
                                                    .Except(tierNamesInCustomTiers);
     var messages = badTierNames.Select(CreateErrorMessage).ToArray();
     shouldContinue = messages.Length == 0;
     return messages;
 }
        private void StubBlockPlanSettingsExtraColumns(IExcelLoader loader, string extraPropName)
        {
            loader.Stub(x => x.Sheet<BlockPlanSetting>())
                  .Return(this.GetFixture().Create<ISheetInfo<BlockPlanSetting>>());
            loader.Sheet<BlockPlanSetting>()
                  .Stub(x => x.Definition)
                  .Return(this.GetFixture().Create<ISheetDefinition>());

            var colDefs = new[]
                          {
                              new ColumnDefinition {ExtraProperty = false, PropertyName = "Col1"},
                              new ColumnDefinition {ExtraProperty = false, PropertyName = "Col2"},
                              new ColumnDefinition {ExtraProperty = true, PropertyName = extraPropName}
                          };
            loader.Sheet<BlockPlanSetting>()
                  .Definition
                  .Stub(x => x.ColumnDefinitions)
                  .Return(colDefs);
        }
        private void StubCustomTierSheetData(IExcelLoader loader)
        {
            loader.Stub(x => x.Sheet<CustomTier>())
                  .Return(this.GetFixture().Create<ISheetInfo<CustomTier>>());

            var customDatas = new[]
                              {
                                  new CustomTier
                                  {
                                      TierName = "CustomTier1",
                                      TierDescription = this.GetFixture().Create<string>()
                                  },
                                  new CustomTier
                                  {
                                      TierName = "CustomTier2",
                                      TierDescription = this.GetFixture().Create<string>()
                                  }
                              };
            loader.Sheet<CustomTier>().Stub(x => x.Data).Return(customDatas);
        }
        protected override IEnumerable<IValidationMessage> Validate(IExcelLoader excelLoader,
                                                                    IDictionary<string, object> context,
                                                                    out bool shouldContinue)
        {
            var messages = new List<IValidationMessage>();
            foreach (var blockPlanSetting in excelLoader.Sheet<BlockPlanSetting>().Data)
            {
                if (blockPlanSetting.BlockSubjectCount == 0)
                {
                    var message = CreateErrorMessage("tsdv_BlockSizeZeroError", blockPlanSetting.Block);
                    messages.Add(message);
                }
                else if (TotalTierCountMismatched(blockPlanSetting))
                {
                    var message = CreateErrorMessage("tsdv_BlockValidationError", blockPlanSetting.Block);
                    messages.Add(message);
                }
            }

            shouldContinue = messages.Count == 0;
            return messages;
        }
 protected internal abstract IEnumerable<IValidationMessage> Validate(IExcelLoader excelLoader, IDictionary<string, object> context, out bool shouldContinue);
예제 #22
0
 public ExcelPipeline(IExcelLoader loader, ITableExporter tableExporter)
 {
     this.loader        = loader;
     this.tableExporter = tableExporter;
 }
 public void Init()
 {
     var localization = TestHelper.CreateStubLocalization();
     _sut = new TierFormFieldSheetShouldHaveAllTierNamesDefinedInCustomTierSheet(localization);
     _loader = this.GetFixture().Create<IExcelLoader>();
 }
 public void Init()
 {
     var localization = TestHelper.CreateStubLocalization();
     _sut = new BlockPlanSettingSheetShouldHaveMatchedBlockSubjectCount(localization);
     _loader = this.GetFixture().Create<IExcelLoader>();
 }
 public virtual IValidationRuleResult Check(IExcelLoader excelLoader, IDictionary<string, object> context)
 {
     bool shouldContinue;
     var messages = Validate(excelLoader, context, out shouldContinue);
     return new ValidationRuleResult {Messages = messages, ShouldContinue = shouldContinue};
 }