public void test_THAT_membership_operation_with_spgroup_IS_converted_to_expression_correctly()
        {
            var op1      = new FieldRefOperand("Field");
            var mt       = new Camlex.SPGroup(2);
            var typeName = mt.GetType().Name;
            var op       = new MembershipOpeartion(null, op1, mt);

            var expr = op.ToExpression();

            Assert.That(expr.ToString(),
                        Is.EqualTo(string.Format("Membership(x.get_Item(\"Field\"), new {0}({1}))", typeName, 2)));
        }
예제 #2
0
        public override IOperation GetOperation()
        {
            if (!this.IsValid())
            {
                throw new CamlAnalysisException(string.Format(
                                                    "Can't create {0} from the following xml: {1}", typeof(MembershipOpeartion).Name, el));
            }

            var fieldRefElement = el.Elements(Tags.FieldRef).First();
            var typeAttribute   = el.Attributes(Attributes.Type).First();

            var fieldRefOperand = operandBuilder.CreateFieldRefOperand(fieldRefElement);

            Camlex.MembershipType membershipType = null;

            switch (typeAttribute.Value)
            {
            case Camlex.Membership_SPWebAllUsers:
                membershipType = new Camlex.SPWebAllUsers();
                break;

            case Camlex.Membership_SPGroup:
                var groupId = int.Parse(el.Attributes(Attributes.ID).First().Value);
                membershipType = new Camlex.SPGroup(groupId);
                break;

            case Camlex.Membership_SPWebGroups:
                membershipType = new Camlex.SPWebGroups();
                break;

            case Camlex.Membership_CurrentUserGroups:
                membershipType = new Camlex.CurrentUserGroups();
                break;

            case Camlex.Membership_SPWebUsers:
                membershipType = new Camlex.SPWebUsers();
                break;
            }


            return(new MembershipOpeartion(null,
                                           fieldRefOperand, membershipType));
        }