public void ParserExtractsRuleComponents()
        {
            //Arrange
            var buffer = new OutputBuffer()
            {
                BufferWidth = 133
            };
            var output = new Output(buffer);

            //Act
            var results = TestStrings
                          .Select(s => new { String = s, Result = EntityReferenceParser.Parse(s) })
                          .ToList();

            //Assert
            var report = results.AsReport(rep => rep
                                          .AddColumn(r => r.String, cc => cc.Heading("Input"))
                                          .AddColumn(r => r.Result.Valid, cc => { })
                                          .AddChild(r => new[] { new { r.Result?.Error } }, erep => erep.AddColumn(e => e.Error, cc => { }))
                                          .AddChild(r => new[] { new { Result = r.Result?.EntityReference?.Describe() } },
                                                    drep => drep.AddColumn(e => e.Result ?? "NULL", cc => cc.Heading("Result")))
                                          );

            output.FormatTable(report);
            Approvals.Verify(output.Report);
        }
示例#2
0
        public ValidationFieldAttribute(string fieldName)
        {
            var result = EntityReferenceParser.Parse(fieldName);

            if (!result.Valid)
            {
                throw new EntityReferenceInvalid(result.Error, fieldName);
            }
            Field = result.EntityReference;
        }
示例#3
0
        public FieldAttribute(string fieldName, string rule = null)
        {
            var entityReferenceParseResult = EntityReferenceParser.Parse(fieldName);

            if (!entityReferenceParseResult.Valid)
            {
                throw new Exception($"{EntityReference}: {entityReferenceParseResult.Error}");
            }

            EntityReference = entityReferenceParseResult.EntityReference;

            if (rule != null)
            {
                Rule = ApplyIfParser.Parse(rule);
                if (!Rule.Valid)
                {
                    throw new Exception($"{EntityReference}: {ApplyIfParser.Parse(rule).Error} ({rule})");
                }
                if (Rule.RequireCleanInput || Rule.RequireFirstError)
                {
                    throw new Exception($"{EntityReference}: Only match rules are allowed on fields. ({rule})");
                }
            }
        }