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

MSLISTSWS_S02_TC46_GetListContentTypes_Succeed_BestMatch() private method

        public void MSLISTSWS_S02_TC46_GetListContentTypes_Succeed_BestMatch()
        {
            #region Add a list
            string listName = TestSuiteHelper.GetUniqueListName();

            string listId = TestSuiteHelper.CreateList(listName);

            bool isListCreatedSuccessful = !string.IsNullOrEmpty(listId);
            this.Site.Assert.IsTrue(isListCreatedSuccessful, "Creating list successfully.");

            #endregion Add a list

            #region CreateContentType
            string displayName = TestSuiteHelper.GetUniqueContentTypeName();
            string fieldName = TestSuiteHelper.GetUniqueFieldName();
            List<string> fields = new List<string> { fieldName };

            string contentTypeId = TestSuiteHelper.CreateContentType(listId, displayName, fields);

            this.Site.Assert.IsTrue(!string.IsNullOrEmpty(contentTypeId), "CreateContentType successfully.");
            #endregion CreateContentType

            #region GetListContentTypes
            GetListContentTypesResponseGetListContentTypesResult listContentTypes = this.listswsAdapter.GetListContentTypes(listId, contentTypeId);
            this.Site.Assert.IsNotNull(listContentTypes, "Calling GetListContentTypes successfully.");
            bool isListExist = listContentTypes.ContentTypes.ContentType.Any(contentType => contentType.ID.Equals(contentTypeId, StringComparison.OrdinalIgnoreCase));

            if (!isListExist)
            {
                Site.Assert.Fail("There is no list which matches the list name{0} in the GetListContentTypes response", listName);
            }

            bool isBestMatchExist = false;

            // BestMatch is specified as TRUE 
            foreach (GetListContentTypesResponseGetListContentTypesResultContentTypesContentType ct in listContentTypes.ContentTypes.ContentType)
            {
                if (ct.BestMatchSpecified == true)
                {
                    isBestMatchExist = true;
                    break;
                }
            }

            if (!isBestMatchExist)
            {
                Site.Assert.Fail("Could not find the Best Match.");
            }

            // If BestMatch is specified as TRUE, then capture R612.
            Site.CaptureRequirement(
                612,
                @"[In GetListContentTypes operation] 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.");

            // If BestMatch is specified as TRUE, then capture R1826.
            Site.CaptureRequirement(
                1826,
                @"[GetListContentTypes]If the content type specified by contentTypeId exists on the list, the server MUST choose that content type as the best match.");

            #endregion
        }
S02_OperationOnContentType