Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PnP.Framework.Provisioning.Model;
using PnP.Framework.Provisioning.ObjectHandlers;
using PnP.Framework.Provisioning.Providers.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -212,6 +213,31 @@ public void CanProvisionObjects()
}
}


[TestMethod]
public void CanExportListLevelContentTypes()
{
using (var ctx = TestCommon.CreateClientContext())
{
var web = ctx.Web;

// Export the template
var template = new ProvisioningTemplate();
var creationInfo = new ProvisioningTemplateCreationInformation(ctx.Web);
creationInfo.HandlersToProcess= Handlers.Lists|Handlers.ContentTypes;
listName = "My Test";
creationInfo.ListsToExtract = new List<string> { listName };
template = new ObjectListInstance(FieldAndListProvisioningStepHelper.Step.Export).ExtractObjects(ctx.Web, template, creationInfo);
var xml = template.ToXML();

// Verify that the template contains the list
var exportedList = template.Lists.FirstOrDefault(l => l.Title == listName);
Assert.IsNotNull(exportedList.ContentTypeBindings, "content types should be in the exported template");
Console.WriteLine("\nGenerated XML (first 2000 chars):");
Console.WriteLine(xml.Substring(0, Math.Min(2000, xml.Length)));
}
}

[TestMethod]
public void CanCreateEntities()
{
Expand Down Expand Up @@ -280,6 +306,96 @@ public void CanTokensBeUsedInListInstance()
}
}

[TestMethod]
public void CanApplyListInstanceWithListContentTypeFieldRefSettings()
{
var contentTypeName = $"Sequential Approval";
var listUrl = $"Lists/Test Flow History";

using (var ctx = TestCommon.CreateClientContext())
{
void CleanupAppliedListInstanceTemplateArtifacts()
{
var list = ctx.Web.GetListByUrl(listUrl);
if (list != null)
{
list.DeleteObject();
ctx.ExecuteQueryRetry();
}

var webContentTypes = ctx.LoadQuery(ctx.Web.ContentTypes.Where(ct => ct.Name == contentTypeName));
ctx.ExecuteQueryRetry();
var createdContentType = webContentTypes.FirstOrDefault();
if (createdContentType != null)
{
createdContentType.DeleteObject();
ctx.ExecuteQueryRetry();
}

var fieldIds = new[]
{
new Guid("50e30439-74bf-47f9-8b6a-eb5adf43f7ed"),
new Guid("186ded6c-06bf-4b6f-bec3-5b1c1ea3f376"),
new Guid("813a56bf-4a89-4b7b-9fcb-2bb5a89eec56"),
new Guid("61b240e9-4544-4a7b-b86b-d5f1c6c5f772"),
};

ctx.Load(ctx.Web.Fields, fs => fs.Include(f => f.Id));
ctx.ExecuteQueryRetry();
var fields = ctx.Web.Fields.Where(f => fieldIds.Contains(f.Id)).ToList();
if (fields.Any())
{
foreach (var field in fields)
{
field.DeleteObject();
}
ctx.ExecuteQueryRetry();
}
}

var provider = new XMLFileSystemTemplateProvider(
String.Format(@"{0}\..\..\..\Resources", AppDomain.CurrentDomain.BaseDirectory),
"Templates");

var template = provider.GetTemplate(
"ProvisioningTemplate-2026-04-Sample-01-test.xml",
new PnP.Framework.Provisioning.Providers.Xml.XMLPnPSchemaV202604Serializer());
template.Connector = provider.Connector;


var applyingInformation = new ProvisioningTemplateApplyingInformation
{
HandlersToProcess = Handlers.Fields | Handlers.ContentTypes | Handlers.Lists
};

try
{
ctx.Web.ApplyProvisioningTemplate(template, applyingInformation);

var list = ctx.Web.GetListByUrl(listUrl);
var contentTypes = list.EnsureProperty(l => l.ContentTypes);
var myct = contentTypes.FirstOrDefault(ct => ct.Name == contentTypeName);

Assert.IsNotNull(myct);

ctx.Load(myct, ct => ct.FieldLinks.Include(fl => fl.Id, fl => fl.Required));
ctx.Load(list.Fields, fs => fs.Include(f => f.Id, f => f.Title));
ctx.ExecuteQueryRetry();

var taskDueDateField = list.Fields.FirstOrDefault(f => f.Title == "Task Due Date");
Assert.IsNotNull(taskDueDateField);

var taskDueDateFieldLink = myct.FieldLinks.FirstOrDefault(fl => fl.Id == taskDueDateField.Id);
Assert.IsNotNull(taskDueDateFieldLink);
Assert.IsTrue(taskDueDateFieldLink.Required);
}
finally
{
CleanupAppliedListInstanceTemplateArtifacts();
}
}
}

[TestMethod]
public void FolderContentTypeShouldNotBeRemovedFromProvisionedDocumentLibraries()
{
Expand Down
Loading