本文整理汇总了C#中SPMeta2.Definitions.DefinitionBase.WithAssertAndCast方法的典型用法代码示例。如果您正苦于以下问题:C# DefinitionBase.WithAssertAndCast方法的具体用法?C# DefinitionBase.WithAssertAndCast怎么用?C# DefinitionBase.WithAssertAndCast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPMeta2.Definitions.DefinitionBase
的用法示例。
在下文中一共展示了DefinitionBase.WithAssertAndCast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
var spObject = GetField(modelHost, definition);
var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);
ValidateField(assert, spObject, definition);
var textField = spObject as SPFieldNumber;
var textDefinition = model.WithAssertAndCast<NumberFieldDefinition>("model", value => value.RequireNotNull());
var typedFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);
typedFieldAssert.ShouldBeEqual(m => m.MaximumValue, o => o.MaximumValue);
typedFieldAssert.ShouldBeEqual(m => m.MinimumValue, o => o.MinimumValue);
typedFieldAssert.ShouldBeEqual(m => m.ShowAsPercentage, o => o.ShowAsPercentage);
if (!string.IsNullOrEmpty(textDefinition.DisplayFormat))
typedFieldAssert.ShouldBeEqual(m => m.DisplayFormat, o => o.GetDisplayFormat());
else
typedFieldAssert.SkipProperty(m => m.DisplayFormat);
}
示例2: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
var spObject = GetField(modelHost, definition);
var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);
ValidateField(assert, spObject, definition);
var textField = spObject as SPFieldMultiLineText;
var textDefinition = model.WithAssertAndCast<NoteFieldDefinition>("model", value => value.RequireNotNull());
var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);
textFieldAssert.ShouldBeEqual(m => m.NumberOfLines, o => o.NumberOfLines);
textFieldAssert.ShouldBeEqual(m => m.RichText, o => o.RichText);
textFieldAssert.ShouldBeEqual(m => m.AppendOnly, o => o.AppendOnly);
textFieldAssert.ShouldBeEqual(m => m.RichText, o => o.RichText);
textFieldAssert.ShouldBeEqual(m => m.UnlimitedLengthInDocumentLibrary, o => o.UnlimitedLengthInDocumentLibrary);
if (!string.IsNullOrEmpty(textDefinition.RichTextMode))
textFieldAssert.ShouldBeEqual(m => m.RichTextMode, o => o.GetRichTextMode());
else
textFieldAssert.SkipProperty(m => m.RichTextMode);
}
示例3: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
var spObject = GetField(modelHost, definition);
var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);
ValidateField(assert, spObject, definition);
var textField = spObject.Context.CastTo<FieldDateTime>(spObject);
var textDefinition = model.WithAssertAndCast<DateTimeFieldDefinition>("model", value => value.RequireNotNull());
var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);
if (!string.IsNullOrEmpty(textDefinition.CalendarType))
textFieldAssert.ShouldBeEqual(m => m.CalendarType, o => o.GetCalendarType());
else
textFieldAssert.SkipProperty(m => m.CalendarType, "CalendarType is null or empty. Skipping.");
if (!string.IsNullOrEmpty(textDefinition.FriendlyDisplayFormat))
textFieldAssert.ShouldBeEqual(m => m.FriendlyDisplayFormat, o => o.GetFriendlyDisplayFormat());
else
textFieldAssert.SkipProperty(m => m.FriendlyDisplayFormat, "FriendlyDisplayFormat is null or empty. Skipping.");
if (!string.IsNullOrEmpty(textDefinition.DisplayFormat))
textFieldAssert.ShouldBeEqual(m => m.DisplayFormat, o => o.GetDisplayFormat());
else
textFieldAssert.SkipProperty(m => m.DisplayFormat, "FriendlyDisplayFormat is null or empty. Skipping.");
}
示例4: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
if (modelHost is WebModelHost)
{
var workflowWebSubscriptionModelHost = modelHost.WithAssertAndCast<WebModelHost>("modelHost", value => value.RequireNotNull());
var definition = model.WithAssertAndCast<SP2013WorkflowSubscriptionDefinition>("model", value => value.RequireNotNull());
var web = workflowWebSubscriptionModelHost.HostWeb;
var spObject = GetCurrentWebWorkflowSubscriptioBySourceId(workflowWebSubscriptionModelHost,
web,
web.ID,
definition);
ValidateWorkflowSubscription(modelHost, workflowWebSubscriptionModelHost.HostWeb, spObject, definition);
}
if (modelHost is ListModelHost)
{
var workflowSubscriptionModelHost = modelHost.WithAssertAndCast<ListModelHost>("modelHost", value => value.RequireNotNull());
var definition = model.WithAssertAndCast<SP2013WorkflowSubscriptionDefinition>("model", value => value.RequireNotNull());
var list = workflowSubscriptionModelHost.HostList;
var web = list.ParentWeb;
var spObject = GetCurrentWebWorkflowSubscriptioBySourceId(workflowSubscriptionModelHost,
web,
list.ID,
definition);
ValidateWorkflowSubscription(modelHost, web, spObject, definition);
}
}
示例5: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
var spObject = GetField(modelHost, definition);
var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);
ValidateField(assert, spObject, definition);
var typedField = spObject.Context.CastTo<FieldUser>(spObject);
var typedDefinition = model.WithAssertAndCast<UserFieldDefinition>("model", value => value.RequireNotNull());
var typedFieldAssert = ServiceFactory.AssertService.NewAssert(model, typedDefinition, typedField);
typedFieldAssert.ShouldBeEqual(m => m.AllowMultipleValues, o => o.AllowMultipleValues);
typedFieldAssert.ShouldBeEqual(m => m.AllowDisplay, o => o.AllowDisplay);
typedFieldAssert.ShouldBeEqual(m => m.Presence, o => o.Presence);
typedFieldAssert.ShouldBeEqual(m => m.SelectionMode, o => o.GetSelectionMode());
if (typedDefinition.SelectionGroup.HasValue)
{
typedFieldAssert.ShouldBeEqual(m => m.SelectionGroup, o => o.SelectionGroup);
}
else
{
typedFieldAssert.SkipProperty(m => m.SelectionGroup, "SelectionGroup is NULL. Skipping.");
}
if (!string.IsNullOrEmpty(typedDefinition.SelectionGroupName))
{
var web = ExtractWebFromHost(modelHost);
var context = web.Context;
var group = web.SiteGroups.GetByName(typedDefinition.SelectionGroupName);
context.Load(group);
context.ExecuteQueryWithTrace();
typedFieldAssert.ShouldBeEqual((p, s, d) =>
{
var srcProp = s.GetExpressionValue(m => m.SelectionGroupName);
var isValid = typedField.SelectionGroup == group.Id;
return new PropertyValidationResult
{
Tag = p.Tag,
Src = srcProp,
Dst = null,
IsValid = isValid
};
});
}
else
{
typedFieldAssert.SkipProperty(m => m.SelectionGroupName, "SelectionGroupName is NULL. Skipping.");
}
}
示例6: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
base.DeployModel(modelHost, model);
var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
var spObject = GetField(modelHost, definition);
var textField = spObject.Context.CastTo<FieldChoice>(spObject);
var textDefinition = model.WithAssertAndCast<ChoiceFieldDefinition>("model", value => value.RequireNotNull());
var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);
textFieldAssert.ShouldBeEqual(m => m.EditFormat, o => o.GetEditFormat());
}
示例7: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
var spObject = GetField(modelHost, definition);
var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);
ValidateField(assert, spObject, definition);
var textField = spObject as SPFieldBoolean;
var textDefinition = model.WithAssertAndCast<BooleanFieldDefinition>("model", value => value.RequireNotNull());
var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);
}
示例8: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var siteModelHost = modelHost.WithAssertAndCast<AdminSiteModelHost>("modelHost", value => value.RequireNotNull());
var o365SiteModel = model.WithAssertAndCast<O365SiteDefinition>("model", value => value.RequireNotNull());
DeployO365SiteCollection(modelHost, siteModelHost.HostClientContext, o365SiteModel);
}
示例9: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var securableObject = ExtractSecurableObject(modelHost);
var breakRoleInheritanceModel = model.WithAssertAndCast<BreakRoleInheritanceDefinition>("model", value => value.RequireNotNull());
ProcessRoleInheritance(modelHost, securableObject, breakRoleInheritanceModel);
}
示例10: DeployModelInternal
protected override void DeployModelInternal(object modelHost, DefinitionBase model)
{
var siteModelHost = modelHost.WithAssertAndCast<SiteModelHost>("modelHost", value => value.RequireNotNull());
var definitionModel = model.WithAssertAndCast<ContentTypeDefinition>("model", value => value.RequireNotNull());
var site = siteModelHost.HostSite;
var rootWeb = site.RootWeb;
var contentTypes = rootWeb.AvailableContentTypes;
var spModel = contentTypes[definitionModel.Name];
TraceUtils.WithScope(traceScope =>
{
Trace.WriteLine(string.Format("Validate model: {0} ContentType:{1}", definitionModel, spModel));
// assert base properties
traceScope.WithTraceIndent(trace =>
{
trace.WriteLine(string.Format("Validate Name: model:[{0}] ct:[{1}]", definitionModel.Name, spModel.Name));
Assert.AreEqual(definitionModel.Name, spModel.Name);
trace.WriteLine(string.Format("Validate Description: model:[{0}] ct:[{1}]", definitionModel.Description, spModel.Description));
Assert.AreEqual(definitionModel.Description, spModel.Description);
trace.WriteLine(string.Format("Validate Id: model:[{0}] ct:[{1}]", definitionModel.GetContentTypeId(), spModel.Id));
Assert.AreEqual(new SPContentTypeId(definitionModel.GetContentTypeId()), spModel.Id);
trace.WriteLine(string.Format("Validate Group: model:[{0}] ct:[{1}]", definitionModel.Group, spModel.Group));
Assert.AreEqual(definitionModel.Group, spModel.Group);
});
});
}
示例11: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var securableObject = ExtractSecurableObject(modelHost);
var definition = model.WithAssertAndCast<ResetRoleInheritanceDefinition>("model", value => value.RequireNotNull());
var context = securableObject.Context;
if (!securableObject.IsObjectPropertyInstantiated("HasUniqueRoleAssignments"))
{
context.Load(securableObject, s => s.HasUniqueRoleAssignments);
context.ExecuteQueryWithTrace();
}
var assert = ServiceFactory.AssertService
.NewAssert(definition, securableObject)
.ShouldNotBeNull(securableObject);
assert.ShouldBeEqual((p, s, d) =>
{
var dstProp = d.GetExpressionValue(m => m.HasUniqueRoleAssignments);
return new PropertyValidationResult
{
Tag = p.Tag,
Src = null,
Dst = dstProp,
IsValid = d.HasUniqueRoleAssignments == false
};
});
}
示例12: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var definition = model.WithAssertAndCast<EventReceiverDefinition>("model", value => value.RequireNotNull());
Microsoft.SharePoint.Client.EventReceiverDefinition spObject = null;
if (modelHost is ListModelHost)
spObject = FindEventReceiverDefinition((modelHost as ListModelHost).HostList.EventReceivers, definition);
else if (modelHost is WebModelHost)
spObject = FindEventReceiverDefinition((modelHost as WebModelHost).HostWeb.EventReceivers, definition);
else if (modelHost is SiteModelHost)
spObject = FindEventReceiverDefinition((modelHost as SiteModelHost).HostSite.EventReceivers, definition);
else
{
throw new SPMeta2UnsupportedModelHostException("model host should be ListModelHost or WebModelHost");
}
var assert = ServiceFactory.AssertService
.NewAssert(definition, spObject)
.ShouldNotBeNull(spObject)
.ShouldBeEqual(m => m.Name, o => o.ReceiverName)
.ShouldBeEqual(m => m.Class, o => o.ReceiverClass)
.ShouldBeEqual(m => m.Assembly, o => o.ReceiverAssembly)
.SkipProperty(m => m.Data, "Data property is not supported by CSOM. SKipping.")
.ShouldBeEqual(m => m.SequenceNumber, o => o.SequenceNumber)
.ShouldBeEqual(m => m.Synchronization, o => o.GetSynchronization())
.ShouldBeEqual(m => m.Type, o => o.GetEventReceiverType());
}
示例13: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var webAppModelHost = modelHost.WithAssertAndCast<WebApplicationModelHost>("modelHost", value => value.RequireNotNull());
var definition = model.WithAssertAndCast<PeoplePickerSettingsDefinition>("model", value => value.RequireNotNull());
DeployPeoplePickerSettings(modelHost, webAppModelHost.HostWebApplication, definition);
}
示例14: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
// base validation
base.DeployModel(modelHost, model);
// web specific validation
var host = modelHost.WithAssertAndCast<WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
var definition = model.WithAssertAndCast<PageViewerWebPartDefinition>("model", value => value.RequireNotNull());
var item = host.PageListItem;
WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
{
var web = spWebPartManager.Web;
var typedObject = spObject as PageViewerWebPart;
var assert = ServiceFactory.AssertService
.NewAssert(definition, typedObject)
.ShouldNotBeNull(typedObject);
if (!string.IsNullOrEmpty(definition.ContentLink))
assert.ShouldBeEqual(m => m.ContentLink, o => o.ContentLink);
else
assert.SkipProperty(m => m.ContentLink);
if (!string.IsNullOrEmpty(definition.SourceType))
assert.ShouldBeEqual(m => m.SourceType, o => o.GetSourceType());
else
assert.SkipProperty(m => m.SourceType);
});
}
示例15: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var securableObject = modelHost.WithAssertAndCast<SecurableObject>("modelHost", value => value.RequireNotNull());
var securityGroupLinkModel = model.WithAssertAndCast<SecurityGroupLinkDefinition>("model", value => value.RequireNotNull());
var web = GetWebFromSPSecurableObject(securableObject);
var context = web.Context;
context.Load(web, w => w.SiteGroups);
context.Load(securableObject, s => s.RoleAssignments.Include(r => r.Member));
context.ExecuteQuery();
var securityGroup = WebExtensions.FindGroupByName(web.SiteGroups, securityGroupLinkModel.SecurityGroupName);
TraceUtils.WithScope(traceScope =>
{
traceScope.WriteLine(string.Format("Validate model:[{0}] securableObject:[{1}]", securityGroupLinkModel, securityGroup));
traceScope.WithTraceIndent(trace =>
{
// asserting it exists
trace.WriteLine(string.Format("Validating existance..."));
var existingRoleAssignments = FindClientRoleRoleAssignment(securableObject.RoleAssignments, securityGroup);
Assert.IsNotNull(existingRoleAssignments);
trace.WriteLine(string.Format("RoleAssignments for security group link [{0}] exists.", securityGroupLinkModel.SecurityGroupName));
});
});
}