public void Should_store_Dec_result(short value, short expected) { Mockery .VariableRetrieves(value); var args = new OperandBuilder() .WithArg(AnyVariable) .Build(); Operation.Execute(args); Mockery .ResultStored(expected); }
public void test_WHEN_native_value_is_datetime_with_includetimevalue_THEN_datetime_operand_is_created() { var operandBuilder = new OperandBuilder(); Expression <Func <SPListItem, bool> > expr = x => (DateTime)x["Foo"] == new DateTime(2010, 1, 2, 3, 4, 5).IncludeTimeValue(); var operand = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right); Assert.That(operand, Is.InstanceOf <DateTimeValueOperand>()); var valueOperand = operand as DateTimeValueOperand; Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.DateTime))); Assert.That(valueOperand.Value, Is.EqualTo(new DateTime(2010, 1, 2, 3, 4, 5))); Assert.That(valueOperand.IncludeTimeValue, Is.True); }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="symbol">The symbol of this operator.</param> /// <param name="independency">The independency of this operator.</param> /// <param name="description">The description of this operator.</param> protected BaseBuiltInComparativeOperator(string symbol, OperatorIndependency independency, string description) : base(symbol, independency) { builder = new OperandBuilder(); if (description == null) { var attribute = Attribute.GetCustomAttribute(GetType(), typeof(DescriptionAttribute)) as DescriptionAttribute; Description = (attribute != null) ? attribute.Description : ""; } else { Description = description; } }
public void test_WHEN_string_based_value_is_user_id_THEN_lookup_field_ref_operand_is_created() { Expression <Func <SPListItem, bool> > expr = x => x["foo"] == (DataTypes.UserId) "1"; var operandBuilder = new OperandBuilder(); var operand = operandBuilder.CreateFieldRefOperand(((BinaryExpression)expr.Body).Left, new UserIdValueOperand("1")); Assert.That(operand, Is.InstanceOf <FieldRefOperand>()); var op = (FieldRefOperand)operand; Assert.That(op.Attributes.Count, Is.EqualTo(1)); Assert.That(op.Attributes[0].Key, Is.EqualTo("LookupId")); Assert.That(op.Attributes[0].Value, Is.EqualTo("True")); }
public void Should_store_return_value_when_asked() { Mockery .StartingPC(100, true); var args = new OperandBuilder() .WithArg(AnyValue) .Build(); Operation.Execute(args); Mockery .ResultDestinationRetrievedFromPC() .ResultStored(AnyValue); }
public void Should_not_store_when_routine_does_not_store() { Mockery .StartingPC(100); var args = new OperandBuilder() .WithArg(AnyValue) .Build(); Operation.Execute(args); Mockery .NoResultDestinationRetrieved() .NoResultWasStored(); }
public void test_WHEN_native_value_is_guid_THEN_guid_operand_is_created() { var operandBuilder = new OperandBuilder(); var guid = new Guid("4feaf1f3-5b04-4d93-b0fc-4e48d0c60eed"); Expression <Func <SPListItem, bool> > expr = x => (Guid)x["Foo"] == guid; var operand = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right); Assert.That(operand, Is.InstanceOf <GuidValueOperand>()); var valueOperand = operand as GuidValueOperand; Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.Guid))); Assert.That(valueOperand.Value, Is.EqualTo(new Guid("4feaf1f3-5b04-4d93-b0fc-4e48d0c60eed"))); }
public void test_WHEN_string_based_value_is_datetime_with_includetimevalue_THEN_datetime_operand_is_created() { var operandBuilder = new OperandBuilder(); Expression <Func <SPListItem, bool> > expr = x => x["Modified"] == ((DataTypes.DateTime) "02.01.2010 03:04:05").IncludeTimeValue(); var operand = operandBuilder.CreateValueOperandForStringBasedSyntax(((BinaryExpression)expr.Body).Right); Assert.That(operand, Is.InstanceOf <DateTimeValueOperand>()); var valueOperand = operand as DateTimeValueOperand; Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.DateTime))); var expected = DateTime.Parse("02.01.2010 03:04:05"); Assert.That(valueOperand.Value, Is.EqualTo(expected)); Assert.That(valueOperand.IncludeTimeValue, Is.True); }
static Camlex() { // factories setup var operandBuilder = new OperandBuilder(); var operationResultBuilder = new OperationResultBuilder(); var analyzerFactory = new AnalyzerFactory(operandBuilder, operationResultBuilder); translatorFactory = new TranslatorFactory(analyzerFactory); // re var reoperandBuilder = new ReOperandBuilderFromCaml(); var reanalyzerFactory = new ReAnalyzerFromCamlFactory(reoperandBuilder); retranslatorFactory = new ReTranslatorFromCamlFactory(reanalyzerFactory); relinkerFactory = new ReLinkerFromCamlFactory(); }
public void Should_store_the_value_from_addr_plus_index() { // TODO: Crap test , doesn't check the address used to retrieve the array item is correct ushort addr = 1234; ushort index = 12; var args = new OperandBuilder() .WithArg(addr) .WithArg(index) .Build(); Operation.Execute(args); Mockery .ResultDestinationRetrievedFromPC() .ResultStoredWasByte(0); }
public void Should_return_property_length() { byte propInfo = 123; var expected = ZProperty.GetPropertySize(propInfo); Mockery .SetNextGet(propInfo); var args = new OperandBuilder() .WithArg(AnyVariable) .Build(); Operation.Execute(args); Mockery .ResultStored(expected); }
public void Should_print_the_text() { var args = new OperandBuilder() .WithArg(0) .Build(); Mockery .ZsciiStringReturns("some text"); Operation.Execute(args); Mockery .Printed("some text") ; }
public void Should_retrieve_variable_and_store() { const ushort value = 1234; Mockery .VariableRetrieves(value); var args = new OperandBuilder() .WithArg(AnyVariable) .Build(); Operation.Execute(args); Mockery .ResultDestinationRetrievedFromPC() .ResultStored(value); }
public void Should_print_the_text() { var args = new OperandBuilder() .WithArg(0) .Build(); Mockery .ZsciiStringReturns("some text"); Operation.Execute(args); Mockery // TODO: Check that a packed address was used .Printed("some text") ; }
public void When_no_routine_address_supplied_set_result_to_0() { const ushort packedRoutineAddress = 0; var args = new OperandBuilder() .WithArg(packedRoutineAddress) .Build(); Mockery .AssertStackIsEmpty(); Mockery .SetRoutineArgCount(0); Operation.Execute(args); Mockery .ResultDestinationRetrievedFromPC() .ResultStoredWasByte(0); }
public void Should_clear_attribute() { ushort obj = 1234; ushort attribute = 0x02; var args = new OperandBuilder() .WithArg(obj) .WithArg(attribute) .Build(); var zObj = new Mock <IZMachineObject>(); var zAttributes = new Mock <IZAttributes>(); zObj.Setup(z => z.Attributes).Returns(zAttributes.Object); Mockery.SetNextObject(zObj.Object); Operation.Execute(args); zAttributes.Verify(o => o.ClearAttribute((byte)It.Is <byte>(v => v == attribute))); }
public void Should_increment_value_and_NOT_jump() { ushort initialValue = 10; ushort comparison = 15; var args = new OperandBuilder() .WithArg(AnyValue) .WithArg(comparison) .Build(); Mockery.VariableRetrieves(initialValue); Operation.Execute(args); var expectedValue = (initialValue + 1); Mockery .ResultStored((ushort)expectedValue) .JumpedWith(false); }
public void Should_jump_if_objectA_is_child_of_objectB() { ushort parent = 1234; Mockery.SetNextObject( new ZMachineObjectBuilder() .WithParent(parent) .Build() ); var operands = new OperandBuilder() .WithAnyArg() .WithArg(parent) .Build(); Operation.Execute(operands); Mockery.JumpedWith(true); }
public void Should_print_the_object_name() { var args = new OperandBuilder() .WithArg(0) .Build(); var objectName = "My Object"; Mockery .SetNextObject(new ZMachineObjectBuilder() .WithName(objectName).Build()); Operation.Execute(args); Mockery // TODO: Check that a packed address was used .Printed(objectName) ; }
public void Should_remove_immediate_child() { ushort child = 20; ushort child2 = 25; ushort sibling = 30; ushort parent = 5; ushort objectToRemove = child; var(childZObj, parentZObj, _) = ZMachineObjectBuilder.BuildSimpleRelationship(parent, child, sibling, child2); Mockery .SetGetObject(child, childZObj) .SetGetObject(parent, parentZObj); var args = new OperandBuilder() .WithArg(objectToRemove) .Build(); Operation.Execute(args); parentZObj.Child.ShouldBe(childZObj.Sibling); childZObj.Parent.ShouldBe((ushort)0); }
public void SetUp() { testee = new OperandBuilder(); }
private IOperand createValueOperand(XElement operationElement, XElement valueElement, bool isComparision) { if (operationElement == null) { throw new ArgumentNullException("operationElement"); } if (valueElement == null) { throw new ArgumentNullException("valueElement"); } var typeAttr = valueElement.Attributes().FirstOrDefault(a => a.Name == Attributes.Type); if (typeAttr == null) { throw new CamlAnalysisException( string.Format( "Can't create value operand: Type attribute is missing. Xml which causes issue:\n{0}", valueElement)); } string typeName = string.Format("{0}.{1}+{2}, {3}", typeof(DataTypes).Namespace, typeof(DataTypes).Name, typeAttr.Value, typeof(DataTypes).Assembly.FullName); Type type = null; try { type = Type.GetType(typeName, false); } catch { type = null; } if (type == null) { throw new CamlAnalysisException( string.Format( "Can't create value operand: Type attribute '{0}' is incorrect type name. It should have CAML-compatible type name", typeAttr.Value)); } // DataTypes.Lookup is internal. Users should use LookupValue or LookupId. But in order to determine what exact type // should be used - we also need to analyze FieldRef operand because it contains LookupId="True" attribute (i.e. not Value // operand contains it) if (type == typeof(DataTypes.Lookup)) { type = typeof(DataTypes.LookupValue); var fieldRefElement = operationElement.Elements(Tags.FieldRef).FirstOrDefault(); if (fieldRefElement != null) { var lookupIdAttr = fieldRefElement.Attributes().FirstOrDefault(a => a.Name == Attributes.LookupId); if (lookupIdAttr != null) { bool isLookupId = false; if (bool.TryParse(lookupIdAttr.Value, out isLookupId) && isLookupId) { type = typeof(DataTypes.LookupId); } } } } //The same applies for LookupMulti if (type == typeof(DataTypes.LookupMulti)) { type = typeof(DataTypes.LookupMultiValue); var fieldRefElement = operationElement.Elements(Tags.FieldRef).FirstOrDefault(); if (fieldRefElement != null) { var lookupIdAttr = fieldRefElement.Attributes().FirstOrDefault(a => a.Name == Attributes.LookupId); if (lookupIdAttr != null) { bool isLookupId = false; if (bool.TryParse(lookupIdAttr.Value, out isLookupId) && isLookupId) { type = typeof(DataTypes.LookupMultiId); } } } } // The same about User and UserId. In direct-way translation, the developer should use either User or User ID, // but in referese-way translation, it should be determioned by LookupID="True" attribute if (type == typeof(DataTypes.User)) { var fieldRefElement = operationElement.Elements(Tags.FieldRef).FirstOrDefault(); if (fieldRefElement != null) { var lookupIdAttr = fieldRefElement.Attributes().FirstOrDefault(a => a.Name == Attributes.LookupId); if (lookupIdAttr != null) { bool isLookupId = false; if (bool.TryParse(lookupIdAttr.Value, out isLookupId) && isLookupId) { type = typeof(DataTypes.UserId); } } } } bool isIntegerForUserId = false; if (type == typeof(DataTypes.Integer)) { // DataTypes.Integer also can be used for <UserID />. See http://sadomovalex.blogspot.com/2011/08/camlexnet-24-is-released.html isIntegerForUserId = valueElement.Elements().Count() == 1 && valueElement.Elements().Any(e => e.Name == ReflectionHelper.UserID); } bool includeTimeValue = false; var includeTimeValueAttr = valueElement.Attributes().FirstOrDefault(a => a.Name == Attributes.IncludeTimeValue); if (includeTimeValueAttr != null) { if (!bool.TryParse(includeTimeValueAttr.Value, out includeTimeValue)) { throw new CamlAnalysisException( string.Format( "Can't create value operand: attribute '{0}' has incorrect value '{1}'. It should have boolean value", includeTimeValueAttr.Name, includeTimeValueAttr.Value)); } } string value = valueElement.Value; if (type == typeof(DataTypes.DateTime) && valueElement.Descendants().Count() == 1) { // for DateTime instead of real (Native) value there can be <Now />, <Today />, etc. // See the full list from DateTimeValueOperand value = valueElement.Descendants().First().Name.ToString(); } var convertedType = this.convertToNativeIfPossible(type); // currently only string-based value operand will be returned // todo: add support of native operands here (see OperandBuilder.CreateValueOperand() for details) return(OperandBuilder.CreateValueOperand( convertedType, value, includeTimeValue, true, isComparision, isIntegerForUserId)); }
public bool CompareShouldBeAffectedIgnoreCase(string left, string right, bool ignoreCase) { var expression = Expression.Constant(""); var result = new Equal <CustomEntity>("=", ignoreCase).Compare(expression, OperandBuilder.BuildUp(left), OperandBuilder.BuildUp(right)); return((bool)Expression.Lambda(result.Expression).Compile().DynamicInvoke()); }