/// <summary> /// Gets the search filter instance. /// </summary> /// <param name="localName">Name of the local.</param> /// <returns></returns> private static SearchFilter GetSearchFilterInstance(string localName) { SearchFilter searchFilter; switch (localName) { case XmlElementNames.Exists: searchFilter = new Exists(); break; case XmlElementNames.Contains: searchFilter = new ContainsSubstring(); break; case XmlElementNames.Excludes: searchFilter = new ExcludesBitmask(); break; case XmlElementNames.Not: searchFilter = new Not(); break; case XmlElementNames.And: searchFilter = new SearchFilterCollection(LogicalOperator.And); break; case XmlElementNames.Or: searchFilter = new SearchFilterCollection(LogicalOperator.Or); break; case XmlElementNames.IsEqualTo: searchFilter = new IsEqualTo(); break; case XmlElementNames.IsNotEqualTo: searchFilter = new IsNotEqualTo(); break; case XmlElementNames.IsGreaterThan: searchFilter = new IsGreaterThan(); break; case XmlElementNames.IsGreaterThanOrEqualTo: searchFilter = new IsGreaterThanOrEqualTo(); break; case XmlElementNames.IsLessThan: searchFilter = new IsLessThan(); break; case XmlElementNames.IsLessThanOrEqualTo: searchFilter = new IsLessThanOrEqualTo(); break; default: searchFilter = null; break; } return(searchFilter); }
private static void TestIsGreaterThanDelegate(IsGreaterThan isGreaterThanHandler) { // Only the last delegate in the stack can return a value Assert.IsTrue(isGreaterThanHandler(1, 1)); Assert.IsTrue(isGreaterThanHandler(0, 0)); Assert.IsTrue(isGreaterThanHandler(2, 2)); }
public void No_match_if_not_greater() { var isGreaterThanOne = new IsGreaterThan <int>(1); var matches = isGreaterThanOne.Matches(0); Assert.IsFalse(matches); }
public void No_match_if_not_greater() { var isGreaterThanOne = new IsGreaterThan<int>(1); var matches = isGreaterThanOne.Matches(0); Assert.IsFalse(matches); }
public void No_match_if_equal() { var isGreaterThanOne = new IsGreaterThan <int>(1); var matches = isGreaterThanOne.Matches(1); Assert.False(matches); }
public void TestMultiCastDelegate() { IsGreaterThan isGreaterThanHandler = IsGreaterThanImplementation; isGreaterThanHandler += IsGreaterOrEqual; TestIsGreaterThanDelegate(isGreaterThanHandler); }
public void WhereTheItemAtPositionIsGreaterThanValue_WithNotExistentItemInPosition_ShouldThrowException() { int[] array = { 1, 2, 3 }; int index = 3; Action act = () => IsAnEnumerable <int> .WhereTheItemAtPosition(index, IsGreaterThan.Value(2)).Evaluate(array); act.Should().Throw <ScreenplayException>() .WithMessage($"Index {index} is out of range for the IEnumerable<{typeof(int)}> with count {array.Count()}"); }
public void IsGreaterThan_HandleType_ShouldReturnIsGreaterThan() { var decisionType = enDecisionType.IsGreaterThan; //------------Setup for test-------------------------- var greaterThan = new IsGreaterThan(); //------------Execute Test--------------------------- //------------Assert Results------------------------- Assert.AreEqual(decisionType, greaterThan.HandlesType()); }
public SqlTag Deserialize(XmlNode node) { IsGreaterThan than = new IsGreaterThan(this._configScope.DataExchangeFactory.AccessorFactory); NameValueCollection attributes = NodeUtils.ParseAttributes(node, this._configScope.Properties); than.Prepend = NodeUtils.GetStringAttribute(attributes, "prepend"); than.Property = NodeUtils.GetStringAttribute(attributes, "property"); than.CompareProperty = NodeUtils.GetStringAttribute(attributes, "compareProperty"); than.CompareValue = NodeUtils.GetStringAttribute(attributes, "compareValue"); return(than); }
/// <summary> /// Deserializes the specified configuration in an <see cref="IsGreaterThan"/> object /// </summary> /// <param name="configuration">The configuration.</param> /// <returns></returns> public override SqlTag Deserialize(IConfiguration configuration) { IsGreaterThan isGreaterThan = new IsGreaterThan(accessorFactory); isGreaterThan.Prepend = ConfigurationUtils.GetStringAttribute(configuration.Attributes, "prepend"); isGreaterThan.Property = ConfigurationUtils.GetStringAttribute(configuration.Attributes, "property"); isGreaterThan.CompareProperty = ConfigurationUtils.GetStringAttribute(configuration.Attributes, "compareProperty"); isGreaterThan.CompareValue = ConfigurationUtils.GetStringAttribute(configuration.Attributes, "compareValue"); return(isGreaterThan); }
public void IsGreaterThan_IsGreaterThanUnitTest_Invoke_TrueIsReturned() { //init var comparer = new IsGreaterThan(); //exe var actual = comparer.Invoke(new[] { "100", "2" }); //assert Assert.IsTrue(actual, "IsGreaterThan returned the wrong result when comparing integers"); }
// ReSharper disable InconsistentNaming public void IsGreaterThan_IsGreaterThanUnitTest_Invoke_FalseIsReturned() // ReSharper restore InconsistentNaming { //init var comparer = new IsGreaterThan(); //exe var actual = comparer.Invoke(new[] { "2", "100" }); //assert Assert.IsFalse(actual, "IsGreaterThan returned the wrong result when comparing integers"); }
public void ReturnSql() { IsGreaterThan tag = new IsGreaterThan { //BodyText = "", Prepend = "And Id", Property = "Status", CompareValue = "0", }; string sql = tag.BuildSql(new RequestContext { Request = new { Status = OrderStatus.Done } }); Assert.NotNull(sql); }
public void IsGreaterThan_IsGreaterThanUnitTest_Invoke_FalseIsReturned() { //init var comparer = new IsGreaterThan(); //exe var actual = comparer.Invoke(new[] { "2", "100" }); //assert Assert.IsFalse(actual, "IsGreaterThan returned the wrong result when comparing integers"); //exe actual = comparer.Invoke(new[] { "SomeVal", "AnotherVal" }); //assert Assert.IsTrue(actual, "IsGreaterThan returned the wrong result when comparing strings"); //exe actual = comparer.Invoke(new[] { string.Empty }); //assert Assert.IsFalse(actual, "IsGreaterThan returned the wrong result when comparing empty string"); }
static void Main(string[] args) { IsGreaterThan g1 = (basic) => { if (basic > 10000) { return(true); } else { return(false); } }; Console.WriteLine("Enter Basic : "); int temp = int.Parse(Console.ReadLine()); Console.WriteLine("IsGreaterThan 10000 : " + g1(temp)); Console.ReadLine(); }
private static void TestIsGreaterThanDelegate(IsGreaterThan isGreaterThanHandler) { Assert.IsTrue(isGreaterThanHandler(1, 0)); Assert.IsFalse(isGreaterThanHandler(0, 0)); Assert.IsFalse(isGreaterThanHandler(0, 1)); }
public static ITag LoadTag(XmlNode xmlNode, IList <Include> includes) { ITag tag = null; bool isIn = xmlNode.Attributes?["In"] != null; var prepend = xmlNode.Attributes?["Prepend"]?.Value.Trim(); var property = xmlNode.Attributes?["Property"]?.Value.Trim(); var compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim(); #region Init Tag switch (xmlNode.Name) { case "#text": case "#cdata-section": { var bodyText = " " + xmlNode.InnerText.Replace("\n", "").Trim(); return(new SqlText { BodyText = bodyText }); } case "Include": { var refId = xmlNode.Attributes?["RefId"]?.Value; var include_tag = new Include { RefId = refId, Prepend = prepend }; includes.Add(include_tag); tag = include_tag; break; } case "IsEmpty": { tag = new IsEmpty { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsEqual": { tag = new IsEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterEqual": { tag = new IsGreaterEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterThan": { tag = new IsGreaterThan { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessEqual": { tag = new IsLessEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessThan": { tag = new IsLessThan { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotEmpty": { tag = new IsNotEmpty { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNotEqual": { tag = new IsNotEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotNull": { tag = new IsNotNull { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNull": { tag = new IsNull { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsTrue": { tag = new IsTrue { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsFalse": { tag = new IsFalse { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsProperty": { tag = new IsProperty { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "Switch": { tag = new Switch { Property = property, //Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Case": { var switchNode = xmlNode.ParentNode; var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim(); var switchPrepend = switchNode.Attributes?["Prepend"]?.Value.Trim(); tag = new Switch.Case { CompareValue = compareValue, Property = switchProperty, Prepend = switchPrepend, ChildTags = new List <ITag>() }; break; } case "Default": { var switchNode = xmlNode.ParentNode; var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim(); var switchPrepend = switchNode.Attributes?["Prepend"]?.Value.Trim(); tag = new Switch.Defalut { Property = switchProperty, Prepend = switchPrepend, ChildTags = new List <ITag>() }; break; } case "Dynamic": { tag = new Dynamic { Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Where": { tag = new Where { ChildTags = new List <ITag>() }; break; } case "Set": { tag = new Set { ChildTags = new List <ITag>() }; break; } case "For": { var open = xmlNode.Attributes?["Open"]?.Value.Trim(); var separator = xmlNode.Attributes?["Separator"]?.Value.Trim(); var close = xmlNode.Attributes?["Close"]?.Value.Trim(); var key = xmlNode.Attributes?["Key"]?.Value.Trim(); tag = new For { Prepend = prepend, Property = property, Open = open, Close = close, Separator = separator, Key = key, ChildTags = new List <ITag>() }; break; } case "Env": { var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim(); tag = new Env { Prepend = prepend, DbProvider = dbProvider, ChildTags = new List <ITag>() }; break; } case "#comment": { break; } default: { throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}."); }; } #endregion foreach (XmlNode childNode in xmlNode) { ITag childTag = LoadTag(childNode, includes); if (childTag != null && tag != null) { (tag as Tag).ChildTags.Add(childTag); } } return(tag); }
/// <summary> /// Gets the search filter instance. /// </summary> /// <param name="localName">Name of the local.</param> /// <returns></returns> private static SearchFilter GetSearchFilterInstance(string localName) { SearchFilter searchFilter; switch (localName) { case XmlElementNames.Exists: searchFilter = new Exists(); break; case XmlElementNames.Contains: searchFilter = new ContainsSubstring(); break; case XmlElementNames.Excludes: searchFilter = new ExcludesBitmask(); break; case XmlElementNames.Not: searchFilter = new Not(); break; case XmlElementNames.And: searchFilter = new SearchFilterCollection(LogicalOperator.And); break; case XmlElementNames.Or: searchFilter = new SearchFilterCollection(LogicalOperator.Or); break; case XmlElementNames.IsEqualTo: searchFilter = new IsEqualTo(); break; case XmlElementNames.IsNotEqualTo: searchFilter = new IsNotEqualTo(); break; case XmlElementNames.IsGreaterThan: searchFilter = new IsGreaterThan(); break; case XmlElementNames.IsGreaterThanOrEqualTo: searchFilter = new IsGreaterThanOrEqualTo(); break; case XmlElementNames.IsLessThan: searchFilter = new IsLessThan(); break; case XmlElementNames.IsLessThanOrEqualTo: searchFilter = new IsLessThanOrEqualTo(); break; default: searchFilter = null; break; } return searchFilter; }
public void WhereTheLastItemIsGreaterThanValue_WithLastItemGreater_ShouldBeTrue() { int[] array = { 1, 2, 3 }; IsAnEnumerable <int> .WhereTheLastItem(IsGreaterThan.Value(2)).Evaluate(array).Should().BeTrue(); }
public void Less_False() { IsGreaterThan.Value(2).Evaluate(1).Should().BeFalse(); }
private ITag LoadTag(XmlNode xmlNode, Statement statement) { ITag tag = null; var prepend = xmlNode.Attributes?["Prepend"]?.Value.Trim(); var property = xmlNode.Attributes?["Property"]?.Value.Trim(); var compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim(); #region Init Tag switch (xmlNode.Name) { case "#text": case "#cdata-section": { var innerText = xmlNode.InnerText; var bodyText = innerText; //bodyText += innerText.Trim().Replace("\r", " ").Replace("\n", " "); //bodyText += " "; return(new SqlText { Statement = statement, BodyText = bodyText }); } case "Include": { var refId = xmlNode.Attributes?["RefId"]?.Value; if (refId.IndexOf('.') < 0) { refId = $"{statement.SmartSqlMap.Scope}.{refId}"; } var include_tag = new Include { RefId = refId, Prepend = xmlNode.Attributes?["Prepend"]?.Value }; statement.IncludeDependencies.Add(include_tag); tag = include_tag; break; } case "IsEmpty": { tag = new IsEmpty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsEqual": { tag = new IsEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterEqual": { tag = new IsGreaterEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterThan": { tag = new IsGreaterThan { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessEqual": { tag = new IsLessEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessThan": { tag = new IsLessThan { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotEmpty": { tag = new IsNotEmpty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNotEqual": { tag = new IsNotEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotNull": { tag = new IsNotNull { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNull": { tag = new IsNull { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsTrue": { tag = new IsTrue { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsFalse": { tag = new IsFalse { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsProperty": { tag = new IsProperty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "Placeholder": { tag = new Placeholder { Prepend = xmlNode.Attributes?["Prepend"]?.Value, Property = property, ChildTags = new List <ITag>() }; break; } case "Switch": { tag = new Switch { Property = property, Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Case": { var switchNode = xmlNode.ParentNode; var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim(); var switchPrepend = switchNode.Attributes?["Prepend"]?.Value.Trim(); tag = new Switch.Case { CompareValue = compareValue, Property = switchProperty, Prepend = switchPrepend, ChildTags = new List <ITag>() }; break; } case "Default": { var switchNode = xmlNode.ParentNode; var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim(); var switchPrepend = switchNode.Attributes?["Prepend"]?.Value.Trim(); tag = new Switch.Defalut { Property = switchProperty, Prepend = switchPrepend, ChildTags = new List <ITag>() }; break; } case "Dynamic": { tag = new Dynamic { Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Where": { tag = new Where { ChildTags = new List <ITag>() }; break; } case "Set": { tag = new Set { ChildTags = new List <ITag>() }; break; } case "For": { var open = xmlNode.Attributes?["Open"]?.Value.Trim(); var separator = xmlNode.Attributes?["Separator"]?.Value.Trim(); var close = xmlNode.Attributes?["Close"]?.Value.Trim(); var key = xmlNode.Attributes?["Key"]?.Value.Trim(); tag = new For { Prepend = prepend, Property = property, Open = open, Close = close, Separator = separator, Key = key, ChildTags = new List <ITag>() }; break; } case "Env": { var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim(); tag = new Env { Prepend = prepend, DbProvider = dbProvider, ChildTags = new List <ITag>() }; break; } case "#comment": { return(null); } default: { throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}."); }; } tag.Statement = statement; #endregion foreach (XmlNode childNode in xmlNode) { ITag childTag = LoadTag(childNode, statement); if (childTag != null && tag != null) { childTag.Parent = tag; (tag as Tag).ChildTags.Add(childTag); } } return(tag); }
public void WhereEveryItemIsGreaterThanValue_WithAllItemsGreater_ShouldBeTrue() { int[] array = { 1, 2, 3 }; IsAnEnumerable <int> .WhereEveryItem(IsGreaterThan.Value(0)).Evaluate(array).Should().BeTrue(); }
public void Equal_False() { IsGreaterThan.Value(1).Evaluate(1).Should().BeFalse(); }
public void WhereTheFirstItemIsGreaterThanValue_WithFirstItemNotGreater_ShouldBeFalse() { int[] array = { 1, 2, 3 }; IsAnEnumerable <int> .WhereTheFirstItem(IsGreaterThan.Value(1)).Evaluate(array).Should().BeFalse(); }
public static ITag LoadTag(XNode node) { ITag tag = null; if (node.NodeType == System.Xml.XmlNodeType.Text || node.NodeType == System.Xml.XmlNodeType.CDATA) { tag = new SqlText { BodyText = node.ToString() }; } if (node.NodeType == System.Xml.XmlNodeType.Element) { XElement elenode = node as XElement; bool isIn = elenode.Attribute("In") != null; var prepend = elenode.Attribute("Prepend")?.Value.Trim(); var property = elenode.Attribute("Property")?.Value.Trim(); var compareValue = elenode.Attribute("CompareValue")?.Value.Trim(); var nodeName = elenode.Name.LocalName; switch (nodeName) { case "IsEmpty": { tag = new IsEmpty { Prepend = prepend, Property = property, Children = new List <ITag>() }; break; } case "IsEqual": { tag = new IsEqual { Prepend = prepend, Property = property, CompareValue = compareValue, Children = new List <ITag>() }; break; } case "IsNotEqual": { tag = new IsNotEqual { Prepend = prepend, CompareValue = compareValue, Property = property, Children = new List <ITag>() }; break; } case "IsGreaterEqual": { tag = new IsGreaterEqual { Prepend = prepend, Property = property, CompareValue = compareValue, }; break; } case "IsGreaterThan": { tag = new IsGreaterThan { Prepend = prepend, Property = property, CompareValue = compareValue, Children = new List <ITag>() }; break; } case "IsLessEqual": { tag = new IsLessEqual { Prepend = prepend, Property = property, CompareValue = compareValue, Children = new List <ITag>() }; break; } case "IsLessThan": { tag = new IsLessThan { Prepend = prepend, Property = property, CompareValue = compareValue, Children = new List <ITag>() }; break; } case "IsNotEmpty": { tag = new IsNotEmpty { Prepend = prepend, Property = property, Children = new List <ITag>() }; break; } case "IsNotNull": { tag = new IsNotNull { Prepend = prepend, Property = property, Children = new List <ITag>() }; break; } case "IsNull": { tag = new IsNull { Prepend = prepend, Property = property, Children = new List <ITag>() }; break; } case "Switch": { tag = new Switch { // Prepend = prepend, Property = property, Children = new List <ITag>() }; break; } case "Case": { var switchNode = node.Parent; var switchProperty = switchNode.Attribute("Property")?.Value.Trim(); var switchPrepend = switchNode.Attribute("Prepend")?.Value.Trim(); tag = new Switch.Case { Prepend = switchPrepend, Property = switchProperty, CompareValue = compareValue, Children = new List <ITag>() }; break; } case "Default": { var switchNode = node.Parent; var switchProperty = switchNode.Attribute("Property")?.Value.Trim(); var switchPrepend = switchNode.Attribute("Prepend")?.Value.Trim(); tag = new Switch.Default { Prepend = switchPrepend, Property = switchProperty, Children = new List <ITag>() }; break; } case "Where": { tag = new Where { Children = new List <ITag>() }; break; } case "Dynamic": { tag = new Dynamic { Prepend = prepend, Children = new List <ITag>() }; break; } case "IsProperty": { tag = new IsProperty { Prepend = prepend, Children = new List <ITag>(), Property = property }; break; } default: { throw new BaraException($"Statement can't load TagName:{nodeName}"); } } foreach (var childNode in elenode.Nodes()) { ITag childTag = LoadTag(childNode); if (childTag != null && tag != null) { (tag as Tag).Children.Add(childTag); } } } return(tag); }
public void Test04LambdaFunction() { IsGreaterThan isGreaterThanHandler = (aValue, compareTo) => aValue > compareTo; TestIsGreaterThanDelegate(isGreaterThanHandler); }
public void Test01CreateADelegateInstance() { IsGreaterThan isGreaterThanHandler = new IsGreaterThan(DelegatesToLambda.IsGreaterThanImplementation); TestIsGreaterThanDelegate(isGreaterThanHandler); }
public void WhereCountIsGreaterThanValue_WithHasSizeNotGreater_ShouldBeFalse() { int[] array = { 1, 2, 3 }; IsAnEnumerable <int> .WhereTheCount(IsGreaterThan.Value(3)).Evaluate(array).Should().BeFalse(); }
public void WhereAtLeastOneItemIsGreaterThanValue_WithNoItemsGreater_ShouldBeFalse() { int[] array = { 1, 2, 3 }; IsAnEnumerable <int> .WhereAtLeastOneItem(IsGreaterThan.Value(3)).Evaluate(array).Should().BeFalse(); }
private ITag LoadTag(XNode xmlNode, IList <Include> includes) { ITag tag = null; var prepend = xmlNode?.GetAttribute("Prepend")?.Trim(); var property = xmlNode?.GetAttribute("Property")?.Trim(); var compareValue = xmlNode?.GetAttribute("CompareValue")?.Trim(); #region Init Tag switch (xmlNode.GetName()) { case "#text": case "#cdata-section": { var bodyText = " " + xmlNode.GetValue().Replace("\n", "").Trim(); return(new SqlText { LineInfo = XmlLineInfo.Create(xmlNode), BodyText = bodyText }); } case "If": { tag = new IfTag { Test = xmlNode.GetAttribute("Test") }; break; } case "Include": { var refId = xmlNode?.GetAttribute("RefId"); var include_tag = new Include { RefId = refId, Prepend = prepend }; includes.Add(include_tag); tag = include_tag; break; } case "IsEmpty": { tag = new IsEmpty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsEqual": { tag = new IsEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "Bind": { tag = new BindTag { Name = xmlNode.GetAttribute("Name"), Value = xmlNode.GetAttribute("Value"), }; break; } case "Trim": { tag = new TrimTag { Prefix = xmlNode.GetAttribute("Prefix"), PrefixOverrides = xmlNode.GetAttribute("PrefixOverrides"), Suffix = xmlNode.GetAttribute("Suffix"), ChildTags = new List <ITag>(), }; break; } case "IsGreaterEqual": { tag = new IsGreaterEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterThan": { tag = new IsGreaterThan { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessEqual": { tag = new IsLessEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessThan": { tag = new IsLessThan { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotEmpty": { tag = new IsNotEmpty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNotEqual": { tag = new IsNotEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotNull": { tag = new IsNotNull { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNull": { tag = new IsNull { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsTrue": { tag = new IsTrue { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsFalse": { tag = new IsFalse { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsProperty": { tag = new IsProperty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "Placeholder": { tag = new Placeholder { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "Switch": { tag = new Switch { Property = property, Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Case": { var switchNode = xmlNode.Parent; var switchProperty = xmlNode?.GetAttribute("Property")?.Trim(); var switchPrepend = xmlNode?.GetAttribute("Prepend")?.Trim(); tag = new Switch.Case { CompareValue = compareValue, Property = switchProperty, Prepend = switchPrepend, Test = xmlNode?.GetAttribute("Test")?.Trim(), ChildTags = new List <ITag>() }; break; } case "Default": { var switchNode = xmlNode.Parent; var switchProperty = xmlNode?.GetAttribute("Property")?.Trim(); var switchPrepend = xmlNode?.GetAttribute("Prepend")?.Trim(); tag = new Switch.Defalut { Property = switchProperty, Prepend = switchPrepend, ChildTags = new List <ITag>() }; break; } case "Dynamic": { tag = new Dynamic { Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Where": { tag = new Where { ChildTags = new List <ITag>() }; break; } case "Set": { tag = new Set { ChildTags = new List <ITag>() }; break; } case "For": { var open = xmlNode?.GetAttribute("Open")?.Trim(); var separator = xmlNode?.GetAttribute("Separator")?.Trim(); var close = xmlNode?.GetAttribute("Close")?.Trim(); var key = xmlNode?.GetAttribute("Key")?.Trim(); var index = xmlNode?.GetAttribute("Index")?.Trim(); tag = new For { Prepend = prepend, Property = property, Open = open, Close = close, Index = index, Separator = separator, Key = key, ChildTags = new List <ITag>() }; break; } case "Env": { var dbProvider = xmlNode?.GetAttribute("DbProvider")?.Trim(); tag = new Env { Prepend = prepend, DbProvider = dbProvider, ChildTags = new List <ITag>() }; break; } case "#comment": { break; } default: { throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.GetName()}."); }; } #endregion if (tag != null) { tag.LineInfo = XmlLineInfo.Create(xmlNode); } if (xmlNode is XElement ell) { foreach (XNode childNode in ell.Nodes()) { ITag childTag = LoadTag(childNode, includes); if (childTag != null && tag != null) { childTag.Parent = tag; (tag as Tag).ChildTags.Add(childTag); } } } return(tag); }
public ITag Build(XmlNode xmlNode) { ITag tag = null; var prepend = xmlNode.Attributes?["Prepend"]?.Value.Trim(); var property = xmlNode.Attributes?["Property"]?.Value.Trim(); var compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim(); #region Init Tag switch (xmlNode.Name) { case "#text": case "#cdata-section": { var bodyText = " " + xmlNode.InnerText.Replace("\n", "").Trim(); return(new SqlText { BodyText = bodyText }); } case "Include": { var refId = xmlNode.Attributes?["RefId"]?.Value; var include_tag = new Include { RefId = refId, Prepend = prepend }; //includes.Add(include_tag); tag = include_tag; break; } case "IsEmpty": { tag = new IsEmpty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsEqual": { tag = new IsEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterEqual": { tag = new IsGreaterEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterThan": { tag = new IsGreaterThan { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessEqual": { tag = new IsLessEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessThan": { tag = new IsLessThan { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotEmpty": { tag = new IsNotEmpty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNotEqual": { tag = new IsNotEqual { Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotNull": { tag = new IsNotNull { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNull": { tag = new IsNull { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsTrue": { tag = new IsTrue { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsFalse": { tag = new IsFalse { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsProperty": { tag = new IsProperty { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "Placeholder": { tag = new Placeholder { Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "Switch": { tag = new Switch { Property = property, Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Case": { var switchNode = xmlNode.ParentNode; var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim(); var switchPrepend = switchNode.Attributes?["Prepend"]?.Value.Trim(); tag = new Switch.Case { CompareValue = compareValue, Property = switchProperty, Prepend = switchPrepend, Test = xmlNode.Attributes?["Test"]?.Value.Trim(), ChildTags = new List <ITag>() }; break; } case "Bind": { tag = new BindTag { Name = xmlNode.Attributes["Name"]?.Value, Value = xmlNode.Attributes["Value"]?.Value, }; break; } case "Trim": { tag = new TrimTag { Prefix = xmlNode.Attributes["Prefix"]?.Value, PrefixOverrides = xmlNode.Attributes["PrefixOverrides"]?.Value, Suffix = xmlNode.Attributes["Suffix"]?.Value, ChildTags = new List <ITag>() }; break; } case "Default": { var switchNode = xmlNode.ParentNode; var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim(); var switchPrepend = switchNode.Attributes?["Prepend"]?.Value.Trim(); tag = new Switch.Defalut { Property = switchProperty, Prepend = switchPrepend, ChildTags = new List <ITag>() }; break; } case "Dynamic": { tag = new Dynamic { Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Where": { tag = new Where { ChildTags = new List <ITag>() }; break; } case "If": { var test = xmlNode.Attributes["Test"]?.Value; tag = new IfTag { Test = test }; } break; case "Set": { tag = new Set { ChildTags = new List <ITag>() }; break; } case "For": { var open = xmlNode.Attributes?["Open"]?.Value.Trim(); var separator = xmlNode.Attributes?["Separator"]?.Value.Trim(); var close = xmlNode.Attributes?["Close"]?.Value.Trim(); var key = xmlNode.Attributes?["Key"]?.Value.Trim(); tag = new For { Prepend = prepend, Property = property, Open = open, Close = close, Separator = separator, Key = key, ChildTags = new List <ITag>() }; break; } case "Env": { var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim(); tag = new Env { Prepend = prepend, DbProvider = dbProvider, ChildTags = new List <ITag>() }; break; } case "#comment": { break; } default: { throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}."); }; } #endregion return(tag); }
public static ITag LoadTag(XmlNode xmlNode) { ITag tag = null; bool isIn = xmlNode.Attributes?["In"] != null; var prepend = xmlNode.Attributes?["Prepend"]?.Value; var property = xmlNode.Attributes?["Property"]?.Value; var compareValue = xmlNode.Attributes?["CompareValue"]?.Value; #region Init Tag switch (xmlNode.Name) { case "#text": case "#cdata-section": { var bodyText = xmlNode.InnerText.Replace("\n", ""); return(new SqlText { BodyText = bodyText }); } case "IsEmpty": { tag = new IsEmpty { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsEqual": { tag = new IsEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsGreaterEqual": { tag = new IsGreaterEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, }; break; } case "IsGreaterThan": { tag = new IsGreaterThan { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessEqual": { tag = new IsLessEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsLessThan": { tag = new IsLessThan { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotEmpty": { tag = new IsNotEmpty { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNotEqual": { tag = new IsNotEqual { In = isIn, Prepend = prepend, Property = property, CompareValue = compareValue, ChildTags = new List <ITag>() }; break; } case "IsNotNull": { tag = new IsNotNull { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsNull": { tag = new IsNull { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsTrue": { tag = new IsTrue { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "IsFalse": { tag = new IsFalse { In = isIn, Prepend = prepend, Property = property, ChildTags = new List <ITag>() }; break; } case "Switch": { tag = new Switch { Property = property, //Prepend = prepend, ChildTags = new List <ITag>() }; break; } case "Case": { var switchNode = xmlNode.ParentNode; var switchProperty = switchNode.Attributes?["Property"]?.Value; var switchPrepend = switchNode.Attributes?["Prepend"]?.Value; tag = new Switch.Case { CompareValue = compareValue, Property = switchProperty, Prepend = switchPrepend, ChildTags = new List <ITag>() }; break; } case "#comment": { break; } default: { break; }; } #endregion foreach (XmlNode childNode in xmlNode) { ITag childTag = LoadTag(childNode); (tag as Tag).ChildTags.Add(childTag); } return(tag); }
public void Greater_True() { IsGreaterThan.Value(1).Evaluate(2).Should().BeTrue(); }