Пример #1
0
 public string Generate(ConcreteClass _concreteClass, List<Constraint> constraints)
 {
     var text = new StringBuilder();
     var count = constraints.Count;
     for (var i = 0; i < count; i++)
     {
         var constraint = constraints[i];
         var property = constraint.Property;
           if (constraint.ConcreteClassPropertyMapping != null)
         {
             var classes = constraint.ConcreteClassPropertyMapping.ConcreteClasses;
             var properties = constraint.ConcreteClassPropertyMapping.Properties;
             var @operator = constraint.Operators[0].Value;
             var assert = string.Empty;
             if (@operator.Contains("contains"))
             {
                 var boolQualifier = @operator.ToLower() == "contains" ? "" : "!";
                 if (properties.Count() > 1 && properties[1].GetRelationQualifiedEnum() == RelationQualifiedEnum.LinqSubset)
                 {
                     assert = string.Format("{0}{1}.{2}.Any(x => x.{3} == {4}.{3})", boolQualifier,
                                        classes[0].Instance.Value, properties[0].Name,
                                        properties[1].Name, classes[1].Instance.Value);
                 }
                 else
                 {
                     assert = string.Format("{0}{1}.{2}.Contains({3})", boolQualifier,
                                        classes[0].Instance.Value, properties[0].Name,
                                        classes[1].Instance.Value);
                 }
             }
             else
             {
                 assert = string.Format("{0}.{1} {2} {3}.{4}", classes[0].Instance.Value, properties[0].Name, @operator, classes[1].Instance.Value, properties[1].Name);
             }
             text.AppendLine(AssertText.Replace("##clause##", WriteAssertMessage(assert)));
         }
         else
         {
             GenerateSingleAssert(property, _concreteClass, text);
         }
     }
     return text.ToString();
 }
Пример #2
0
 private void GenerateSingleAssert(Property property, ConcreteClass _concreteClass, StringBuilder text)
 {
     if (string.IsNullOrEmpty(property.Relation))
     {
         var assert = string.Empty;
         var assertBody = string.Empty;
         if (property.Count != null && property.Value == null)
         {
             var countValue = Int32.Parse(property.Count.Value);
             var countOperator = property.Count.Operators.Count > 0
                                     ? property.Count.Operators[0].Value
                                     : "==";
             assert = string.Format("{0}.{1}.Count {2} {3}",
                                    _concreteClass.Instance.Value, property.Name, countOperator, countValue);
             assertBody = AssertText.Replace("##clause##", WriteAssertMessage(assert));
         }
         else if (RegexUtility.IsBool(property.Value))
         {
             var value = Boolean.Parse(property.Value);
             var boolQualifier = value ? string.Empty : "!";
             assert = string.Format("{0}{1}.{2}", boolQualifier, _concreteClass.Instance.Value, property.Name);
             assertBody = AssertText.Replace("##clause##", WriteAssertMessage(assert));
         }
         else if (RegexUtility.IsDateTime(property.Value))
         {
             var dtInstance = "dateTime" + InstanceIdentifier;
             var dateTimeStatement =
                 new Dictionary<string, object> {{"instance", dtInstance}, {"value", property.Value}}.
                     AsNVelocityTemplate(TemplateEnum.DateTimeVariable);
             text.AppendLine(dateTimeStatement);
             assert = string.Format("{0}.{1} {2} {3}", _concreteClass.Instance.Value,
                                    property.Name, property.Operators[0].Value,
                                    dtInstance);
             assertBody = AssertText.Replace("##clause##", WriteAssertMessage(assert));
             InstanceIdentifier++;
         }
         else if (property.Operators[0].Value.Contains("contains"))
         {
             assertBody = AssertText.Replace("##clause##", WriteAssertMessage(GetContainsAssert(property.Operators[0].Value, _concreteClass, property)));
         }
         else
         {
             assert = string.Format("{0}.{1} {2} {3}", _concreteClass.Instance.Value,
                                    property.Name, property.Operators[0].Value,
                                    property.Value);
             assertBody = AssertText.Replace("##clause##", WriteAssertMessage(assert));
         }
         text.AppendLine(assertBody);
     }
 }
Пример #3
0
 private string GetContainsAssert(string @operator, ConcreteClass _concreteClass, Property property)
 {
     string assert;
     var boolQualifier = @operator.ToLower() == "contains" ? "" : "!";
     assert = string.Format("{0}{1}.{2}.Contains({3})", boolQualifier,
                            _concreteClass.Instance.Value, property.Name,
                            property.Value);
     return assert;
 }
Пример #4
0
 public Property()
 {
     ConcreteClass = new ConcreteClass();
     Operators = new List<Operator>();
     DefaultValue = new DefaultValue();
 }