GetSubResourceUrl() public static method

A method is used to get folder children's level URL.
public static GetSubResourceUrl ( string wopiRootResourceUrl, WOPISubResourceUrlType subResourceUrlType ) : string
wopiRootResourceUrl string A parameter represents the WOPI resource URL for the folder level.
subResourceUrlType WOPISubResourceUrlType A parameter represents the WOPI sub resource URL for the folder level.
return string
        public void MSWOPI_S19_TC05_PutFile_Fail409()
        {
            // Get the file URL.
            string fileUrl = this.AddFileToSUT();

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
            string identifierForLock          = Guid.NewGuid().ToString("N");

            // Lock this file.
            WopiAdapter.Lock(wopiTargetFileUrl, commonHeaders, identifierForLock);

            try
            {
                // Get file content URL.
                string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

                // Get the common header.
                commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

                string exceptedUpdateContent = "WOPI PUT file test";
                byte[] bodycontents          = Encoding.UTF8.GetBytes(exceptedUpdateContent);
                string identifier            = Guid.NewGuid().ToString("N");

                int statusCode = 0;
                try
                {
                    // Update a file on the WOPI server.
                    WOPIHttpResponse httpWebResponseOfPutFile = WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifier);
                    statusCode = httpWebResponseOfPutFile.StatusCode;
                }
                catch (WebException webEx)
                {
                    HttpWebResponse errorResponse = this.GetErrorResponseFromWebException(webEx);
                    statusCode = this.GetStatusCodeFromHTTPResponse(errorResponse);
                }

                // Verify MS-WOPI requirement: MS-WOPI_R690
                this.Site.CaptureRequirementIfAreEqual(
                    409,
                    statusCode,
                    690,
                    @"[In PutFile] Status code ""409"" means ""Lock mismatch"".");
            }
            finally
            {
                // Release a lock for editing a file.
                commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
                WopiAdapter.UnLock(wopiTargetFileUrl, commonHeaders, identifierForLock);
            }
        }
        public void MSWOPI_S19_TC01_GetFile()
        {
            // Get the file URL.
            string fileUrl = this.AddFileToSUT();

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get file content URL.
            string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

            int statusCode = 0;

            // Get a file.
            WOPIHttpResponse responseOfGetFile = WopiAdapter.GetFile(wopiFileContentsLevelUrl, commonHeaders, null);

            statusCode = responseOfGetFile.StatusCode;

            // Verify MS-WOPI requirement: MS-WOPI_R667
            this.Site.CaptureRequirementIfAreEqual(
                200,
                statusCode,
                667,
                @"[In GetFile] Status code ""200"" means ""Success"".");

            // Verify MS-WOPI requirement: MS-WOPI_R657
            this.Site.CaptureRequirementIfIsNotNull(
                responseOfGetFile,
                657,
                @"[In HTTP://server/<...>/wopi*/files/<id>/contents] Operation ""GetFile"" is used for ""Request message to retrieve a file for the HTTP://server/<...>/wopi*/files/<id>/contents operation"".");

            // Verify MS-WOPI requirement: MS-WOPI_R659
            this.Site.CaptureRequirementIfIsNotNull(
                responseOfGetFile,
                659,
                @"[In GetFile] Get a file.");

            // The URI in "GetFile" WOPI request follow the "HTTP://server/<...>/wopi*/files/<id>/contents?access_token=<token>" pattern, if the operation execute successfully, capture R660
            // Verify MS-WOPI requirement: MS-WOPI_R660
            this.Site.CaptureRequirement(
                660,
                @"[In GetFile] HTTP Verb: GET
                          URI: HTTP://server/<...>/wopi*/files/<id>/contents?access_token=<token>");

            // Verify MS-WOPI requirement: MS-WOPI_R672
            this.Site.CaptureRequirementIfIsNotNull(
                responseOfGetFile,
                672,
                @"[In Response Body] The binary contents of the file.");
        }
        public void MSWOPI_S19_TC06_PutFile_Lock()
        {
            // Get the file URL.
            string fileUrl = this.AddFileToSUT();

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get file content URL.
            string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);

            string identifierForLock = Guid.NewGuid().ToString("N");

            // Lock this file.
            WopiAdapter.Lock(wopiTargetFileUrl, commonHeaders, identifierForLock);

            try
            {
                // Get the common header.
                commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

                string exceptedUpdateContent = "WOPI PUT file test";
                byte[] bodycontents          = Encoding.UTF8.GetBytes(exceptedUpdateContent);

                // Update a file on the WOPI server with the identifier of Lock.
                WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifierForLock);

                // Get the common header.
                commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

                // Get a file.
                WOPIHttpResponse responseOfGetFile = WopiAdapter.GetFile(wopiFileContentsLevelUrl, commonHeaders, null);

                // Read message from response of GetFile.
                string actualUpdateContent = WOPIResponseHelper.ReadHTTPResponseBodyToString(responseOfGetFile);

                // Verify MS-WOPI requirement: MS-WOPI_R697
                this.Site.CaptureRequirementIfAreEqual(
                    exceptedUpdateContent,
                    actualUpdateContent,
                    697,
                    @"[In Processing Details] If the file is currently associated with a lock established by the Lock operation (see section 3.3.5.1.3) [or the UnlockAndRelock operation (see section 3.3.5.1.6)] the WOPI server MUST provide the matching lock value in order for this operation to succeed.");
            }
            finally
            {
                // Release a lock for editing a file.
                commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
                WopiAdapter.UnLock(wopiTargetFileUrl, commonHeaders, identifierForLock);
            }
        }
        public void MSWOPI_S19_TC04_PutFile_Fail404()
        {
            // Get the file URL.
            string fileUrl = this.AddFileToSUT();

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get file content URL.
            string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);

            // Delete this file.
            WopiAdapter.DeleteFile(wopiTargetFileUrl, commonHeaders);

            // The file has been deleted, so remove it from the clean up list.
            this.ExcludeFileFromTheCleanUpProcess(fileUrl);

            // Get the common header.
            commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

            string exceptedUpdateContent = "WOPI PUT file test";

            byte[] bodycontents = Encoding.UTF8.GetBytes(exceptedUpdateContent);
            string identifier   = Guid.NewGuid().ToString("N");

            int statusCodeOfPutFile = 0;

            try
            {
                // Update a file on the WOPI server.
                WOPIHttpResponse httpWebResponseOfPutFile = WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifier);
                statusCodeOfPutFile = httpWebResponseOfPutFile.StatusCode;
            }
            catch (WebException webEx)
            {
                HttpWebResponse errorResponse = this.GetErrorResponseFromWebException(webEx);
                statusCodeOfPutFile = this.GetStatusCodeFromHTTPResponse(errorResponse);
            }

            // Verify MS-WOPI requirement: MS-WOPI_R689
            this.Site.CaptureRequirementIfAreEqual(
                404,
                statusCodeOfPutFile,
                689,
                @"[In PutFile] Status code ""404"" means ""File unknown/User unauthorized"".");
        }
        public void MSWOPI_S19_TC02_GetFile_Fail404()
        {
            // Get the file URL.
            string fileUrl = this.AddFileToSUT();

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get file content URL.
            string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);

            // Delete the file.
            WopiAdapter.DeleteFile(wopiTargetFileUrl, commonHeaders);

            // The file has been deleted, so remove it from the clean up list.
            this.ExcludeFileFromTheCleanUpProcess(fileUrl);

            // Get the common header.
            commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

            int statusCodeOfGetFile = 0;

            try
            {
                // Get a file.
                WOPIHttpResponse responseOfGetFile = WopiAdapter.GetFile(wopiFileContentsLevelUrl, commonHeaders, null);
                statusCodeOfGetFile = responseOfGetFile.StatusCode;
            }
            catch (WebException webEx)
            {
                HttpWebResponse errorResponse = this.GetErrorResponseFromWebException(webEx);
                statusCodeOfGetFile = this.GetStatusCodeFromHTTPResponse(errorResponse);
            }

            // Verify MS-WOPI requirement: MS-WOPI_R669
            this.Site.CaptureRequirementIfAreEqual(
                404,
                statusCodeOfGetFile,
                669,
                @"[In GetFile] Status code ""404"" means ""File unknown/User unauthorized"".");
        }
        public void MSWOPI_S20_TC03_EnumerateChildren_Fail404()
        {
            if (!Common.IsRequirementEnabled("MS-WOPI", 593, this.Site))
            {
                Site.Assume.Inconclusive(@"The implementation does not support the get the folder access_token and WOPISrc. It is determined using SHOULDMAY PTFConfig property named R593Enabled_MS-WOPI.");
            }
            // Get the folder URL.
            string folderFullUrl = Common.GetConfigurationPropertyValue("SubFolderUrl", this.Site);

            // Get the WOPI URL.
            string wopiTargetFolderUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(folderFullUrl, WOPIRootResourceUrlType.FolderLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get folder content URL.
            string wopiFolderContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFolderUrl, WOPISubResourceUrlType.FolderChildrenLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiFolderContentsLevelUrl);

            // Remove "Authorization" header from common headers.
            commonHeaders.Remove("Authorization");

            // Return the contents of a folder on the WOPI server with invalid token.
            int statusCode = 0;

            try
            {
                WOPIHttpResponse httpWebResponseForEnumerateChildren = WopiAdapter.EnumerateChildren(wopiFolderContentsLevelUrl, commonHeaders);
                statusCode = httpWebResponseForEnumerateChildren.StatusCode;
            }
            catch (WebException webEx)
            {
                HttpWebResponse errorResponse = this.GetErrorResponseFromWebException(webEx);
                statusCode = this.GetStatusCodeFromHTTPResponse(errorResponse);
            }

            // Verify MS-WOPI requirement: MS-WOPI_R709
            this.Site.CaptureRequirementIfAreEqual <int>(
                404,
                statusCode,
                709,
                @"[In EnumerateChildren] Status code ""404"" means ""File unknown/User unauthorized"".");
        }
        public void MSWOPI_S19_TC03_PutFile()
        {
            // Get the file URL.
            string fileUrl = this.AddFileToSUT();

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get file content URL.
            string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

            string exceptedUpdateContent = "WOPI PUT file test";

            byte[] bodycontents = Encoding.UTF8.GetBytes(exceptedUpdateContent);
            string identifier   = Guid.NewGuid().ToString("N");

            int statusCode = 0;

            // Update a file on the WOPI server.
            WOPIHttpResponse httpWebResponseOfPutFile = WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifier);

            statusCode = httpWebResponseOfPutFile.StatusCode;

            // Verify MS-WOPI requirement: MS-WOPI_R687
            this.Site.CaptureRequirementIfAreEqual(
                200,
                statusCode,
                687,
                @"[In PutFile] Status code ""200"" means ""Success"".");

            // Get the common header.
            commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

            // Get a file.
            WOPIHttpResponse responseOfGetFile = WopiAdapter.GetFile(wopiFileContentsLevelUrl, commonHeaders, null);

            // Read message from response of GetFile.
            string actualUpdateContent = WOPIResponseHelper.ReadHTTPResponseBodyToString(responseOfGetFile);

            // Verify MS-WOPI requirement: MS-WOPI_R674
            this.Site.CaptureRequirementIfAreEqual(
                exceptedUpdateContent,
                actualUpdateContent,
                674,
                @"[In PutFile] Update a file on the WOPI server.");

            // Verify MS-WOPI requirement: MS-WOPI_R675
            this.Site.CaptureRequirement(
                675,
                @"[In PutFile] HTTP Verb: POST
                          URI: HTTP://server/<...>/wopi*/files/<id>/contents?access_token=<token>");

            // Verify MS-WOPI requirement: MS-WOPI_R696
            this.Site.CaptureRequirementIfAreEqual(
                exceptedUpdateContent,
                actualUpdateContent,
                696,
                @"[In Processing Details] The WOPI server MUST update the binary of the file identified by <id> to match the binary contents in the request body, if the response indicates Success.");

            // Verify MS-WOPI requirement: MS-WOPI_R658
            this.Site.CaptureRequirementIfAreEqual(
                exceptedUpdateContent,
                actualUpdateContent,
                658,
                @"[In HTTP://server/<...>/wopi*/files/<id>/contents] Operation ""PutFile"" is used for 
                          ""Request message to update a file for the HTTP://server/<...>/wopi*/files/<id>/contents operation"".");

            // Verify MS-WOPI requirement: MS-WOPI_R673
            this.Site.CaptureRequirementIfAreEqual(
                exceptedUpdateContent,
                actualUpdateContent,
                673,
                @"[In Processing Details] The WOPI server MUST return the complete binary of the file identified by <id> in the response body, if the response indicates Success.");
        }
Example #8
0
        public void MSWOPI_S20_TC01_EnumerateChildren()
        {
            // Get the folder URL.
            string folderFullUrl = Common.GetConfigurationPropertyValue("SubFolderUrl", this.Site);

            // Get the WOPI URL.
            string wopiTargetFolderUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(folderFullUrl, WOPIRootResourceUrlType.FolderLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get folder content URL.
            string wopiFolderContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFolderUrl, WOPISubResourceUrlType.FolderChildrenLevel);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiFolderContentsLevelUrl);

            // Return the contents of a folder on the WOPI server.
            WOPIHttpResponse httpWebResponseForEnumerateChildren = WopiAdapter.EnumerateChildren(wopiFolderContentsLevelUrl, commonHeaders);

            int statusCode = httpWebResponseForEnumerateChildren.StatusCode;

            // Get the json string from the response of EnumerateChildren.
            string jsonStringForEnumerateChildren = WOPIResponseHelper.ReadHTTPResponseBodyToString(httpWebResponseForEnumerateChildren);

            // Convert the json string to object.
            EnumerateChildren enchildren = WOPISerializerHelper.JsonToObject <EnumerateChildren>(jsonStringForEnumerateChildren);
            string            fileName   = enchildren.Children[0].Name;

            // Verify MS-WOPI requirement: MS-WOPI_R707
            this.Site.CaptureRequirementIfAreEqual <int>(
                200,
                statusCode,
                707,
                @"[In EnumerateChildren] Status code ""200"" means ""Success"".");

            // The status code is 200 mean success.When response is success the URIs are return.
            this.Site.CaptureRequirement(
                703,
                @"[In HTTP://server/<...>/wopi*/folder/<id>/children] Operation ""EnumerateChildren"" is used for ""Returns a set of URIs that provides access to resources in the folder"".");

            // The status code is 200 mean success.When response is success the contexts are return.
            this.Site.CaptureRequirement(
                704,
                @"[In EnumerateChildren] The EnumerateChildren method returns the contents of a folder on the WOPI server.");

            // The status code is 200 mean success.When response is success the URI follows the format.
            this.Site.CaptureRequirement(
                705,
                @"[In EnumerateChildren] HTTP Verb: GET
                          URI: HTTP://server/<...>/wopi*/folder/<id>/children?access_token=<token>");

            string subFileUrl       = Common.GetConfigurationPropertyValue("UrlOfFileOnSubFolder", this.Site);
            string expectedFileName = TestSuiteHelper.GetFileNameFromFullUrl(subFileUrl);

            // Verify MS-WOPI requirement: MS-WOPI_R713
            bool isEqualToExpectedFileName = expectedFileName.CompareStringValueIgnoreCase(fileName, this.Site);

            this.Site.CaptureRequirementIfIsTrue(
                isEqualToExpectedFileName,
                713,
                @"[In Response Body] Name: The name of the child resource.");

            // Verify MS-WOPI requirement: MS-WOPI_R714
            // The EnumerateChildren request message follow this format and use the id and token return by WOPI server.
            // If the WOPI server can return the response of EnumerateChildren, capture R714
            this.Site.CaptureRequirement(
                714,
                @"[In Response Body] Url: The URI of the child resource of the form http://server/<...>/wopi*/files/<id>?access_token=<token> where id is the WOPI server’s unique id of the resource and token is the token that provides access to the resource.");
        }
Example #9
0
        public void MSWOPI_S20_TC02_EnumerateChildren_Version()
        {
            #region Get the WOPI resource URL for visiting file.

            // Get the file URL.
            string fileUrl = Common.GetConfigurationPropertyValue("UrlOfFileOnSubFolder", this.Site);

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get file content URL.
            string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

            #endregion

            #region  Get the WOPI resource URL for visiting folder.

            // Get the folder URL.
            string folderFullUrl = Common.GetConfigurationPropertyValue("SubFolderUrl", this.Site);

            // Get the WOPI URL.
            string wopiTargetFolderUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(folderFullUrl, WOPIRootResourceUrlType.FolderLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get folder content URL.
            string wopiFolderContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFolderUrl, WOPISubResourceUrlType.FolderChildrenLevel);

            #endregion

            #region Call EnumerateChildren

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiFolderContentsLevelUrl);

            // Return the contents of a folder on the WOPI server.
            WOPIHttpResponse httpWebResponseForEnumerateChildren = WopiAdapter.EnumerateChildren(wopiFolderContentsLevelUrl, commonHeaders);

            // Get the json string from the response of EnumerateChildren.
            string jsonStringForEnumerateChildren = WOPIResponseHelper.ReadHTTPResponseBodyToString(httpWebResponseForEnumerateChildren);

            // Convert the json string to object.
            EnumerateChildren enchildren = WOPISerializerHelper.JsonToObject <EnumerateChildren>(jsonStringForEnumerateChildren);

            string versionOld = enchildren.Children[0].Version;

            #endregion

            #region Call PutFile

            // Get the common header.
            commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

            string exceptedUpdateContent = "WOPI PUT file test";
            byte[] bodycontents          = Encoding.UTF8.GetBytes(exceptedUpdateContent);
            string identifier            = Guid.NewGuid().ToString("N");

            // Update a file on the WOPI server.
            WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifier);

            #endregion

            #region Call EnumerateChildren

            // Get the common header.
            commonHeaders = HeadersHelper.GetCommonHeaders(wopiFolderContentsLevelUrl);

            // Return the contents of a folder on the WOPI server.
            httpWebResponseForEnumerateChildren = WopiAdapter.EnumerateChildren(wopiFolderContentsLevelUrl, commonHeaders);

            // Get the json string from the response of EnumerateChildren.
            jsonStringForEnumerateChildren = WOPIResponseHelper.ReadHTTPResponseBodyToString(httpWebResponseForEnumerateChildren);

            // Convert the json string to object.
            enchildren = WOPISerializerHelper.JsonToObject <EnumerateChildren>(jsonStringForEnumerateChildren);

            string versionNew = enchildren.Children[0].Version;

            #endregion

            #region Call CheckFileInfo

            // Get the common header.
            commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);

            // Return information about the file
            WOPIHttpResponse responseOfCheckFileInfo = WopiAdapter.CheckFileInfo(wopiTargetFileUrl, commonHeaders, null);

            // Get the json string from the response of CheckFileInfo.
            string jsonStringForCheckFileInfo = WOPIResponseHelper.ReadHTTPResponseBodyToString(responseOfCheckFileInfo);

            // Convert the json string to object.
            CheckFileInfo checkFileInfo = WOPISerializerHelper.JsonToObject <CheckFileInfo>(jsonStringForCheckFileInfo);

            string versionCheckFileInfo = checkFileInfo.Version;

            #endregion

            // Verify MS-WOPI requirement: MS-WOPI_R716
            this.Site.CaptureRequirementIfAreNotEqual <string>(
                versionOld,
                versionNew,
                716,
                @"[In Response Body] [Version] This value MUST change when the file changes.");

            // Verify MS-WOPI requirement: MS-WOPI_R934
            this.Site.CaptureRequirementIfAreEqual <string>(
                versionCheckFileInfo,
                versionNew,
                934,
                @"[In Response Body] [Version] MUST match the value that would be provided by the ""Version"" field in the response to CheckFileInfo (see section 3.3.5.1.1).");
        }
        public void MSWOPI_S19_TC05_PutFile_Fail409()
        {
            // Get the file URL.
            string fileUrl = this.AddFileToSUT();

            // Get the WOPI URL.
            string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain);

            // Get the common header.
            WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
            string identifierForLock          = Guid.NewGuid().ToString("N");

            // Lock this file.
            WopiAdapter.Lock(wopiTargetFileUrl, commonHeaders, identifierForLock);

            try
            {
                // Get file content URL.
                string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel);

                // Get the common header.
                commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl);

                string exceptedUpdateContent = "WOPI PUT file test";
                byte[] bodycontents          = Encoding.UTF8.GetBytes(exceptedUpdateContent);
                string identifier            = Guid.NewGuid().ToString("N");

                int             statusCode    = 0;
                HttpWebResponse errorResponse = null;
                try
                {
                    // Update a file on the WOPI server.
                    WOPIHttpResponse httpWebResponseOfPutFile = WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifier);
                    statusCode = httpWebResponseOfPutFile.StatusCode;
                }
                catch (WebException webEx)
                {
                    errorResponse = this.GetErrorResponseFromWebException(webEx);
                    statusCode    = this.GetStatusCodeFromHTTPResponse(errorResponse);
                }

                // Verify MS-WOPI requirement: MS-WOPI_R690
                this.Site.CaptureRequirementIfAreEqual(
                    409,
                    statusCode,
                    690,
                    @"[In PutFile] Status code ""409"" means ""Lock mismatch"".");

                if (Common.IsRequirementEnabled("MS-WOPI", 685003, this.Site))
                {
                    // Verify MS-WOPI requirement: MS-WOPI_R685003
                    this.Site.CaptureRequirementIfIsTrue(
                        errorResponse.Headers.Get("X-WOPI-Lock") != null,
                        685003,
                        @"[In PutFile] This header [X-WOPI-Lock] MUST be included when responding with the 409 status code. ");

                    // Verify MS-WOPI requirement: MS-WOPI_R980001
                    this.Site.CaptureRequirementIfIsTrue(
                        errorResponse.Headers.Get("X-WOPI-Lock") != null,
                        980001,
                        @"[In PutFile] an X-WOPI-Lock response header containing the value of the current lock on the file MUST be included when using this response code [409].");

                    Boolean VerifyR685005 = false;
                    for (int i = 0; i < errorResponse.Headers.Count; i++)
                    {
                        if (errorResponse.Headers.AllKeys[i] == "X-WOPI-Lock")
                        {
                            VerifyR685005 = true;
                            break;
                        }
                    }
                    // Verify MS-WOPI requirement: MS-WOPI_R685005
                    this.Site.CaptureRequirementIfIsTrue(
                        VerifyR685005,
                        685005,
                        @"[In PutFile] X-WOPI-Lock is a string.");
                }

                if (Common.IsRequirementEnabled("MS-WOPI", 685009001, this.Site))
                {
                    // Verify MS-WOPI requirement: MS-WOPI_R685009001
                    this.Site.CaptureRequirementIfIsTrue(
                        string.IsNullOrEmpty(errorResponse.Headers.Get("X-WOPI-LockFailureReason")),
                        685009001,
                        @"[In PutFile] Implementation does not include the header X-WOPI-LockFailureReason when responding with the 409 status code. (SharePoint Foundation 2010 and above follows this behavior).");
                }

                if (Common.IsRequirementEnabled("MS-WOPI", 685012001, this.Site))
                {
                    // Verify MS-WOPI requirement: MS-WOPI_R685012001
                    this.Site.CaptureRequirementIfIsTrue(
                        string.IsNullOrEmpty(errorResponse.Headers.Get("X-WOPI-LockedByOtherInterface")),
                        685012001,
                        @"[In PutFile] Implementation does not include the header X-WOPI-LockedByOtherInterface  when responding with the 409 status code. (SharePoint Foundation 2010 and above follows this behavior).");
                }
            }
            finally
            {
                // Release a lock for editing a file.
                commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
                WopiAdapter.UnLock(wopiTargetFileUrl, commonHeaders, identifierForLock);
            }
        }