private void InstallListsFieldsCommon(
            bool verifyOnly,
            bool overWrite,
            bool newField,
            string typeAsString,
            string expectedRow03,
            string expectedRow13,
            string expectedRow14)
        {
            // Arrange
            var appDef = new ApplicationDef();
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml($"<root><Fields><Field InternalName='internalName' Overwrite='{overWrite}' Total='total'><Field Type='Boolean' DisplayName='displayName'><CHOICES><CHOICE/></CHOICES></Field></Field></Fields></root>");
            var ndList = xmlDoc.FirstChild;

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);

            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) => newField ? null : new ShimSPFieldChoice();
            ShimSPField.AllInstances.TypeAsStringGet = _ => typeAsString;
            ShimSPField.AllInstances.TypeGet         = _ => SPFieldType.Choice;

            // Act
            _privateObject.Invoke(InstallListsFieldsMethod, new object[] { new ShimSPList().Instance, ndList, 0 });
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(2, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);
        }
コード例 #2
0
        private void InstallListsViewsCommon(
            bool verifyOnly,
            bool hasView,
            bool overWrite,
            string expectedRow03,
            string expectedRow13,
            string expectedRow14)
        {
            // Arrange
            var appDef = new ApplicationDef();
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml($"<root><Views><View Name='name' Overwrite='{overWrite}'><Fields></Fields></View></Views></root>");
            var ndList = xmlDoc.FirstChild;

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);

            ShimSPViewCollection.AllInstances.ItemGetString = (_, __) => hasView ? new ShimSPView(): null;

            // Act
            _privateObject.Invoke(InstallListsViewsMethod, new object[] { new ShimSPList().Instance, ndList, 0 });
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(2, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);
        }
コード例 #3
0
        private void InstallListsLookupsCommon(
            bool verifyOnly,
            bool overWrite,
            bool hasParentList,
            bool newField,
            bool deleteIfNoList,
            bool isLookUp,
            int expectedRowCount,
            string expectedRow03,
            string expectedRow13,
            string expectedRow14,
            string expectedRow23)
        {
            // Arrange
            var firstCall = true;
            var appDef    = new ApplicationDef();
            var xmlDoc    = new XmlDocument();

            xmlDoc.LoadXml($"<root><Lookups><Lookup InternalName='internalName' Overwrite='{overWrite}' DisplayName='displayName' AdvancedLookup='advancedLookup' DeleteIfNoList='{deleteIfNoList}'/></Lookups></root>");
            var ndList = xmlDoc.FirstChild;

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);

            ShimSPListCollection.AllInstances.TryGetListString = (_, __) => hasParentList ? new ShimSPList() : null;
            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) =>
            {
                if (!firstCall)
                {
                    return(new ShimSPFieldLookup());
                }

                firstCall = false;
                return(newField ? null : new ShimSPFieldLookup());
            };
            ShimSPField.AllInstances.TypeGet      = _ => isLookUp ? SPFieldType.Lookup : SPFieldType.Invalid;
            ShimSPField.AllInstances.SchemaXmlGet = _ => @"
<root List='' ShowField= ''>
</root>";

            // Act
            _privateObject.Invoke(iInstallListsLookupsMethod, new object[] { new ShimSPList().Instance, ndList, 0 });
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(expectedRowCount, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);
            if (expectedRowCount > 2)
            {
                Assert.AreEqual(expectedRow23, dtMessages.Rows[2][3]);
            }
        }
        private void CheckPermissionsCommon(
            bool verifyOnly,
            bool overWrite,
            bool isInstalledElsewhere,
            bool hasPermissions,
            bool hasSolutions,
            bool isSiteAdmin,
            bool expected,
            string expectedRow03,
            string expectedRow04)
        {
            // Arrange
            var appDef = new ApplicationDef();
            var xml    = new StringBuilder();

            xml.Append("<root>")
            .Append("<Solutions>")
            .Append(hasSolutions ? "<Solution/>" : string.Empty)
            .Append("</Solutions>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);
            _privateObject.SetFieldOrProperty(IsInstalledElsewhereProp, isInstalledElsewhere);
            _privateObject.SetFieldOrProperty(ConfigJobProp, new ShimInstallAndConfigure().Instance);

            xml.Clear();
            xml.Append("<root>")
            .Append("<rs:data xmlns:rs='http://www.w3.org/TR/html4/' ItemCount='1'>")
            .Append("<z:row xmlns:z='http://www.w3.org/TR/html4/' ows_FSObjType='ows_FSObjType' ows_FileRef='ows_FileRef' ows_FileLeafRef='ows_FileLeafRef' ows_Title='ows_Title'/>")
            .Append("</rs:data>")
            .Append("</root>");
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml.ToString());

            ShimLists.Constructor = _ => { };
            ShimLists.AllInstances.GetListItemsStringStringXmlNodeXmlNodeStringXmlNodeString = (a, b, c, d, e, f, g, h) => xmlDoc.FirstChild;
            ShimSPSecurableObject.AllInstances.DoesUserHavePermissionsSPBasePermissions      = (a, b) => hasPermissions;
            ShimSPUser.AllInstances.IsSiteAdminGet = _ => isSiteAdmin;

            // Act
            var actual     = (bool)_privateObject.Invoke(CheckPermissionsMethod);
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.AreEqual(expected, actual);
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(1, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow04, dtMessages.Rows[0][4]);
        }
        private void iInstallListsCommon(
            bool verifyOnly,
            bool canUpgrade,
            bool hasNoDelete,
            bool isListExist,
            int rowCount,
            string expectedRow03,
            string expectedRow13,
            string expectedRow14,
            string expectedRow23,
            string expectedRow24)
        {
            // Arrange
            var guids  = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            var scopes = new[] { SPFeatureScope.Site, SPFeatureScope.Site, SPFeatureScope.Web, SPFeatureScope.Web };
            var i      = 0;
            var k      = 0;
            var appDef = new ApplicationDef();
            var xml    = new StringBuilder();

            xml.Append("<root>")
            .Append("<Lists>")
            .AppendFormat("<List Name='name' CanUpgrade='{0}' Reporting='true' Template='template' ", canUpgrade)
            .Append(hasNoDelete ? "NoDelete=''" :string.Empty)
            .Append(" />")
            .Append("</Lists>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);

            ShimSPListCollection.AllInstances.TryGetListString = (a, b) => isListExist ? new ShimSPList() : null;

            // Act
            _privateObject.Invoke(iInstallListsMethod);
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(rowCount, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);
            if (rowCount > 2)
            {
                Assert.AreEqual(expectedRow23, dtMessages.Rows[2][3]);
                Assert.AreEqual(expectedRow24, dtMessages.Rows[2][4]);
            }
        }
        private void iInstallFilesCommon(
            bool verifyOnly,
            bool overWrite,
            string expectedRow03,
            string expectedRow13,
            string expectedRow14)
        {
            // Arrange
            var expectedOuterXml = "<Files><File Name=\"lookupValue\" RemoteFile=\"lookupValue\" Overwrite=\"True\" NoDelete=\"true\" Type=\"lookupValue\" FullFile=\"lookupValue\" /></Files>";
            var appDef           = new ApplicationDef();
            var xml = new StringBuilder();

            xml.Append("<root>")
            .Append("<Files>")
            .Append("<File Path='lookupValue' Overwrite='true' NoDelete='true'/>")
            .Append("</Files>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);

            xml.Clear();
            xml.Append("<root>")
            .Append("<rs:data xmlns:rs='http://www.w3.org/TR/html4/' ItemCount='1'>")
            .Append("<z:row xmlns:z='http://www.w3.org/TR/html4/' ows_FSObjType='ows_FSObjType' ows_FileRef='ows_FileRef' ows_FileLeafRef='ows_FileLeafRef' ows_Title='ows_Title'/>")
            .Append("</rs:data>")
            .Append("</root>");
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml.ToString());

            ShimLists.Constructor = _ => { };
            ShimLists.AllInstances.GetListItemsStringStringXmlNodeXmlNodeStringXmlNodeString = (a, b, c, d, e, f, g, h) => xmlDoc.FirstChild;

            // Act
            var actual     = _privateObject.Invoke(iInstallFilesMethod) as XmlNode;
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedOuterXml, actual.OuterXml);

            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(2, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);
        }
コード例 #7
0
        private void iInstallFilesProcessFolderCommon(
            bool verifyOnly,
            bool overWrite,
            bool skipReports,
            bool folderExist,
            int typeValue,
            bool fileExist,
            string pathValue,
            string expectedRow03)
        {
            // Arrange
            var xml         = new StringBuilder();
            var xmlDocument = new XmlDocument();

            xml.Append("<Folders>")
            .AppendFormat("<Folder RemoteFile='{0}' Type='{1}' Name='Report Library' Overwrite='false'/>", pathValue, typeValue)
            .Append("</Folders>");

            xmlDocument.LoadXml(xml.ToString());
            var ndFolder = xmlDocument.FirstChild;

            var appDef = new ApplicationDef();

            xml.Clear();
            xml.Append("<root>")
            .Append("<Lists>")
            .Append("</Lists>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);

            ShimSPWeb.AllInstances.IDGet = _ => skipReports?Guid.NewGuid() : Guid.Empty;

            ShimSPFolder.AllInstances.ExistsGet = _ => folderExist;
            ShimSPFile.AllInstances.ExistsGet   = _ => fileExist;

            // Act
            _privateObject.Invoke(iInstallFilesProcessFolderMethod, new object[] { 0, 0, ndFolder, 0, new ShimAppStore().Instance, overWrite });
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(1, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
        }
コード例 #8
0
        private void InstallAndConfigureApp(
            bool hasItems,
            bool hasAppList,
            int community,
            bool verifyOnly,
            bool overWrite,
            int rowCount,
            string expectedRow03,
            string expectedRow04)

        {
            // Arrange
            var appDef = new ApplicationDef
            {
                Community = "community",
                Version   = "version"
            };
            var xml = new StringBuilder();

            xml.Append("<root>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);
            _privateObject.SetFieldOrProperty(AppListProp, hasAppList ? new ShimSPList().Instance : null);

            ShimSPListItem.AllInstances.IDGet = _ => community;
            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) => new ShimSPField();
            ShimSPListItemCollection.AllInstances.CountGet     = _ => hasItems ? 1 : 0;
            ShimSPListItemCollection.AllInstances.ItemGetInt32 = (a, b) => new ShimSPListItem();
            ShimSPSecurableObject.AllInstances.DoesUserHavePermissionsSPBasePermissions = (a, b) => true;
            ShimSPListItem.AllInstances.ItemGetString          = (a, b) => "PreCheck Queued";
            ShimSPListCollection.AllInstances.TryGetListString = (_, __) => new ShimSPList();

            // Act
            _applicationInstaller.InstallAndConfigureApp(verifyOnly, new ShimSPWeb().Instance, 0);
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(rowCount, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow04, dtMessages.Rows[0][4]);
        }
コード例 #9
0
        private void InstallPropertiesCommon(
            bool verifyOnly,
            bool append,
            bool overWrite,
            string values,
            bool containsKey,
            string expectedRow03,
            string expectdRow13,
            string expectedRow14)
        {
            // Arrange
            var appDef = new ApplicationDef();
            var xml    = new StringBuilder();

            xml.Append("<root>")
            .Append("<Web>")
            .Append("<Properties>")
            .AppendFormat("<Property Name='name' Value='value' Append='{0}' Overwrite='{1}' LockWebProperty='false' Seperator='\\0' DuplicateRegEx=''>", append, overWrite)
            .Append("</Property>")
            .Append("</Properties>")
            .Append("</Web>")
            .Append("</root>");

            appDef.ApplicationXml.LoadXml(xml.ToString());
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);

            ShimCoreFunctions.getConfigSettingSPWebString       = (a, b) => values;
            ShimStringDictionary.AllInstances.ContainsKeyString = (a, b) => containsKey;

            // Act
            _privateObject.Invoke(InstallPropertiesMethod);
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(2, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectdRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);
        }
        private void iInstallSolutionsCommon(
            bool verifyOnly,
            bool overWrite,
            string fileName,
            string expectedRow03,
            string expectedRow13,
            string expectedRow14,
            string expectedRow23,
            string expectedRow24)
        {
            // Arrange
            var appDef = new ApplicationDef();
            var xml    = new StringBuilder();

            xml.Append("<root>")
            .Append("<Solutions>")
            .AppendFormat("<Solution FileName='{0}' Overwrite='{1}'>", fileName, overWrite)
            .Append("</Solution>")
            .AppendFormat("<ListTemplate FileName='{0}' Overwrite='{1}'>", fileName, overWrite)
            .Append("</ListTemplate>")
            .Append("</Solutions>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);

            // Act
            _privateObject.Invoke(iInstallSolutionMethod);
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(3, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);
            Assert.AreEqual(expectedRow23, dtMessages.Rows[2][3]);
            Assert.AreEqual(expectedRow24, dtMessages.Rows[2][4]);
        }
コード例 #11
0
        private void InstallListsViewsWebpartsInstallCommon(bool verifyOnly, bool hasViewFile, string expectedRow03)
        {
            // Arrange
            var appDef = new ApplicationDef();

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);

            ShimAppStore.AllInstances.GetFileString = (a, b) => hasViewFile ? new byte[] { 0 } : null;

            // Act
            _privateObject.Invoke(InstallListsViewsWebpartsInstallMethod, new object[] { new ShimSPView().Instance, true, new ShimAppStore().Instance, 0 });
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(1, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
        }
コード例 #12
0
        private void InstallAndConfigureAppCommon(
            bool hasAppList,
            int community,
            bool verifyOnly,
            bool overWrite,
            int rowCount,
            string expectedRow03,
            string expectedRow04,
            string expectedRow13,
            string expectedRow14,
            string expectedRow23,
            string expectedRow24,
            string expectedRow33,
            string expectedRow43,
            string expectedRow53,
            string expectedRow63,
            string expectedRow73,
            string expectedRow83)

        {
            // Arrange
            var appDef = new ApplicationDef
            {
                Community = "community",
                Version   = "version"
            };
            var xml = new StringBuilder();

            xml.Append("<root>")
            .Append("<Application ProcessReports='true'>")
            .Append("<QuickLaunch>")
            .Append("<Item Name='name' Url='url' External='true'>")
            .Append("<Item Name='name' Url='url' External='true'/>")
            .Append("</Item>")
            .Append("</QuickLaunch>")
            .Append("<TopNav/>")
            .Append("</Application>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);
            _privateObject.SetFieldOrProperty(AppListProp, hasAppList ? new ShimSPList().Instance : null);

            ShimSPListItem.AllInstances.IDGet = _ => community;

            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) => new ShimSPField();

            // Act
            _privateObject.Invoke(InstallAndConfigureAppMethod);
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(rowCount, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow04, dtMessages.Rows[0][4]);
            if (rowCount > 1)
            {
                Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
                Assert.AreEqual(expectedRow14, dtMessages.Rows[1][4]);

                if (rowCount > 2)
                {
                    Assert.AreEqual(expectedRow23, dtMessages.Rows[2][3]);
                    Assert.AreEqual(expectedRow24, dtMessages.Rows[2][4]);
                    Assert.AreEqual(expectedRow33, dtMessages.Rows[3][3]);
                    Assert.AreEqual(expectedRow43, dtMessages.Rows[4][3]);
                    Assert.AreEqual(expectedRow53, dtMessages.Rows[5][3]);

                    if (rowCount > 6)
                    {
                        Assert.AreEqual(expectedRow63, dtMessages.Rows[6][3]);
                        if (rowCount > 7)
                        {
                            Assert.AreEqual(expectedRow73, dtMessages.Rows[7][3]);
                            if (rowCount > 8)
                            {
                                Assert.AreEqual(expectedRow83, dtMessages.Rows[8][3]);
                            }
                        }
                    }
                }
            }
        }
        private void iInstallFeaturesCommon(
            bool verifyOnly,
            string expectedRow03,
            string expectedRow13,
            string expectedRow23,
            string expectedRow33,
            string expectedRow43,
            string expectedRow53)
        {
            // Arrange
            var guids  = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            var scopes = new[] { SPFeatureScope.Site, SPFeatureScope.Site, SPFeatureScope.Web, SPFeatureScope.Web };
            var i      = 0;
            var k      = 0;
            var appDef = new ApplicationDef();
            var xml    = new StringBuilder();

            xml.Append("<root>")
            .Append("<Features>")
            .AppendFormat("<Feature ID='{0}' Name='name1' IncludedInSolutions='{1}'/>", guids[0], true)
            .AppendFormat("<Feature ID='{0}' Name='name2' IncludedInSolutions='{1}'/>", guids[1], true)
            .AppendFormat("<Feature ID='{0}' Name='name3' IncludedInSolutions='{1}'/>", guids[2], true)
            .AppendFormat("<Feature ID='{0}' Name='name4' IncludedInSolutions='{1}'/>", guids[3], true)
            .AppendFormat("<Feature ID='{0}' Name='name5' IncludedInSolutions='{1}'/>", Guid.NewGuid(), true)
            .Append("</Features>")
            .Append("</root>");
            appDef.ApplicationXml.LoadXml(xml.ToString());

            _privateObject.SetFieldOrProperty(OWebProp, new ShimSPWeb().Instance);
            _privateObject.SetFieldOrProperty(AppDefProp, appDef);
            _privateObject.SetFieldOrProperty(VerifyOnlyProp, verifyOnly);
            _privateObject.SetFieldOrProperty(ListItemProp, new ShimSPListItem().Instance);

            ShimSPPersistedObjectCollection <SPFeatureDefinition> .AllInstances.GetEnumerator = _ =>
            {
                var list = new List <SPFeatureDefinition>
                {
                    new ShimSPFeatureDefinition
                    {
                        CompatibilityLevelGet = () => 14,
                        ScopeGet       = () => scopes[k++],
                        IdGet          = () => guids[i++],
                        DisplayNameGet = () => $"dsplayName{k}"
                    }.Instance,

                    new ShimSPFeatureDefinition
                    {
                        CompatibilityLevelGet = () => 15,
                        ScopeGet       = () => scopes[k++],
                        IdGet          = () => guids[i++],
                        DisplayNameGet = () => $"dsplayName{k}"
                    }.Instance
                };

                return(list.GetEnumerator());
            };

            // Act
            _privateObject.Invoke(iInstallFeaturesMethod);
            var dtMessages = _privateObject.GetFieldOrProperty(DTMessagesProp) as DataTable;

            // Assert
            Assert.IsNotNull(dtMessages);
            Assert.AreEqual(6, dtMessages.Rows.Count);
            Assert.AreEqual(expectedRow03, dtMessages.Rows[0][3]);
            Assert.AreEqual(expectedRow13, dtMessages.Rows[1][3]);
            Assert.AreEqual(expectedRow23, dtMessages.Rows[2][3]);
            Assert.AreEqual(expectedRow33, dtMessages.Rows[3][3]);
            Assert.AreEqual(expectedRow43, dtMessages.Rows[4][3]);
            Assert.AreEqual(expectedRow53, dtMessages.Rows[5][3]);
        }
コード例 #14
0
        public void InstallAndConfigureApp(bool verifyonly, SPWeb web, int iCommunityId)
        {
            bVerifyOnly = verifyonly;
            oWeb        = web;
            iCommunity  = iCommunityId;
            appDef      = Applications.GetApplicationInfo(_id);


            CheckInstalledRoot();

            oAppList = oWeb.Lists.TryGetList("Installed Applications");
            if (oAppList == null)
            {
                addMessage(ErrorLevels.Error, "Application List", "You do not have the application list installed", 0);
            }
            else
            {
                var query = new SPQuery();
                query.Query = "<Where><Eq><FieldRef Name='EXTID' /><Value Type='Number'>" + appDef.Id + "</Value></Eq></Where>";
                var lic = oAppList.GetItems(query);

                if (lic.Count > 0)
                {
                    oListItem = lic[0];
                }
                else
                {
                    addMessage(ErrorLevels.Error, "Open Application Item", "Could not find item in list", 0);
                    return;
                }

                if (appDef.loadErrorMessage == string.Empty)
                {
                    if (CheckPermissions())
                    {
                        if (CheckForApplicationList())
                        {
                            if (CheckForPreReqs())
                            {
                                if (CheckForKeys())
                                {
                                    InstallAndConfigureApp();

                                    if (!bVerifyOnly)
                                    {
                                        ReportToAppReporting(web);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    addMessage(ErrorLevels.Error, "Check Applications", appDef.loadErrorMessage, 0);
                }
                if (oListItem != null)
                {
                    reportResults();
                }
            }
        }