public void MSWOPI_S17_TC17_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 the common header.
WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
int statusCodeOfLock;
string lockIdentifierValue = Guid.NewGuid().ToString("N");
// Take a lock for editing a file.
WOPIHttpResponse httpWebResponseForLock = WopiAdapter.Lock(wopiTargetFileUrl, commonHeaders, lockIdentifierValue);
bool isWebExceptionRaise = false;
bool isDeleteFileSuccessful = false;
try
{
statusCodeOfLock = httpWebResponseForLock.StatusCode;
// Verify MS-WOPI requirement: MS-WOPI_R405
this.Site.CaptureRequirementIfAreEqual(
200,
statusCodeOfLock,
405,
@"[In Lock] Status code ""200"" means ""Success"".");
// Get the common header.
commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
try
{
// Delete this file which is locked.
WopiAdapter.DeleteFile(wopiTargetFileUrl, commonHeaders);
// The file has been deleted, so remove it from the clean up list.
this.ExcludeFileFromTheCleanUpProcess(fileUrl);
isDeleteFileSuccessful = true;
}
catch (WebException webEx)
{
isWebExceptionRaise = true;
HttpWebResponse errorResponse = this.GetErrorResponseFromWebException(webEx);
this.GetStatusCodeFromHTTPResponse(errorResponse);
}
// Verify MS-WOPI requirement: MS-WOPI_R256
this.Site.CaptureRequirementIfIsTrue(
isWebExceptionRaise,
256,
@"[In HTTP://server/<...>/wopi*/files/<id>] Operation ""Lock"" is used for ""Takes a lock for editing a file"".");
// Verify MS-WOPI requirement: MS-WOPI_R390
this.Site.CaptureRequirementIfIsTrue(
isWebExceptionRaise,
390,
@"[In Lock] Take a lock for editing a file.");
// The URI in "Lock" WOPI request follow the "HTTP://server/<...>/wopi*/files/<id>?access_token=<token>" pattern, if the operation execute successfully, capture R660
// Verify MS-WOPI requirement: MS-WOPI_R391
this.Site.CaptureRequirement(
391,
@"[In Lock] HTTP Verb: POST
URI: HTTP://server/<...>/wopi*/files/<id>?access_token=<token>");
// If the WOPI server perform the LOCK operation successfully with the specified lock indentifier in X-WOPI-Lock header, then capture R397, R411
// Verify MS-WOPI requirement: MS-WOPI_R397
this.Site.CaptureRequirement(
397,
@"[In Lock] X-WOPI-Lock is a string provided by the WOPI client that the WOPI server MUST use to identify the lock on the file.");
// Verify MS-WOPI requirement: MS-WOPI_R411
this.Site.CaptureRequirement(
411,
@"[In Processing Details] The WOPI server MUST use the string provided in the X-WOPI-Lock header to create a lock on a file.");
}
finally
{
if (!isDeleteFileSuccessful)
{
// Release a lock for editing a file.
commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl);
WopiAdapter.UnLock(wopiTargetFileUrl, commonHeaders, lockIdentifierValue);
}
}
}