public void Test_DecimalAttribute([ValueSource(nameof(Comparisons))] ValidationComparison comparison, [ValueSource(nameof(Amounts))] decimal amount, [ValueSource(nameof(ComparisonAmounts))] int comparisonAmount) { var attribute = new DecimalAttribute(comparisonAmount, comparison); var result = attribute.IsValid(amount); Assert.IsTrue(result); }
public void SetValue_SetsDecimalAttribute() { NewElement element = InitializeEmptyNewElement(); int id = 15; var att = new DecimalAttribute() { Id = id }; element.DecimalAttributes.Add(att); decimal value = 15.15m; element.SetValue(id, value); Assert.Equal(value, att.Value); }
protected virtual void addColumn_Decimal(EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName) { if (ep.MoneyAttribute != null) { sb.Append(columnName); sb.Append(" money default 0, "); } else { DecimalAttribute da = ep.DecimalAttribute; if (da == null) { throw new Exception("DecimalAttribute not found=" + entity.FullName + "_" + ep.Name); } sb.Append(columnName); sb.Append(" decimal(" + da.Precision + "," + da.Scale + ") default 0, "); } }
private Element ConvertXElementToElement(XElement element) { var elementValues = new List <string>(); if (!element.Elements().Any()) { var tElem = _oldRoot.Descendants(element.Name).Where(x => GetParentsAsString(x, -1) == GetParentsAsString(element, -1) && !x.Elements().Any()).Select(e => e.Value); elementValues.AddRange(tElem); } var xElementList = _oldRoot.Descendants(element.Name).GroupBy(el => el.Parent).Select(g => new { g.Key, Count = g.Count() }).Where(x => x.Count > 1); Element returnElement; var elementName = element.Name.LocalName; var elementType = DataType.GetDataTypeFromList(elementValues, _dateFormat, _dateTimeFormat); switch (elementType.type) { case DataType.Type.Date: returnElement = new DateTimeElement(elementName, _dateFormat); break; case DataType.Type.DateTime: returnElement = new DateTimeElement(elementName, _dateTimeFormat); break; case DataType.Type.Bool: returnElement = new BoolElement(elementName, "True", "False"); break; case DataType.Type.@bool: returnElement = new BoolElement(elementName, "true", "false"); break; case DataType.Type.@int: returnElement = new IntElement(elementName); break; case DataType.Type.@decimal: returnElement = new DecimalElement(elementName); break; case DataType.Type.@string: returnElement = new StringElement(elementName); break; default: returnElement = new Element(elementName); break; } returnElement.Enumerable = xElementList.Any(); returnElement.Type = elementType; returnElement.OriginalElement = element; foreach (var xElement in element.Elements()) { returnElement.Elements.Add(ConvertXElementToElement(xElement)); } foreach (var xAttribute in element.Attributes()) { var tElements = _oldRoot.DescendantsAndSelf(element.Name).Where(x => GetParentsAsString(x, -1) == GetParentsAsString(element, -1)).ToList(); var xAttr = xAttribute; var attributeValues = tElements.Select(tElement => tElement.Attribute(xAttr.Name)).Select(attribute => attribute != null ? attribute.Value : "").ToList(); Attribute thisAttribute; var attributeName = xAttribute.Name.LocalName; if (xAttribute.IsNamespaceDeclaration) { returnElement.NamespaceAttributes.Add(xAttribute); continue; } if (attributeName == "schemaLocation") { thisAttribute = new SchemaLocationAttribute(attributeName, xAttribute.Value); returnElement.Attributes.Add(thisAttribute); continue; } var attributeType = DataType.GetDataTypeFromList(attributeValues, _dateFormat, _dateTimeFormat); switch (attributeType.type) { case DataType.Type.Date: thisAttribute = new DateTimeAttribute(attributeName, _dateFormat); break; case DataType.Type.DateTime: thisAttribute = new DateTimeAttribute(attributeName, _dateTimeFormat); break; case DataType.Type.Bool: thisAttribute = new BoolAttribute(attributeName, "True", "False"); break; case DataType.Type.@bool: thisAttribute = new BoolAttribute(attributeName, "true", "false"); break; case DataType.Type.@int: thisAttribute = new IntAttribute(attributeName); break; case DataType.Type.@decimal: thisAttribute = new DecimalAttribute(attributeName); break; case DataType.Type.@string: thisAttribute = new StringAttribute(attributeName); break; default: thisAttribute = new Attribute(attributeName); break; } thisAttribute.Type = attributeType; returnElement.Attributes.Add(thisAttribute); } return(returnElement); }