예제 #1
0
        public void FeatureReceiverAddsWebPartTest()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                if (context.IsolationLevel == IsolationLevel.Fake)
                {
                    var webPartManager = new ShimSPLimitedWebPartManager();
                    new ShimSPWeb(context.Web)
                    {
                        GetLimitedWebPartManagerStringPersonalizationScope = (s, c) =>
                        {
                            return webPartManager;
                        },
                    };

                    webPartManager.WebPartsGet = () =>
                    {
                        var webPartCollection = new ShimSPLimitedWebPartCollection();
                        webPartCollection.ItemGetInt32 = (i) => { return new SalesOrderWebPart(); };

                        return webPartCollection.Instance;
                    };
                }

                var feature = context.Web.Features.FirstOrDefault(f => f.DefinitionId == featureId);
                if (feature == null)
                    context.Web.Features.Add(featureId);

                AssertIfWebpartOnPage(context, true);

                context.Web.Features.Remove(featureId);
            }
        }
        public void FeatureReceiverAddsWebPartTest()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                if (context.IsolationLevel == IsolationLevel.Fake)
                {
                    var webPartManager = new ShimSPLimitedWebPartManager();
                    new ShimSPWeb(context.Web)
                    {
                        GetLimitedWebPartManagerStringPersonalizationScope = (s, c) =>
                        {
                            return(webPartManager);
                        },
                    };

                    webPartManager.WebPartsGet = () =>
                    {
                        var webPartCollection = new ShimSPLimitedWebPartCollection();
                        webPartCollection.ItemGetInt32 = (i) => { return(new SalesOrderWebPart()); };

                        return(webPartCollection.Instance);
                    };
                }

                var feature = context.Web.Features.FirstOrDefault(f => f.DefinitionId == featureId);
                if (feature == null)
                {
                    context.Web.Features.Add(featureId);
                }

                AssertIfWebpartOnPage(context, true);

                context.Web.Features.Remove(featureId);
            }
        }
        public void GetWebPartByTypeName_WhenDifferentType_ReturnNull()
        {
            // Arrange
            var webPartManager = new ShimSPLimitedWebPartManager
            {
                WebPartsGet = () => new ShimSPLimitedWebPartCollection().Bind(new XsltListViewWebPart[]
                {
                    new ShimXsltListViewWebPart().Instance
                })
            }.Instance;

            // Act
            var result = ExtensionMethods.GetWebPartByTypeName(webPartManager, DummyString);

            // Assert
            result.ShouldBeNull();
        }
        public void GetWebPartByTypeName_OnValidCall_ConfirmResult()
        {
            // Arrange
            const string WebPartType    = "XsltListViewWebPart";
            var          webPartManager = new ShimSPLimitedWebPartManager
            {
                WebPartsGet = () => new ShimSPLimitedWebPartCollection().Bind(new XsltListViewWebPart[]
                {
                    new ShimXsltListViewWebPart().Instance
                })
            }.Instance;

            // Act
            var result = ExtensionMethods.GetWebPartByTypeName(webPartManager, WebPartType);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ShouldBeOfType(typeof(XsltListViewWebPart)));
        }