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

MSLISTSWS_S02_TC07_CreateContentType_ErrorFieldName() private method

        public void MSLISTSWS_S02_TC07_CreateContentType_ErrorFieldName()
        {
            #region Create a new list

            bool isCreateListSuccess = false;
            string listName = TestSuiteHelper.GetUniqueListName();
            string listGuid = TestSuiteHelper.CreateList(listName);
            isCreateListSuccess = !string.IsNullOrEmpty(listGuid);
            Site.Assert.IsTrue(isCreateListSuccess, "Creating a new list '{0}' should succeed.", listName);
            #endregion

            #region CreateContentType with error field name
            string contentTypeId = null;
            string fieldNameA = Common.GetConfigurationPropertyValue("ListFieldText", this.Site);
            string fieldNameB = TestSuiteHelper.GetUniqueFieldName();
            AddOrUpdateFieldsDefinition addFields = TestSuiteHelper.CreateAddContentTypeFields(fieldNameA, fieldNameB);
            string parentTypeName = TestSuiteHelper.GetFirstExistContentTypeName(listGuid);
            string parentTypeId = TestSuiteHelper.GetContentTypeId(listGuid, parentTypeName);
            string contentTypeDisplayName = TestSuiteHelper.GetUniqueContentTypeName();

            // Call CreateContentType operation to create a content type with 2 field names, one is valid field name and the other is invalid one.
            contentTypeId = this.listswsAdapter.CreateContentType(
                                                        listGuid,
                                                        contentTypeDisplayName,
                                                        parentTypeId,
                                                        addFields,
                                                        new CreateContentTypeContentTypeProperties(),
                                                        "TRUE");

            Site.Assert.IsNotNull(contentTypeId, "The result of CreateContentType operation should not be NULL");

            #endregion

            #region Get the created content type and capture requirements.

            // Get the previous step created content type.
            GetListContentTypeResponseGetListContentTypeResult contentTypeResult = null;
            bool isExceptionThrown = false;

            try
            {
                contentTypeResult = this.listswsAdapter.GetListContentType(
                                            listName,
                                            contentTypeId);
            }
            catch (SoapException)
            {
                isExceptionThrown = true;
            }
            catch (WebException)
            {
                isExceptionThrown = true;
            }

            // If no exception thrown, it means the error is ignored by protocol server. Capture R429
            Site.CaptureRequirementIfIsFalse(
                        isExceptionThrown,
                        429,
                        @"The protocol server adds the given fields to the newly created content type. If an error regarding the fields is encountered during this operation, the protocol server MUST ignore this error.");

            bool isContains = false;
            foreach (FieldDefinitionCTRemove field in contentTypeResult.ContentType.Fields.Items)
            {
                if (field.Name == fieldNameA)
                {
                    isContains = true;
                    break;
                }
            }

            // If the content type exists, and the valid field exists, then capture R2266 and R2267.
            Site.CaptureRequirementIfIsTrue(
                isContains,
                2266,
                @"[The content type will still exist as a newly created content type on the protocol server and all fields added to the content type before the error was encountered MUST stay added to the content type.] The content type will still exist as a newly created content type on the protocol server.");

            Site.CaptureRequirementIfIsTrue(
                isContains,
                2267,
                @"[The protocol server adds the given fields to the newly created content type. If an error regarding the fields is encountered during this operation, the protocol server MUST ignore this error. The content type will still exist as a newly created content type on the protocol server and]  all fields added to the content type before the error was encountered MUST stay added to the content type.");

            #endregion
        }
S02_OperationOnContentType