public void override_the_default_mode() { var node = new ValidationNode(); node.DefaultMode(ValidationMode.Triggered); node.Mode.ShouldEqual(ValidationMode.Triggered); }
public void determine_the_mode_uses_the_last_matching_policy() { var accessor = SingleProperty.Build <ValidationModeTarget>(x => x.Property); var services = new InMemoryServiceLocator(); services.Add(new AccessorRules()); var mode = ValidationMode.Triggered; var p1 = MockRepository.GenerateStub <IValidationModePolicy>(); p1.Stub(x => x.Matches(services, accessor)).Return(true); p1.Stub(x => x.DetermineMode(services, accessor)).Return(ValidationMode.Live); var p2 = MockRepository.GenerateStub <IValidationModePolicy>(); p2.Stub(x => x.Matches(services, accessor)).Return(true); p2.Stub(x => x.DetermineMode(services, accessor)).Return(mode); var node = new ValidationNode(); node.DefaultMode(ValidationMode.Live); node.RegisterPolicy(p1); node.RegisterPolicy(p2); node.As <IValidationNode>().DetermineMode(services, accessor).ShouldEqual(mode); }
public void default_rendering_strategies() { new AjaxValidationNode(ActionCall.For <FormValidationModeEndpoint>(x => x.post_ajax(null))) .Validation .ShouldHaveTheSameElementsAs(ValidationNode.Default()); new ValidationActionFilter(null, null) .Validation .ShouldHaveTheSameElementsAs(ValidationNode.Default()); }
public void finds_the_validation_node() { var stub = new StubValidationBehaviorNode { Validation = ValidationNode.Default() }; var chain = new BehaviorChain(); chain.AddToEnd(stub); chain.ValidationNode().ShouldEqual(stub.Validation); }
public void determine_the_mode_uses_the_default_when_no_policies_match() { var accessor = SingleProperty.Build<ValidationModeTarget>(x => x.Property); var services = new InMemoryServiceLocator(); services.Add(new AccessorRules()); var p1 = MockRepository.GenerateStub<IValidationModePolicy>(); p1.Stub(x => x.Matches(services, accessor)).Return(false); p1.Stub(x => x.DetermineMode(services, accessor)).Return(ValidationMode.Triggered); var node = new ValidationNode(); node.DefaultMode(ValidationMode.Live); node.RegisterPolicy(p1); node.As<IValidationNode>().DetermineMode(services, accessor).ShouldEqual(ValidationMode.Live); }
public ValidationNode Validate( ISerializationManager serialization, MappingDataNode mapping, ISerializationContext?context) { var validatedMapping = new Dictionary <ValidationNode, ValidationNode>(); foreach (var(key, val) in mapping.Children) { if (key is not ValueDataNode valueDataNode) { validatedMapping.Add(new ErrorNode(key, "Key not ValueDataNode."), new InconclusiveNode(val)); continue; } var field = BaseFieldDefinitions.FirstOrDefault(f => f.Attribute.Tag == valueDataNode.Value); if (field == null) { var error = new ErrorNode( key, $"Field \"{valueDataNode.Value}\" not found in \"{Type}\".", false); validatedMapping.Add(error, new InconclusiveNode(val)); continue; } var keyValidated = serialization.ValidateNode(typeof(string), key, context); ValidationNode valValidated = field.Attribute.CustomTypeSerializer != null ? serialization.ValidateNodeWith(field.FieldType, field.Attribute.CustomTypeSerializer, val, context) : serialization.ValidateNode(field.FieldType, val, context); validatedMapping.Add(keyValidated, valValidated); } return(new ValidatedMappingNode(validatedMapping)); }
public void returns_empty_if_no_validation_node_exists() { var chain = new BehaviorChain(); chain.ValidationNode().ShouldEqual(ValidationNode.Empty()); }
public void SetUp() { theValidationNode = new ValidationNode(); }
public void is_empty_negative() { ValidationNode.Default().IsEmpty().ShouldBeFalse(); }
public void is_empty() { ValidationNode.Empty().IsEmpty().ShouldBeTrue(); }
public void defaults() { var strategies = ValidationNode.Default(); strategies.ShouldHaveTheSameElementsAs(RenderingStrategies.Summary, RenderingStrategies.Highlight); }