public IValueCheck CreateCheck( CheckDefinition checkDefinition, FieldDefinition fieldDefinition, Func <FormData> formData = null, INZazuTableDataSerializer tableSerializer = null, int rowIdx = -1) { if (checkDefinition == null) { throw new ArgumentNullException(nameof(checkDefinition)); } if (string.IsNullOrWhiteSpace(checkDefinition.Type)) { throw new ArgumentException("check type not specified"); } // lets check if the given validation type is available if (!_registrations.ContainsKey(checkDefinition.Type.ToLower())) { throw new NotSupportedException($"The specified check '{checkDefinition.Type}' is not supported"); } var concrete = _registrations[checkDefinition.Type.ToLower()]; Trace.WriteLine($"Found check for '{checkDefinition.Type.ToLower()}' as ({concrete.FullName})"); // lets use reflection to create an instance var result = (IValueCheck) Activator.CreateInstance(concrete, checkDefinition.Settings, formData, tableSerializer, rowIdx, fieldDefinition); return(result); }
public void Be_Creatable() { var settings = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } }; var sut = new CheckDefinition { Type = "type", Settings = settings }; sut.Type.Should().Be("type"); sut.Settings.Should().BeEquivalentTo(settings); }
public IFormCheck CreateFormCheck(CheckDefinition checkDefinition) { if (checkDefinition == null) { throw new ArgumentNullException(nameof(checkDefinition)); } if (string.IsNullOrWhiteSpace(checkDefinition.Type)) { throw new ArgumentException("form check type not specified"); } switch (checkDefinition.Type) { case "gt": return(new GreaterThanFormCheck(checkDefinition.Settings)); default: throw new NotSupportedException("The specified check is not supported"); } }
public void Create_All_Checks(string type) { var ctx = new ContextFor <CheckFactory>(); var sut = ctx.BuildSut(); var settings = new Dictionary <string, string> { { "Hint", "This is a hint for the error message" }, { "RegEx", "true|false" } }; var checkDefinition = new CheckDefinition { Type = type, Settings = settings }; var definition = new FieldDefinition { Key = "test_string", Type = "string", Checks = new[] { checkDefinition } }; var field = sut.CreateCheck(definition.Checks.Single(), definition, () => new FormData(), Substitute.For <INZazuTableDataSerializer>()); field.Should().NotBeNull(); }