本文整理汇总了C#中SharePointPnP.PowerShell.Tests.PSTestScope类的典型用法代码示例。如果您正苦于以下问题:C# PSTestScope类的具体用法?C# PSTestScope怎么用?C# PSTestScope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PSTestScope类属于SharePointPnP.PowerShell.Tests命名空间,在下文中一共展示了PSTestScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFieldTest
public void AddFieldTest()
{
using (var ctx = TestCommon.CreateClientContext())
{
using (var scope = new PSTestScope(true))
{
scope.ExecuteCommand("Add-SPOField",
new CommandParameter("DisplayName", "PSCmdletTestField"),
new CommandParameter("InternalName", "PSCmdletTestField"),
new CommandParameter("Type", FieldType.Text),
new CommandParameter("Group", "Test Group"));
}
var succeeded = false;
try
{
var field = ctx.Web.Fields.GetByInternalNameOrTitle("PSCmdletTestField");
ctx.ExecuteQueryRetry();
succeeded = true;
field.DeleteObject();
ctx.ExecuteQueryRetry();
}
catch { }
Assert.IsTrue(succeeded);
}
}
示例2: AddEventReceiverTest
public void AddEventReceiverTest()
{
using (var scope = new PSTestScope(true))
{
scope.ExecuteCommand("Add-PnPEventReceiver",
new CommandParameter("Name", "TestEventReceiver"),
new CommandParameter("Url", "https://testserver.com/testeventreceiver.svc"),
new CommandParameter("EventReceiverType", EventReceiverType.ListAdded),
new CommandParameter("Synchronization", EventReceiverSynchronization.Asynchronous));
using (var ctx = TestCommon.CreateClientContext())
{
var receiver = ctx.Web.GetEventReceiverByName("TestEventReceiver");
Assert.IsNotNull(receiver);
Assert.IsTrue(receiver.ReceiverUrl == "https://testserver.com/testeventreceiver.svc");
Assert.IsTrue(receiver.EventType == EventReceiverType.ListAdded);
Assert.IsTrue(receiver.Synchronization == EventReceiverSynchronization.Asynchronous);
receiver.DeleteObject();
ctx.ExecuteQueryRetry();
}
}
}
示例3: AddWebPartToWikiPageTest
public void AddWebPartToWikiPageTest()
{
using (var scope = new PSTestScope(true))
{
using (var ctx = TestCommon.CreateClientContext())
{
var results = scope.ExecuteCommand("Add-SPOWebPartToWikiPage",
new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
new CommandParameter("Path", "..\\..\\Resources\\webpart.xml"),
new CommandParameter("Row", 1),
new CommandParameter("Column", 1));
Assert.IsFalse(results.Any());
var wps = ctx.Web.GetWebParts(serverRelativeHomePageUrl);
foreach (var wp in wps)
{
if (wp.WebPart.Title == "Get started with your site")
{
wp.DeleteWebPart();
ctx.ExecuteQueryRetry();
break;
}
}
}
}
}
示例4: InvokeWebActionListAction
public void InvokeWebActionListAction()
{
using (var scope = new PSTestScope(true))
{
List<string> listNames = new List<string>();
Action<List> listAction = list =>
{
listNames.Add(list.Title);
};
var results = scope.ExecuteCommand("Invoke-SPOWebAction",
new CommandParameter("ListAction", listAction),
new CommandParameter("ListProperties", new[] { "Title" })
);
Assert.IsTrue(listNames.Count > 3, "Wrong count on lists");
Assert.IsTrue(listNames.Contains("PnPTestList1"), "PnPTestList1 is missing");
Assert.IsTrue(listNames.Contains("PnPTestList2"), "PnPTestList2 is missing");
Assert.IsTrue(listNames.Contains("PnPTestList3"), "PnPTestList3 is missing");
InvokeWebActionResult result = results.Last().BaseObject as InvokeWebActionResult;
AssertInvokeActionResult(result,
processedWebCount: 1
);
Assert.IsTrue(result.ProcessedListCount > 3, "Wrong count on proccessed list");
}
}
示例5: GetWebPartPropertyTest
public void GetWebPartPropertyTest()
{
using (var scope = new PSTestScope(true))
{
using (var ctx = TestCommon.CreateClientContext())
{
var wps = ctx.Web.GetWebParts(serverRelativeHomePageUrl);
if (wps.Any())
{
var wp = wps.FirstOrDefault();
var results = scope.ExecuteCommand("Get-SPOWebPartProperty",
new CommandParameter("ServerRelativePageUrl", serverRelativeHomePageUrl),
new CommandParameter("Identity", wp.Id));
Assert.IsTrue(results.Count > 0);
Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Commands.PropertyBagValue));
}
else
{
Assert.Fail("No webparts on page.");
}
}
}
}
示例6: AddFieldFromXmlTest
public void AddFieldFromXmlTest()
{
var xml = @"<Field Type=""Text"" Name=""PSCmdletTest"" DisplayName=""PSCmdletTest"" ID=""{27d81055-f208-41c9-a976-61c5473eed4a}"" Group=""Test"" Required=""FALSE"" StaticName=""PSCmdletTest"" />";
using (var ctx = TestCommon.CreateClientContext())
{
using (var scope = new PSTestScope(true))
{
scope.ExecuteCommand("Add-SPOFieldFromXml",
new CommandParameter("FieldXml", xml));
}
var succeeded = false;
try
{
var field = ctx.Web.Fields.GetByInternalNameOrTitle("PSCmdletTest");
ctx.ExecuteQueryRetry();
succeeded = true;
field.DeleteObject();
ctx.ExecuteQueryRetry();
}
catch { }
Assert.IsTrue(succeeded);
}
}
示例7: GetFeatureTest
public void GetFeatureTest()
{
using (var ctx = TestCommon.CreateClientContext())
{
var isActive = ctx.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
if (!isActive)
{
ctx.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
}
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Get-PnPFeature",
new CommandParameter("Identity", Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID));
Assert.IsTrue(results.Any());
}
if (!isActive)
{
ctx.Web.DeactivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
}
}
}
示例8: DisableFeatureTest
public void DisableFeatureTest()
{
using (var ctx = TestCommon.CreateClientContext())
{
var isActive = ctx.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
if (!isActive)
{
ctx.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
}
using (var scope = new PSTestScope(true))
{
scope.ExecuteCommand("Disable-PnPFeature",
new CommandParameter("Identity", Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID));
}
Assert.IsFalse(ctx.Web.IsFeatureActive(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID));
if (isActive)
{
ctx.Web.ActivateFeature(Core.Constants.MINIMALDOWNLOADSTRATEGYFEATUREID);
}
}
}
示例9: GetEventReceiverTest
public void GetEventReceiverTest()
{
using (var scope = new PSTestScope(true))
{
EventReceiverDefinition receiver = null;
using (var ctx = TestCommon.CreateClientContext())
{
receiver = ctx.Web.AddRemoteEventReceiver("TestEventReceiver", "https://testserver.com/testeventreceiver.svc", EventReceiverType.ListAdded, EventReceiverSynchronization.Asynchronous, true);
}
var results = scope.ExecuteCommand("Get-PnPEventReceiver");
Assert.IsTrue(results.Any());
Assert.IsTrue(results[0].BaseObject.GetType() == typeof(EventReceiverDefinition));
results = scope.ExecuteCommand("Get-PnPEventReceiver",
new CommandParameter("Identity", receiver.ReceiverId));
Assert.IsTrue(results.Any());
using (var ctx = TestCommon.CreateClientContext())
{
receiver = ctx.Web.GetEventReceiverByName("TestEventReceiver");
receiver.DeleteObject();
ctx.ExecuteQueryRetry();
}
}
}
示例10: GetTimeZoneIdTest1
public void GetTimeZoneIdTest1()
{
using (var scope = new PSTestScope(false))
{
var results = scope.ExecuteCommand("Get-PnPTimeZoneId");
Assert.IsTrue(results.Count > 0);
}
}
示例11: GetTimeZoneIdTest2
public void GetTimeZoneIdTest2()
{
using (var scope = new PSTestScope(false))
{
var results = scope.ExecuteCommand("Get-PnPTimeZoneId", new CommandParameter("Match", "Stockholm"));
Assert.IsTrue(results.Count == 1);
}
}
示例12: GetTenantSiteTest
public void GetTenantSiteTest()
{
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Get-PnPTenantSite");
Assert.IsTrue(results.Count > 0);
}
}
示例13: GetWebTemplatesTest
public void GetWebTemplatesTest()
{
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Get-SPOWebTemplates");
Assert.IsTrue(results.Count > 0);
Assert.IsTrue(results[0].BaseObject.GetType().Equals(typeof(Microsoft.Online.SharePoint.TenantAdministration.SPOTenantWebTemplate)));
}
}
示例14: ApplyPnpTemplateFromFolder
public void ApplyPnpTemplateFromFolder()
{
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Apply-PnPProvisioningTemplate",
new CommandParameter("Path", @"dummy.pnp")
);
}
}
示例15: GetWebTemplatesTest
public void GetWebTemplatesTest()
{
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Get-PnPWebTemplates", new CommandParameter("Lcid", "1033"), new CommandParameter("CompatibilityLevel", "15"));
Assert.IsTrue(results.Count > 0);
Assert.IsTrue(results[0].BaseObject.GetType().Equals(typeof(Microsoft.Online.SharePoint.TenantAdministration.SPOTenantWebTemplate)));
}
}