예제 #1
0
        public void UpdatesViewFromChildWebListView()
        {
            Web childWeb = null;

            TestCommon.RegisterPnPHttpClientMock();
            using (var ctx = TestCommon.CreateTestClientContext())
            {
                try
                {
                    childWeb = CreateTestTeamSubSite(ctx.Web);
                    childWeb.EnsureProperty(w => w.Id);
                    var docsList = childWeb.GetListByUrl(TestListUrl);
                    docsList.EnsureProperties(l => l.Id);
                    var wpXml =
                        $@"<webParts>
                        <webPart xmlns=""http://schemas.microsoft.com/WebPart/v3"">
                        <metaData>
                            <type name=""Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"" />
                            <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
                        </metaData>
                        <data>
                            <properties>
                            <property name=""ListId"" type=""System.Guid, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089"">{docsList.Id}</property>
                            <property name=""WebId"" type=""System.Guid, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089"">{childWeb.Id}</property>
                            <property name=""XmlDefinition"" type=""string""><![CDATA[
	                            <View Type=""HTML"" Name=""Unknown view name"" BaseViewID=""1"">
	                                {ViewXml}
                                </View>]]></property>
                            </properties>
                        </data>
                        </webPart>
                    </webParts>";

                    var webParts = CreateBasicWebPart(wpXml);

                    var file         = GetFile(ctx);
                    var wpDefinition = AddWebPart(file, wpXml);

                    var xsltPostProcessor = new XsltWebPartPostProcessor(webParts.WebPart);
                    xsltPostProcessor.Process(wpDefinition, file);

                    var view = childWeb.GetListByUrl(TestListUrl).GetViewById(wpDefinition.Id);

                    AssertViewIsValid(view);
                }
                finally
                {
                    if (childWeb != null && childWeb.Context != null)
                    {
                        childWeb.DeleteObject();
                        childWeb.Context.ExecuteQueryRetry();
                        childWeb.Context.Dispose();
                    }
                }
            }
        }
예제 #2
0
        private void CoreTest(string wpXml, ClientContext ctx)
        {
            var webParts = CreateBasicWebPart(wpXml);

            var file         = GetFile(ctx);
            var wpDefinition = AddWebPart(file, wpXml);

            var xsltPostProcessor = new XsltWebPartPostProcessor(webParts.WebPart);

            xsltPostProcessor.Process(wpDefinition, file);

            var view = ctx.Web.GetListByUrl(TestListUrl).GetViewById(wpDefinition.Id);

            AssertViewIsValid(view);
        }