/// <summary> /// Creates a violation based on the name of a property /// </summary> public DataCreationStrategy <T> CreateViolation(string propertyName, ViolationType violationType) { if (!_validations.ContainsKey(propertyName)) { throw new Exception("There is no definition of valid for this property"); } DataCreationStrategy <T> strategy = _defaultCreationStrategy ?? new DataCreationStrategy <T>(); Validity validation = _validations[propertyName]; validation.ApplyDataCreationStrategy(propertyName, strategy, violationType); return(strategy); }
public override void ApplyDataCreationStrategy(string propertyName, DataCreationStrategy <T> strategy, ViolationType violationType) { if (violationType == ViolationType.MaximumValue && _max.HasValue) { DoubleStrategy doubleStrategy = new DoubleStrategy(); doubleStrategy.Increment(_max.Value + 1); strategy.Add <double, DoubleStrategy>(propertyName, doubleStrategy); } else if (violationType == ViolationType.MinimumValue && _min.HasValue) { DoubleStrategy doubleStrategy = new DoubleStrategy(); doubleStrategy.Decrement(_min.Value - 1); strategy.Add <double, DoubleStrategy>(propertyName, doubleStrategy); } else { throw new UnsupportedViolationException(); } }
public override void ApplyDataCreationStrategy(string propertyName, DataCreationStrategy <T> strategy, ViolationType violationType) { throw new NotImplementedException(); }
public static T CreateItem <T>(DataCreationStrategy <T> strategy) { return(strategy.GetValue()); }
public ListStrategy(DataCreationStrategy <T> embeddedStrategy) { _embeddedStrategy = embeddedStrategy; }
public DefinitionOfValid(DataCreationStrategy <T> defaultStrategy) { _defaultCreationStrategy = defaultStrategy; }