コード例 #1
0
        /// <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);
        }
コード例 #2
0
            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();
                }
            }
コード例 #3
0
 public override void ApplyDataCreationStrategy(string propertyName, DataCreationStrategy <T> strategy, ViolationType violationType)
 {
     throw new NotImplementedException();
 }
コード例 #4
0
 public static T CreateItem <T>(DataCreationStrategy <T> strategy)
 {
     return(strategy.GetValue());
 }
コード例 #5
0
 public ListStrategy(DataCreationStrategy <T> embeddedStrategy)
 {
     _embeddedStrategy = embeddedStrategy;
 }
コード例 #6
0
 public DefinitionOfValid(DataCreationStrategy <T> defaultStrategy)
 {
     _defaultCreationStrategy = defaultStrategy;
 }