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_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_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_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.");
        }