Microsoft.Protocols.TestSuites.MS_LISTSWS.S02_OperationOnContentType.MSLISTSWS_S02_TC36_GetListContentTypesAndProperties_Succeed_BestMatchAndPrefix C# (CSharp) Method

MSLISTSWS_S02_TC36_GetListContentTypesAndProperties_Succeed_BestMatchAndPrefix() private method

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

            #region Data Binding
            string listName = TestSuiteHelper.GetUniqueListName();
            TestSuiteHelper.CreateList(listName);

            // Get the list guid of a list
            GetListResponseGetListResult getListResult = this.listswsAdapter.GetList(listName);
            Site.Assert.IsNotNull(getListResult, "Get the list id of a specified list via its list name through calling operation of GetList");
            string listGUID = getListResult.List.ID;

            // Get contentTypeId of list.
            GetListContentTypesResponseGetListContentTypesResult result;
            result = this.listswsAdapter.GetListContentTypes(listName, string.Empty);

            Site.Assert.IsNotNull(result, "The result must be not null");
            string contentTypeId = result.ContentTypes.ContentType[0].Name;
            string propertyPrefix = Common.GetConfigurationPropertyValue("PropertyPrefix", this.Site);
            #endregion

            #region Calling GetListContentTypesAndProperties operation with listName is GUID,contentTypeId specified,contentTypeId exist on the list(bestMatch),propertyPrefix not empty, includeWebProperties is true
            bool isContentTypeVerified = false;
            bool isBestMatchVerified = false;
            bool isPrefixVerified = false;

            GetListContentTypesAndPropertiesResponseGetListContentTypesAndPropertiesResult resOne = null;
            resOne = this.listswsAdapter.GetListContentTypesAndProperties(listGUID, contentTypeId, propertyPrefix, true, true);

            this.Site.Assert.IsNotNull(resOne, "Call operation GetListContentTypesAndProperties should be successful.");
            #endregion

            #region Verify result, Capture R1044 R1045 R1047 R1069
            int countContentTypes = resOne.ContentTypes.ContentType.GetLength(0);
            int countProperties = resOne.Properties.GetLength(0);
            for (int i = 0; i < countContentTypes; i++)
            {
                if (resOne.ContentTypes.ContentType[i].Name == contentTypeId)
                {
                    isContentTypeVerified = true;
                    if (resOne.ContentTypes.ContentType[i].BestMatch == TRUEONLY.TRUE)
                    {
                        isBestMatchVerified = true;
                    }
                }
            }

            Site.CaptureRequirementIfIsTrue(
                isContentTypeVerified && isBestMatchVerified,
                1044,
                @"[In GetListContentTypesAndProperties]If the contentTypeId parameter is specified, the protocol server MUST attempt to find the ""best match"" to the specified content type from among those on the list.");

            Site.CaptureRequirementIfIsTrue(
                isContentTypeVerified && isBestMatchVerified,
                1045,
                @"[In GetListContentTypesAndProperties]If the content type specified by contentTypeId exists on the list, the server MUST choose that content type as the best match.");

            Site.CaptureRequirementIfIsTrue(
                isBestMatchVerified,
                1047,
                @"[In GetListContentTypesAndProperties]If the server succeeds in finding a best match to the specified content type, the server MUST set the BestMatch attribute of the selected content type to ""TRUE"" in the GetListContentTypesAndPropertiesResponse element.");

            Site.CaptureRequirementIfIsTrue(
                isContentTypeVerified && isBestMatchVerified,
                1069,
                @"[In GetListContentTypesAndPropertiesResponse]If specified at all, then it MUST be specified on the ContentType element that represents the ""best match"" to the content type identified by the contentTypeId element in the GetListContentTypesAndPropertiesSoapIn message.");

            #endregion

            #region Calling GetListContentTypesAndProperties operation with listName is GUID,contentTypeId specified,contentTypeId exist on the list(bestMatch),propertyPrefix not empty, includeWebProperties is false
            GetListContentTypesAndPropertiesResponseGetListContentTypesAndPropertiesResult resTwo = null;
            resTwo = this.listswsAdapter.GetListContentTypesAndProperties(listGUID, contentTypeId, propertyPrefix, false, false);

            this.Site.Assert.IsNotNull(resTwo, "Call operation GetListContentTypesAndProperties should be successful.");
            #endregion

            #region Verify result, Capture R1049
            countContentTypes = resTwo.ContentTypes.ContentType.GetLength(0);
            countProperties = resTwo.Properties.GetLength(0);

            for (int i = 0; i < countProperties; i++)
            {
                if (resTwo.Properties[i].Key.Substring(0, propertyPrefix.Length) == propertyPrefix)
                {
                    isPrefixVerified = true;
                }
                else
                {
                    isPrefixVerified = false;
                    break;
                }
            }

            Site.CaptureRequirementIfIsTrue(
                isPrefixVerified,
                1049,
                @"[In GetListContentTypesAndProperties]If the propertyPrefix parameter is not empty, the protocol server MUST return all of the properties in the list property bag whose property key begins with the propertyPrefix.");

            #endregion
        }
S02_OperationOnContentType