public void test_THAT_text_value_IS_rendered_to_caml_properly() { var operand = new TextValueOperand("foo"); string caml = operand.ToCaml().ToString(); Assert.That(caml, Is.EqualTo("<Value Type=\"Text\">foo</Value>")); }
public void test_THAT_operand_with_not_empty_string_IS_conveted_to_expression_correctly() { var op = new TextValueOperand("foo"); var expr = op.ToExpression(); Assert.That(expr.ToString(), Is.EqualTo("\"foo\"")); }
public void test_THAT_contains_operation_IS_converted_to_expression_correctly() { var op1 = new FieldRefOperand("Title"); var op2 = new TextValueOperand("foo"); var op = new ContainsOperation(null, op1, op2); var expr = op.ToExpression(); Assert.That(expr.ToString(), Is.EqualTo("Convert(x.get_Item(\"Title\")).Contains(\"foo\")")); }
internal void BASE_test_WHEN_expression_is_valid_THEN_operation_is_returned (Func <XElement, IReOperandBuilder, TAnalyzer> constructor, string operationName, OperationType operationType, string operationSymbol) { typeof(DataTypes).GetMembers() .Where(x => x.MemberType == MemberTypes.NestedType).Select(x => x.Name).ToList().ForEach(x => { var foundItem = supportedTypesWithExamples .Where(y => y.SupportedType.Name == x).FirstOrDefault(); if (foundItem == null || (operationType == OperationType.Comparison && !foundItem.ComparisonOperationsSupport) || (operationType == OperationType.Textual && !foundItem.TextualOperationsSupport)) { return; } foundItem.ExamplesOfCorrectValue.ForEach(value => { var lookupId = value.StartsWith(LookupId) ? LookupId : string.Empty; value = value.Replace(LookupId, string.Empty); var xml = string.Format( "<{0}>" + " <FieldRef Name=\"Title\" {1} />" + " <Value Type=\"{2}\">{3}</Value>" + "</{0}>", operationName, lookupId, foundItem.SupportedType.Name, value); var b = MockRepository.GenerateStub <IReOperandBuilder>(); b.Stub(c => c.CreateFieldRefOperand(null)).Return(new FieldRefOperand("Title")).IgnoreArguments(); // if (operationName == Tags.Geq || operationName == Tags.Gt || // operationName == Tags.Leq || operationName == Tags.Lt) // { // b.Stub(c => c.IsOperationComparison(null)).Return(true).IgnoreArguments(); // } // else // { // b.Stub(c => c.IsOperationComparison(null)).Return(false).IgnoreArguments(); // } var valueOperand = default(IOperand); if (operationType == OperationType.Equality) { valueOperand = new TextValueOperand(value); } if (operationType == OperationType.Comparison) { valueOperand = new GenericStringBasedValueOperand(foundItem.SupportedType, value); } if (operationType == OperationType.Textual) { valueOperand = new TextValueOperand(value); } b.Stub(c => c.CreateValueOperand(null, false)).Return(valueOperand).IgnoreArguments(); var analyzer = constructor(XmlHelper.Get(xml), b); var operation = analyzer.GetOperation(); Assert.IsInstanceOf <TOperation>(operation); var operationT = (TOperation)operation; var exprectedResult = default(string); if (operationType == OperationType.Equality) { exprectedResult = string.Format("(Convert(x.get_Item(\"Title\")) {0} \"{1}\")", operationSymbol, value); } if (operationType == OperationType.Comparison) { exprectedResult = string.Format("(x.get_Item(\"Title\") {0} Convert(Convert(\"{1}\")))", operationSymbol, value); } if (operationType == OperationType.Textual) { exprectedResult = string.Format("Convert(x.get_Item(\"Title\")).{0}(\"{1}\")", operationSymbol, value); } Assert.That(operationT.ToExpression().ToString(), Is.EqualTo(exprectedResult)); }); }); }