Microsoft.Protocols.TestSuites.MS_SITESS.AdapterHelper.SiteResultDeserialize C# (CSharp) Méthode

SiteResultDeserialize() public static méthode

Deserialize an xml string to a Site object.
public static SiteResultDeserialize ( string getSiteResult ) : Site
getSiteResult string The xml string returned from the GetSite operation.
Résultat Site
        public static Site SiteResultDeserialize(string getSiteResult)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(Site));
            Site siteResult;
            using (StringReader s = new StringReader(getSiteResult))
            {
                siteResult = (Site)deserializer.Deserialize(s);
            }

            return siteResult;
        }

Usage Example

        public void MSSITESS_S06_TC01_GetSiteSucceed()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(5341, this.Site), @"Test is executed only when R5341Enabled is set to true.");

            #region Variables
            string url                     = Common.GetConfigurationPropertyValue(Constants.NormalSubsiteUrl, this.Site);
            string getResult               = string.Empty;
            Guid   expectedGuid            = Guid.Empty;
            bool   expectedUserCodeEnabled = false;
            Site   result;
            Guid   siteGuid            = Guid.Empty;
            bool   siteUserCodeEnabled = false;

            #endregion Variables

            // Initialize the web service with an authenticated account.
            this.sitessAdapter.InitializeWebService(UserAuthenticationOption.Authenticated);

            // Get the site collection identifier of the site collection.
            expectedGuid = new Guid(this.sutAdapter.GetSiteGuid());

            Site.Assert.AreNotEqual <Guid>(
                Guid.Empty,
                expectedGuid,
                "Site's guid should not be null.");

            // Set whether user code is enabled for the site collection. Set user code is true.
            expectedUserCodeEnabled = this.sutAdapter.SetUserCodeEnabled(true);
            Site.Assert.IsTrue(expectedUserCodeEnabled, "The user code should be enabled for the site collection.");

            // Invoke the GetSite operation with valid SiteUrl.
            // getResult is in form: <Site Url=UrlString Id=IdString UserCodeEnabled=UserCodeEnabledString />.
            // If split getResult with '"', the fourth is IdString. And, the sixth is UserCodeEnabledString.
            getResult = this.sitessAdapter.GetSite(url);

            Site.Assert.IsNotNull(getResult, "The GetSiteResult should not be null when invoking the GetSite operation with valid SiteUrl");
            result = AdapterHelper.SiteResultDeserialize(getResult);

            // Get the Id element form result of the succeed GetSite operation.
            siteGuid = new Guid(result.Id);

            // Get the UserCodeEnabled element form result of the succeed GetSite operation.
            bool convertResult = bool.TryParse(result.UserCodeEnabled, out siteUserCodeEnabled);

            #region Capture requirements

            this.VerifyIdString(expectedGuid, siteGuid);

            if (convertResult)
            {
                // The value for UserCodeEnabledString MUST be ""true"" if user code is enabled for the site collection.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R398");

                // Verify MS-SITESS requirement: MS-SITESS_R398
                Site.CaptureRequirementIfAreEqual <bool>(
                    expectedUserCodeEnabled,
                    siteUserCodeEnabled,
                    398,
                    @"[In GetSiteResponse] [GetSiteResult:] The value for UserCodeEnabledString MUST be ""true"" if user code is enabled for the site collection.");
            }
            else
            {
                Site.Assert.Fail("The returned value of the UserCodeEnabled element is not of type bool, the value is : {0}", result.UserCodeEnabled);
            }

            #endregion Capture requirements

            // Set whether user code is enabled for the site collection. Set user code is false.
            expectedUserCodeEnabled = this.sutAdapter.SetUserCodeEnabled(false);
            Site.Assert.IsFalse(expectedUserCodeEnabled, "The user code should not be enabled for the site collection.");

            // Invoke the GetSite operation with valid SiteUrl.
            // getResult is in form: <Site Url=UrlString Id=IdString UserCodeEnabled=UserCodeEnabledString />.
            // If split getResult with '"', the fourth is IdString. And, the sixth is UserCodeEnabledString.
            getResult = this.sitessAdapter.GetSite(url);

            Site.Assert.IsNotNull(getResult, "The GetSiteResult should not be null when invoking the GetSite operation with valid SiteUrl");
            result = AdapterHelper.SiteResultDeserialize(getResult);

            // Get the Id element form result of the succeed GetSite operation.
            siteGuid = new Guid(result.Id);

            // Get the UserCodeEnabled element form result of the succeed GetSite operation.
            convertResult = bool.TryParse(result.UserCodeEnabled, out siteUserCodeEnabled);

            #region Capture requirements

            this.VerifyIdString(expectedGuid, siteGuid);

            if (convertResult)
            {
                // The value for UserCodeEnabledString MUST be ""false"" if user code is not enabled for the site collection.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R399");

                // Verify MS-SITESS requirement: MS-SITESS_R399
                Site.CaptureRequirementIfAreEqual <bool>(
                    expectedUserCodeEnabled,
                    siteUserCodeEnabled,
                    399,
                    @"[In GetSiteResponse] [GetSiteResult:] The value for UserCodeEnabledString MUST be ""false"" if it is not enabled.");
            }
            else
            {
                Site.Assert.Fail("The returned value of the UserCodeEnabled element is not of type bool, the value is : {0}", result.UserCodeEnabled);
            }

            #endregion Capture requirements

            // If code can run to here, it means that Microsoft SharePoint Foundation 2010 and above support operation GetSite.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SITESS_R5341, Microsoft SharePoint Foundation 2010 and above support operation GetSite.");

            // Verify MS-SITESS requirement: MS-SITESS_R5341
            Site.CaptureRequirement(
                5341,
                @"[In Appendix B: Product Behavior] Implementation does support this method [GetSite]. (Microsoft SharePoint Foundation 2010 and above follow this behavior.)");
        }
All Usage Examples Of Microsoft.Protocols.TestSuites.MS_SITESS.AdapterHelper::SiteResultDeserialize