Exemple #1
0
        public override void DeployModel(object modelHost, Definitions.DefinitionBase model)
        {
            var listItemModelHost = modelHost.WithAssertAndCast <ListItemFieldValueModelHost>("modelHost", value => value.RequireNotNull());
            var fieldValue        = model.WithAssertAndCast <ListItemFieldValueDefinition>("model", value => value.RequireNotNull());

            ProcessFieldValue(listItemModelHost, listItemModelHost.CurrentItem, fieldValue);
        }
        public override void DeployModel(object modelHost, Definitions.DefinitionBase model)
        {
            var list          = modelHost.WithAssertAndCast <List>("modelHost", value => value.RequireNotNull());
            var listItemModel = model.WithAssertAndCast <ListItemDefinition>("model", value => value.RequireNotNull());

            ValidateModel(list, listItemModel);
        }
        public override void DeployModel(object modelHost, Definitions.DefinitionBase model)
        {
            var listItemModelHost = modelHost.WithAssertAndCast <ListItemFieldValueModelHost>("modelHost", value => value.RequireNotNull());
            var definition        = model.WithAssertAndCast <ListItemFieldValueDefinition>("model", value => value.RequireNotNull());

            var spObject = listItemModelHost.CurrentItem;

            var assert = ServiceFactory.AssertService
                         .NewAssert(definition, spObject)
                         .ShouldNotBeNull(spObject);

            if (definition.FieldId.HasValue)
            {
                assert.SkipProperty(m => m.Value, string.Format("Skip validation FieldId to get field value is not supported by CSOM."));
                assert.SkipProperty(m => m.FieldId, "Skip validation FieldId to get field value is not supported by CSOM.");

                //assert.ShouldBeEqual((p, s, d) =>
                //{
                //    var srcProp = s.GetExpressionValue(m => m.FieldId);

                //    return new PropertyValidationResult
                //    {
                //        Tag = p.Tag,
                //        Src = srcProp,
                //        Dst = null,
                //        IsValid = object.Equals(s.Value, d[s.FieldId.Value])
                //    };
                //});

                //assert.SkipProperty(m => m.Value, string.Format("Value validated with FieldId and actual value:[{0}]", spObject[definition.FieldId.Value]));
            }
            else
            {
                assert.SkipProperty(m => m.FieldId, "FieldId is null. Skipping.");
            }

            if (!string.IsNullOrEmpty(definition.FieldName))
            {
                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.FieldName);

                    return(new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = object.Equals(s.Value, d[s.FieldName])
                    });
                });

                assert.SkipProperty(m => m.Value, string.Format("Value validated with FieldName and actual value:[{0}]", spObject[definition.FieldName]));
            }
            else
            {
                assert.SkipProperty(m => m.FieldName, "FieldName is null. Skipping.");
            }
        }
        public override void DeployModel(object modelHost, Definitions.DefinitionBase model)
        {
            var listItemModelHost = modelHost.WithAssertAndCast <ListItemModelHost>("modelHost", value => value.RequireNotNull());
            var definition        = model.WithAssertAndCast <ListItemFieldValuesDefinition>("model", value => value.RequireNotNull());

            var spObject = listItemModelHost.HostListItem;

            var assert = ServiceFactory.AssertService
                         .NewAssert(definition, spObject)
                         .ShouldNotBeNull(spObject);

            if (definition.Values.Count > 0)
            {
                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(def => def.Values);

                    var isValid = true;

                    foreach (var value in definition.Values)
                    {
                        if (spObject[value.FieldName].ToString() != value.Value.ToString())
                        {
                            isValid = false;
                            break;
                        }
                    }

                    return(new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    });
                });
            }
            else
            {
                assert.SkipProperty(m => m.Values, "Values.Count == 0. Skipping");
            }
        }