This class specifies changes sub-request.
Inheritance: FsshttpbCellSubRequest
        public void TestCase_S13_TC01_PutChanges_ValidExpectedStorageIndexExtendedGUID()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Query changes from the protocol server
            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            CellStorageResponse queryResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { queryChange });
            CellSubResponseType querySubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(queryResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(querySubResponse.ErrorCode, this.Site), "The operation QueryChanges should succeed.");
            FsshttpbResponse fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(querySubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(fsshttpbResponse, this.Site);
            ExGuid storageIndex = fsshttpbResponse.CellSubResponses[0].GetSubResponseData<QueryChangesSubResponseData>().StorageIndexExtendedGUID;

            // Create a putChanges cellSubRequest
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            putChange.ExpectedStorageIndexExtendedGUID = storageIndex;
            dataElements.AddRange(fsshttpbResponse.DataElementPackage.DataElements);
            cellRequest.AddSubRequest(putChange, dataElements);
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());

            // Put changes to the protocol server
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            // Expect the operation succeeds
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site), "The PutChanges operation should succeed.");

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // Verify MS-FSSHTTPB requirement: MS-FSSHTTPB_R936
                Site.CaptureRequirementIfAreEqual<ErrorCodeType>(
                         ErrorCodeType.Success,
                         SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                         "MS-FSSHTTPB",
                         936,
                         @"[In Put Changes] Expected Storage Index Extended GUID (variable): If the expected storage index was specified and the key that is to be updated in the protocol server’s storage index exists in the expected storage index, the corresponding values in the protocol server’s storage index and the expected storage index MUST match.");
            }
            else
            {
                Site.Assert.AreEqual<ErrorCodeType>(
                    ErrorCodeType.Success,
                    SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                    @"[In Put Changes] Expected Storage Index Extended GUID (variable): If the expected storage index was specified and the key that is to be updated in the protocol server’s storage index exists in the expected storage index, the corresponding values in the protocol server’s storage index and the expected storage index MUST match.");
            }

            fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(fsshttpbResponse, this.Site);
        }
        public void TestCase_S13_TC15_PutChanges_Reserved()
        {
            if (!Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 99108, this.Site))
            {
                Site.Assume.Inconclusive("Implementation does not support the Additional Flags.");
            }

            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create a putChanges cellSubRequest Reserved set to zero.
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
            PutChangesCellSubRequest putChangeFirst = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            putChangeFirst.IsAdditionalFlagsUsed = true;
            putChangeFirst.Reserve = 0;
            cellRequest.AddSubRequest(putChangeFirst, dataElements);
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            CellStorageResponse response = this.Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "The first PutChanges operation should succeed.");

            // Extract the first fsshttpb subResponse            
            FsshttpbResponse fsshttpbResponseFirst = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            // Create another putChanges subRequest with Reserved set to 1.
            cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            PutChangesCellSubRequest putChangeSecond = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            putChangeSecond.IsAdditionalFlagsUsed = true;
            putChangeSecond.Reserve = 1;
            cellRequest.AddSubRequest(putChangeSecond, dataElements);
            cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            response = this.Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });

            // Extract the second fsshttpb subResponse            
            cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "The second PutChanges operation should succeed.");
            FsshttpbResponse fsshttpbResponseSecond = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            // If the main part of the two subResponse is same, then capture MS-FSSHTTPB requirement: MS-FSSHTTPB_R990271
            bool isVerifiedR99054 = SharedTestSuiteHelper.CompareSucceedFsshttpbPutChangesResponse(fsshttpbResponseFirst, fsshttpbResponseSecond, this.Site);
            this.Site.Log.Add(TestTools.LogEntryKind.Debug, "Expect the two put changes responses are same, actual {0}", isVerifiedR99054);

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                Site.CaptureRequirementIfIsTrue(
                         isVerifiedR99054,
                         "MS-FSSHTTPB",
                         99054,
                         @"[Additional Flags] The server response is the same whether the Reserved (11 bits) Flag is set to 0 or 1.");
            }
            else
            {
                Site.Assert.IsTrue(
                    isVerifiedR99054,
                    "[Additional Flags] The server response is the same whether the Reserved (11 bits) Flag is set to 0 or 1.");
            }
        }
        public void TestCase_S13_TC14_PutChanges_EAbort()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create a putChanges cellSubRequest E-Abort Remaining Put Changes On Failure (1 bit) set to zero.
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            putChange.AbortRemainingPutChangesOnFailure = 0;
            cellRequest.AddSubRequest(putChange, dataElements);
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            CellStorageResponse response = this.Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "The first PutChanges operation should succeed.");

            // Extract the fsshttpb response
            FsshttpbResponse fsshttpbResponseFirst = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            // Create a putChanges cellSubRequest E-Abort Remaining Put Changes On Failure (1 bit) set to 1.
            cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            putChange.AbortRemainingPutChangesOnFailure = 1;
            cellRequest.AddSubRequest(putChange, dataElements);
            cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            response = this.Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "The second PutChanges operation should succeed.");

            // Extract the fsshttpb response
            FsshttpbResponse fsshttpbResponseSecond = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            // If the main part of the two subResponse is same, then capture MS-FSSHTTPB requirement: MS-FSSHTTPB_R990271
            bool isVerifiedR51801 = SharedTestSuiteHelper.CompareSucceedFsshttpbPutChangesResponse(fsshttpbResponseFirst, fsshttpbResponseSecond, this.Site);
            this.Site.Log.Add(TestTools.LogEntryKind.Debug, "Expect the two put changes responses are same, actual {0}", isVerifiedR51801);

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                Site.CaptureRequirementIfIsTrue(
                         isVerifiedR51801,
                         "MS-FSSHTTPB",
                         51801,
                         @"[In Put Changes] Whenever the E - Abort Remaining Put Changes on Failure field is set to 0 or 1, the protocol server must return the same response.");
            }
            else
            {
                Site.Assert.IsTrue(isVerifiedR51801, @"[In Put Changes] Whenever the E - Abort Remaining Put Changes on Failure field is set to 0 or 1, the protocol server must return the same response.");
            }
        }
        public void TestCase_S13_TC09_PutChanges_DataPackageReservedIgnore()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create a putChanges cellSubRequest without specified ExpectedStorageIndexExtendedGUID attribute and Imply Null Expected if No Mapping flag set to zero
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            cellRequest.AddSubRequest(putChange, dataElements);

            // Make the DataElementPackage reserved value to 0.
            cellRequest.DataElementPackage.Reserved = 0;
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes operation on the file {0} succeed.",
                this.DefaultFileUrl);

            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponse, this.Site);

            // Create a putChanges cellSubRequest without specified ExpectedStorageIndexExtendedGUID attribute and Imply Null Expected if No Mapping flag set to zero
            FsshttpbCellRequest cellRequestSecond = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuidSecond;
            List<DataElement> dataElementsSecond = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuidSecond);
            PutChangesCellSubRequest putChangeSecond = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuidSecond);
            cellRequestSecond.AddSubRequest(putChangeSecond, dataElementsSecond);

            // Make the DataElementPackage reserved value to 1.
            cellRequestSecond.DataElementPackage.Reserved = 1;
            CellSubRequestType cellSubRequestSecond = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequestSecond.ToBase64());
            CellStorageResponse responseSecond = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequestSecond });
            CellSubResponseType cellSubResponseSecond = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(responseSecond, 0, 0, this.Site);

            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponseSecond.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes operation on the file {0} succeed.",
                this.DefaultFileUrl);

            FsshttpbResponse putChangeResponseSecond = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponseSecond, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponseSecond, this.Site);

            // Compare this two responses roughly, and if these two response are identical in main part, then capture the requirement MS-FSSHTTPB_R371
            bool isVerifyR371 = SharedTestSuiteHelper.CompareSucceedFsshttpbPutChangesResponse(putChangeResponse, putChangeResponseSecond, this.Site);

            this.Site.Log.Add(TestTools.LogEntryKind.Debug, "Expect the two put changes responses are same, actual {0}", isVerifyR371);

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // Verify MS-FSSHTTPB requirement: MS-FSSHTTPB_R371
                Site.CaptureRequirementIfIsTrue(
                         isVerifyR371,
                         "MS-FSSHTTPB",
                         371,
                         @"[In Data Element Package] Whenever the Reserved field is set to 0 or 1, the protocol server must return the same response.");
            }
            else
            {
                Site.Assert.IsTrue(
                    isVerifyR371,
                    @"[In Data Element Package] Whenever the Reserved field is set to 0 or 1, the protocol server must return the same response.");
            }
        }
        public void TestCase_S13_TC10_PutChanges_Partial()
        {
            string fileUrl = Common.GetConfigurationPropertyValue("BigFile", this.Site);

            // Initialize the service
            this.InitializeContext(fileUrl, this.UserName01, this.Password01, this.Domain);

            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            CellStorageResponse response = Adapter.CellStorageRequest(fileUrl, new SubRequestType[] { queryChange });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            this.Site.Assert.AreEqual<ErrorCodeType>(
                        ErrorCodeType.Success,
                        SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                        @"Test case cannot continue unless the query change operation succeeds.");

            FsshttpbResponse fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(fsshttpbResponse, this.Site);

            // Get the file contents
            byte[] bytes = new RootNodeObject.RootNodeObjectBuilder()
                                            .Build(fsshttpbResponse.DataElementPackage.DataElements, fsshttpbResponse.CellSubResponses[0].GetSubResponseData<QueryChangesSubResponseData>().StorageIndexExtendedGUID)
                                            .GetContent()
                                            .ToArray();

            // Update file contents
            byte[] newBytes = SharedTestSuiteHelper.GenerateRandomFileContent(Site);
            System.Array.Copy(newBytes, 0, bytes, 0, newBytes.Length);

            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(bytes, out storageIndexExGuid);

            // Send the first partial put changes sub request null storageIndexExGuid.
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), null);

            cellRequest.AddSubRequest(putChange, dataElements.Take(4).ToList());
            putChange.Partial = 1;
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            response = Adapter.CellStorageRequest(fileUrl, new SubRequestType[] { cellSubRequest });
            cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            // Expect the operation succeeds
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site), "The PutChanges operation should succeed.");
            fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(fsshttpbResponse, this.Site);

            // Send the last partial put changes sub request
            cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            putChange.PartialLast = 1;
            cellRequest.AddSubRequest(putChange, dataElements.Skip(4).ToList());

            cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            cellSubRequest.SubRequestData.CoalesceSpecified = true;
            cellSubRequest.SubRequestData.Coalesce = true;
            response = Adapter.CellStorageRequest(fileUrl, new SubRequestType[] { cellSubRequest });
            cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site), "The PutChanges operation should succeed.");
            fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(fsshttpbResponse, this.Site);
        }
        public void TestCase_S01_TC19_UploadContents_Success_PartitionID()
        {
            // Initialize the context using user01 and defaultFileUrl.
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // A client using protocol version 2.2 uploads content with PartitionID attribute specified.
            CellSubRequestType putChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedPutChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), SharedTestSuiteHelper.GenerateRandomFileContent(this.Site));
            putChange.SubRequestData.PartitionID = "00000000-0000-0000-0000-000000000000";
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { putChange });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual<ErrorCodeType>(
                         ErrorCodeType.Success,
                         SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                         "The test case cannot continue unless the update file contents succeed.");

            // If the server version is 2.2, it should also accept the client version 2.0
            if (response.ResponseVersion.Version >= 2 && response.ResponseVersion.MinorVersion >= 2)
            {
                putChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedPutChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), SharedTestSuiteHelper.GenerateRandomFileContent(this.Site));
                putChange.SubRequestData.PartitionID = "00000000-0000-0000-0000-000000000000";
                response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { putChange }, "1", 2, 0, null, null);
                cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

                if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                {
                    // If the server responds with "Success" to both client 2.0 and 2.2 (the above step), then requirement MS-FSSHTTP_R1829 is captured.
                    Site.CaptureRequirementIfAreEqual<ErrorCodeType>(
                             ErrorCodeType.Success,
                             SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                             "MS-FSSHTTP",
                             1829,
                             @"[In CellSubRequestDataOptionalAttributes][PartitionID] A protocol server that has a version number of 2.2 MUST accept a PartitionID attribute from clients using protocol numbers of 2.0 and 2.2.[The value of PartitionID for the file contents is ""00000000-0000-0000-0000-000000000000""]");
                }
                else
                {
                    Site.Assert.AreEqual<ErrorCodeType>(
                        ErrorCodeType.Success,
                        SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                        @"[In CellSubRequestDataOptionalAttributes][PartitionID] A protocol server that has a version number of 2.2 MUST accept a PartitionID attribute from clients using protocol numbers of 2.0 and 2.2.[The value of PartitionID for the file contents is ""00000000-0000-0000-0000-000000000000""]");
                }
            }

            // If the server version is 2.2, it also should support the partition id defined in the MS-FSSHTTPB.
            if (response.ResponseVersion.Version >= 2 && response.ResponseVersion.MinorVersion >= 2)
            {
                FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
                ExGuid storageIndexExGuid;
                List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(Site), out storageIndexExGuid);
                PutChangesCellSubRequest putChangeFsshttpb = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
                cellRequest.AddSubRequest(putChangeFsshttpb, dataElements);
                putChangeFsshttpb.IsPartitionIDGUIDUsed = true;
                putChangeFsshttpb.PartitionIdGUID = Guid.Empty;

                CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
                cellSubRequest.SubRequestData.PartitionID = null;

                response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
                cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
                this.Site.Assert.AreEqual<ErrorCodeType>(
                             ErrorCodeType.Success,
                             SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                             "For the server version is number of 2.2 or greater, the server should accept the Partition id attribute defined in the MS-FSSHTTPB");
            }

            if (Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 213802, this.Site))
            {
                FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
                ExGuid storageIndexExGuid;
                List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
                PutChangesCellSubRequest putChangeFsshttpb = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
                cellRequest.AddSubRequest(putChangeFsshttpb, dataElements);
                putChangeFsshttpb.IsPartitionIDGUIDUsed = true;
                putChangeFsshttpb.PartitionIdGUID = Guid.Empty;

                CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
                cellSubRequest.SubRequestData.PartitionID = null;

                response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
                cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

                if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                {
                    Site.CaptureRequirementIfAreEqual<ErrorCodeType>(
                             ErrorCodeType.Success,
                             SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                             "MS-FSSHTTPB",
                             213802,
                             @"[In Appendix B: Product Behavior]  Implementation does support the Target Partition Id field. (<4> Section 2.2.2.1:  SharePoint Server 2013 and above support the Target Partition Id field.)");
                }
                else
                {
                    Site.Assert.AreEqual<ErrorCodeType>(
                             ErrorCodeType.Success,
                             SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                             @"[In Appendix B: Product Behavior]  Implementation does support the Target Partition Id field. (<4> Section 2.2.2.1:  SharePoint Server 2013 and above support the Target Partition Id field.)");
                }
            }
        }
        public void TestCase_S13_TC08_PutChanges_FavorCoherencyFailureOverNotFound()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Query changes from the protocol server
            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            CellStorageResponse queryResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { queryChange });
            CellSubResponseType querySubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(queryResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(querySubResponse.ErrorCode, this.Site), "The operation QueryChanges should succeed.");
            FsshttpbResponse fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(querySubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(fsshttpbResponse, this.Site);

            // Put changes to upload the content once.
            CellSubRequestType putChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedPutChanges((ulong)SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), System.Text.Encoding.UTF8.GetBytes(SharedTestSuiteHelper.GenerateRandomString(5)));
            CellStorageResponse putResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { putChange });
            CellSubResponseType putSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(putResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(putSubResponse.ErrorCode, this.Site), "The operation PutChanges should succeed.");
            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(putSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponse, this.Site);

            // Create a putChanges cellSubRequest with nonexistent ExpectedStorageIndexExtendedGUID
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(System.Text.Encoding.Unicode.GetBytes(Common.GenerateResourceName(this.Site, this.DefaultFileUrl)), out storageIndexExGuid);
            PutChangesCellSubRequest putChangeSecond = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            putChangeSecond.ExpectedStorageIndexExtendedGUID = fsshttpbResponse.CellSubResponses[0].GetSubResponseData<QueryChangesSubResponseData>().StorageIndexExtendedGUID;

            // Favor the coherency failure other than not found element.
            putChangeSecond.FavorCoherencyFailureOverNotFound = 1;

            cellRequest.AddSubRequest(putChangeSecond, dataElements);
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());

            // Put changes to the protocol server
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            // For Microsoft product, in this case the server still responses Referenceddataelementnotfound.
            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                Site.CaptureRequirementIfAreEqual<string>(
                    "referenceddataelementnotfound".ToLower(CultureInfo.CurrentCulture),
                    fsshttpbResponse.CellSubResponses[0].ResponseError.ErrorData.ErrorDetail.ToLower(CultureInfo.CurrentCulture),
                    "MS-FSSHTTPB",
                    51701,
                    @"[In Put Changes] Implementation does return a Referenced Data Element Not Found failure, when D - Favor Coherency Failure Over Not Found is set to 1 and a Referenced Data Element Not Found (section 2.2.3.2.1) failure occurred. (SharePoint 2010 and above follow this behavior.)");
            }
            else
            {
                this.Site.Assert.AreEqual<string>(
                    "Referenceddataelementnotfound".ToLower(CultureInfo.CurrentCulture),
                    fsshttpbResponse.CellSubResponses[0].ResponseError.ErrorData.ErrorDetail.ToLower(CultureInfo.CurrentCulture),
                    "For Microsoft, the server still responses Referenceddataelementnotfound even the FavorCoherencyFailureOverNotFound is set to 1.");
            }
        }
        public void TestCase_S13_TC05_PutChanges_MappingExist_ImplyFlagOne()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Query changes from the protocol server to get the current server storage index extended guid for the specified file.
            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            CellStorageResponse queryResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { queryChange });
            CellSubResponseType querySubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(queryResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(querySubResponse.ErrorCode, this.Site), "The operation QueryChanges should succeed.");
            FsshttpbResponse queryChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(querySubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(queryChangeResponse, this.Site);

            // Restore the current server storage index extended guid. 
            ExGuid storageIndex = queryChangeResponse.CellSubResponses[0].GetSubResponseData<QueryChangesSubResponseData>().StorageIndexExtendedGUID;

            // Create a putChanges cellSubRequest specified the Expected Storage Index Extended GUID tribute and Imply Null Expected if No Mapping flag set to one
            // Also use the server returns the data elements, in this case the key will exist.
            FsshttpbCellRequest cellRequestFirst = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndex);

            // Assign the ImplyNullExpectedIfNoMapping to 1.
            putChange.ImplyNullExpectedIfNoMapping = 1;
            putChange.ExpectedStorageIndexExtendedGUID = storageIndex;
            cellRequestFirst.AddSubRequest(putChange, queryChangeResponse.DataElementPackage.DataElements);
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequestFirst.ToBase64());

            // Put changes to the protocol server to expect the server responds the Coherency failure error.
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site), "The PutChanges operation should succeed.");
        }
        public void TestCase_S13_TC06_PutChanges_NotSpecifiedExpectedStorageIndexExtendedGUID_ImplyFlagOne()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create a putChanges cellSubRequest without specified Expected Storage Index Extended GUID attribute and Imply Null Expected if No Mapping flag set to zero
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(System.Text.Encoding.Unicode.GetBytes(Common.GenerateResourceName(this.Site, "FileContent")), out storageIndexExGuid);
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);

            // Assign the ImplyNullExpectedIfNoMapping equal to 1 to make apply the change with checking the expected storage index value. 
            putChange.ImplyNullExpectedIfNoMapping = 1;
            cellRequest.AddSubRequest(putChange, dataElements);
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());

            // Put changes to the protocol server
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            this.Site.Assert.AreNotEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes operation on the file {0} failed.",
                this.DefaultFileUrl);

            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            CellError cellError = (CellError)putChangeResponse.CellSubResponses[0].ResponseError.ErrorData;
            Site.Assert.AreEqual<CellErrorCode>(
                    CellErrorCode.Coherencyfailure,
                    cellError.ErrorCode,
                    @"[In Put Changes structure] Expected Storage Index Extended GUID (variable): [if Imply Null Expected if No Mapping flag specifies 1,] If the Expected Storage Index Extended GUID is not specified, the protocol server returns a Cell Error failure value of 12 indicating a coherency failure as specified in section 2.2.3.2.1.");
        }
        public void TestCase_S13_TC21_PutChanges_FullFileReplacePut()
        {
            if (!Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 99108, this.Site))
            {
                Site.Assume.Inconclusive("Implementation does not support the Additional Flags.");
            }

            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Query changes from the protocol server
            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            CellStorageResponse queryResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { queryChange });
            CellSubResponseType querySubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(queryResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(querySubResponse.ErrorCode, this.Site), "The operation QueryChanges should succeed.");
            FsshttpbResponse queryChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(querySubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(queryChangeResponse, this.Site);

            // Put changes to upload the content once to change the server state. In this case, the server expected the storage index value is different with previous returned.
            CellSubRequestType putChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedPutChanges((ulong)SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), System.Text.Encoding.UTF8.GetBytes(SharedTestSuiteHelper.GenerateRandomString(5)));
            CellStorageResponse putResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { putChange });
            CellSubResponseType putSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(putResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(putSubResponse.ErrorCode, this.Site), "The operation PutChanges should succeed.");
            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(putSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponse, this.Site);

            // Create a putChanges cellSubRequest with specified ExpectedStorageIndexExtendedGUID value as the step 1 returned and with the full file replace put flag as 1.
            FsshttpbCellRequest cellRequestSecond = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(System.Text.Encoding.UTF8.GetBytes(SharedTestSuiteHelper.GenerateRandomString(5)), out storageIndexExGuid);
            PutChangesCellSubRequest putChangeSecond = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);

            // Specify ExpectedStorageIndexExtendedGUID and FullFileReplacePut flag.
            putChangeSecond.ExpectedStorageIndexExtendedGUID = queryChangeResponse.CellSubResponses[0].GetSubResponseData<QueryChangesSubResponseData>().StorageIndexExtendedGUID;
            putChangeSecond.IsAdditionalFlagsUsed = true;
            putChangeSecond.FullFileReplacePut = 1;
            dataElements.AddRange(queryChangeResponse.DataElementPackage.DataElements);
            cellRequestSecond.AddSubRequest(putChangeSecond, dataElements);

            // Put changes to the protocol server 
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequestSecond.ToBase64());
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreNotEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Due to the Invalid Expected StorageIndexExtendedGUID, the put changes should fail.");
            FsshttpbResponse fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                Site.CaptureRequirementIfAreEqual<CellErrorCode>(
                         CellErrorCode.Coherencyfailure,
                         fsshttpbResponse.CellSubResponses[0].ResponseError.GetErrorData<CellError>().ErrorCode,
                         "MS-FSSHTTPB",
                         9905101,
                         @"[In Appendix B: Product Behavior] Implementation does not bypass a full file save and related checks that would otherwise be unnecessary, when his flag [E – Full File Replace Put (1 bit)] is set. (Microsoft SharePoint Server 2010 and Microsoft SharePoint Workspace 2010 and above follow this behavior.)");
            }
            else
            {
                Site.Assert.AreEqual<CellErrorCode>(
                         CellErrorCode.Coherencyfailure,
                         fsshttpbResponse.CellSubResponses[0].ResponseError.GetErrorData<CellError>().ErrorCode,
                         @"[In Appendix B: Product Behavior] Implementation does not bypass a full file save and related checks that would otherwise be unnecessary, when his flag [E – Full File Replace Put (1 bit)] is set. (Microsoft SharePoint Server 2010 and Microsoft SharePoint Workspace 2010 and above follow this behavior.)");
            }
        }
        public void TestCase_S13_TC03_PutChanges_NotSpecifiedExpectedStorageIndexExtendedGUID_ImplyFlagZero()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create a putChanges cellSubRequest without specified Expected Storage Index Extended GUID attribute and Imply Null Expected if No Mapping flag set to zero
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(System.Text.Encoding.Unicode.GetBytes(Common.GenerateResourceName(this.Site, "FileContent")), out storageIndexExGuid);
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);

            // Assign the ImplyNullExpectedIfNoMapping equal to 0 to make apply the change without checking the expected storage index value. 
            putChange.ImplyNullExpectedIfNoMapping = 0;
            cellRequest.AddSubRequest(putChange, dataElements);
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());

            // Put changes to the protocol server
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes operation on the file {0} succeed.",
                this.DefaultFileUrl);

            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponse, this.Site);

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // If the PutChanges operation succeeds, then capture MS-FSSHTTPB_R939
                Site.CaptureRequirement(
                         "MS-FSSHTTPB",
                         939,
                         @"[In Put Changes structure] Expected Storage Index Extended GUID (variable): If this flag[Imply Null Expected if No Mapping] is zero, the protocol server MUST apply the change without checking the current value.");
            }
        }
        public void TestCase_S13_TC02_PutChanges_InvalidExpectedStorageIndexExtendedGUID()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Query changes from the protocol server
            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            CellStorageResponse queryResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { queryChange });
            CellSubResponseType querySubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(queryResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(querySubResponse.ErrorCode, this.Site), "The operation QueryChanges should succeed.");
            FsshttpbResponse queryChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(querySubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(queryChangeResponse, this.Site);

            // Put changes to upload the content once to change the server state. In this case, the server expected the storage index value is different with previous returned.
            CellSubRequestType putChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedPutChanges((ulong)SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), System.Text.Encoding.UTF8.GetBytes(SharedTestSuiteHelper.GenerateRandomString(5)));
            CellStorageResponse putResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { putChange });
            CellSubResponseType putSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(putResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(putSubResponse.ErrorCode, this.Site), "The operation PutChanges should succeed.");
            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(putSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponse, this.Site);

            // Create a putChanges cellSubRequest with specified ExpectedStorageIndexExtendedGUID value as the step 1 returned.
            FsshttpbCellRequest cellRequestSecond = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(System.Text.Encoding.UTF8.GetBytes(SharedTestSuiteHelper.GenerateRandomString(5)), out storageIndexExGuid);
            PutChangesCellSubRequest putChangeSecond = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);

            // Specify ExpectedStorageIndexExtendedGUID
            putChangeSecond.ExpectedStorageIndexExtendedGUID = queryChangeResponse.CellSubResponses[0].GetSubResponseData<QueryChangesSubResponseData>().StorageIndexExtendedGUID;
            dataElements.AddRange(queryChangeResponse.DataElementPackage.DataElements);

            cellRequestSecond.AddSubRequest(putChangeSecond, dataElements);

            // Put changes to the protocol server 
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequestSecond.ToBase64());
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreNotEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Due to the Invalid Expected StorageIndexExtendedGUID, the put changes should fail.");
            FsshttpbResponse fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // Verify MS-FSSHTTPB requirement: MS-FSSHTTPB_R937
                Site.CaptureRequirementIfAreEqual<CellErrorCode>(
                         CellErrorCode.Coherencyfailure,
                         fsshttpbResponse.CellSubResponses[0].ResponseError.GetErrorData<CellError>().ErrorCode,
                         "MS-FSSHTTPB",
                         937,
                         @"[In Put Changes structure] Expected Storage Index Extended GUID (variable): otherwise[If the expected storage index was specified and the key that is to be updated in the protocol server’s storage index exists in the expected storage index but the corresponding values in the protocol server’s storage index and the expected storage index doesn't match] the protocol server MUST return a Cell Error Coherency failure value of 12 indicating a coherency failure as specified in section 2.2.3.2.1.");
            }
            else
            {
                Site.Assert.AreEqual<CellErrorCode>(
                    CellErrorCode.Coherencyfailure,
                    fsshttpbResponse.CellSubResponses[0].ResponseError.GetErrorData<CellError>().ErrorCode,
                    @"[In Put Changes structure] Expected Storage Index Extended GUID (variable): otherwise[If the expected storage index was specified and the key that is to be updated in the protocol server’s storage index exists in the expected storage index but the corresponding values in the protocol server’s storage index and the expected storage index doesn't match] the protocol server MUST return a Cell Error Coherency failure value of 12 indicating a coherency failure as specified in section 2.2.3.2.1.");
            }
        }
        public void TestCase_S13_TC20_PutChanges_CheckForIdReuse()
        {
            if (!Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 99108, this.Site))
            {
                Site.Assume.Inconclusive("Implementation does not support the Additional Flags.");
            }

            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Query changes from the protocol server
            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            CellStorageResponse queryResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { queryChange });
            CellSubResponseType querySubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(queryResponse, 0, 0, this.Site);
            this.Site.Assert.AreEqual(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(querySubResponse.ErrorCode, this.Site), "The operation QueryChanges should succeed.");
            FsshttpbResponse fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(querySubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(fsshttpbResponse, this.Site);
            var preGroupData = fsshttpbResponse.DataElementPackage.DataElements.First(e => e.DataElementType == DataElementType.ObjectGroupDataElementData);

            // Change the new object group data element's element id as the previous step returned id, this will make the data element id for reusing.
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
            var groupData = dataElements.First(e => e.DataElementType == DataElementType.ObjectGroupDataElementData);
            groupData.DataElementExtendedGUID = preGroupData.DataElementExtendedGUID;

            // Send the upload put changes request with CheckForIdReuse value as 1.
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
            cellRequest.AddSubRequest(putChange, dataElements);
            putChange.IsAdditionalFlagsUsed = true;
            putChange.CheckForIdReuse = 1;
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            fsshttpbResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);

            Site.Assert.AreEqual<CellErrorCode>(
                    CellErrorCode.ExtendedGuidCollision,
                    fsshttpbResponse.CellSubResponses[0].ResponseError.GetErrorData<CellError>().ErrorCode,
                    "When the data element id is reused, the server will respond the error code ExtendedGuidCollision");

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // Verify MS-FSSHTTPB requirement: MS-FSSHTTPB_R99049
                Site.CaptureRequirementIfAreEqual<ErrorCodeType>(
                         ErrorCodeType.CellRequestFail,
                         SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                         "MS-FSSHTTPB",
                         99049,
                         @"[Additional Flags] When D – Coherency Check Only Applied Index Entries (1 bit) is set, the server check the index entry that is actually applied and an index entry that is not applied is not checked.");

                Site.CaptureRequirementIfAreEqual<ErrorCodeType>(
                         ErrorCodeType.CellRequestFail,
                         SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                         "MS-FSSHTTPB",
                         99046,
                         @"[Additional Flags] C – Check for Id Reuse (1 bit): A bit that specifies that the server should attempt to check the Put Changes Request for the re-use of previously used Ids. ");

                Site.CaptureRequirementIfAreEqual<ErrorCodeType>(
                         ErrorCodeType.CellRequestFail,
                         SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                         "MS-FSSHTTPB",
                         99047,
                         @"[Additional Flags] This [check the Put Changes Request for the re-use of previously used Ids] may occur when ID allocations are used and a client rollback occurs.");
            }
            else
            {
                Site.Assert.AreEqual<ErrorCodeType>(
                    ErrorCodeType.CellRequestFail,
                    SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                    @"[Additional Flags] When D - Coherency Check Only Applied Index Entries (1 bit) is set, the server check the index entry that is actually applied and an index entry that is not applied is not checked.");
            }
        }
        public void TestCase_S01_TC22_UploadContents_Success_LockID()
        {
            // Initialize the context using user01 and defaultFileUrl.
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Get a schema lock with all valid parameters, expect the server returns the error code "Success".
            SchemaLockSubRequestType subRequest = SharedTestSuiteHelper.CreateSchemaLockSubRequest(SchemaLockRequestTypes.GetLock, false, null);
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { subRequest });
            SchemaLockSubResponseType schemaLockSubResponse = SharedTestSuiteHelper.ExtractSubResponse<SchemaLockSubResponseType>(response, 0, 0, this.Site);

            Site.Assert.AreEqual<ErrorCodeType>(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(schemaLockSubResponse.ErrorCode, this.Site), "Test case cannot continue unless the Get Lock of SchemaLock sub request succeeds.");
            this.StatusManager.RecordSchemaLock(this.DefaultFileUrl, subRequest.SubRequestData.ClientID, subRequest.SubRequestData.SchemaLockID);

            // If the server version is 2.2, it should also accept the client version 2.0
            if (response.ResponseVersion.Version >= 2 && response.ResponseVersion.MinorVersion >= 2)
            {
                // Update contents using the same SchemaLockId and ByPassLockID as the previous step's SchemaLockId when the coalesce is true.
                CellSubRequestType putChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedPutChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), SharedTestSuiteHelper.GenerateRandomFileContent(this.Site));
                putChange.SubRequestData.SchemaLockID = subRequest.SubRequestData.SchemaLockID;
                putChange.SubRequestData.BypassLockID = subRequest.SubRequestData.SchemaLockID;
                putChange.SubRequestData.CoalesceSpecified = true;
                putChange.SubRequestData.Coalesce = true;

                response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { putChange });
                CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

                this.Site.Assert.AreEqual<ErrorCodeType>(
                        ErrorCodeType.Success,
                        SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                        "When the file is locked by schema lock and the ByPassLockID is specified by the valid schema lock id, the server returns the error code success.");

                FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
                ExGuid storageIndexExGuid;
                List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(Site), out storageIndexExGuid);
                PutChangesCellSubRequest putChangeFsshttpb = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);
                cellRequest.AddSubRequest(putChangeFsshttpb, dataElements);
                putChangeFsshttpb.IsLockIdUsed = true;
                putChangeFsshttpb.LockID = new Guid(subRequest.SubRequestData.SchemaLockID);

                CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
                response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
                cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
                this.Site.Assert.AreEqual<ErrorCodeType>(
                             ErrorCodeType.Success,
                             SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                             "For the server version is number of 2.2 or greater, the server should accept the lock id attribute defined in the MS-FSSHTTPB");

                if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                {
                    // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R1834
                    Site.CaptureRequirement(
                             "MS-FSSHTTP",
                             1834,
                             @"[In CellSubRequestDataOptionalAttributes][BypassLockID] A protocol server that has a version number of 2.2 MUST accept both LockID and BypassLockID.");
                }
            }
        }
        public void TestCase_S13_TC16_PutChanges_ReturnAppliedStorageIndexIdEntries_Zero()
        {
            if (!Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 99108, this.Site))
            {
                Site.Assume.Inconclusive("Implementation does not support the Additional Flags.");
            }

            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create a putChanges cellSubRequest without specified ExpectedStorageIndexExtendedGUID attribute and Imply Null Expected if No Mapping flag set to zero
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);

            // Make the ReturnAppliedStorageIndexIdEntries  value to 0.
            putChange.IsAdditionalFlagsUsed = true;
            putChange.ReturnAppliedStorageIndexIdEntries = 0;
            cellRequest.AddSubRequest(putChange, dataElements);

            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            this.Site.Assert.AreEqual<ErrorCodeType>(
               ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes operation on the file {0} succeed.",
                this.DefaultFileUrl);

            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponse, this.Site);

            bool notInlcudeStorageIndex = putChangeResponse.CellSubResponses[0].GetSubResponseData<PutChangesSubResponseData>().PutChangesResponse != null
                                                 && new ExGuid().Equals(putChangeResponse.CellSubResponses[0].GetSubResponseData<PutChangesSubResponseData>().PutChangesResponse.AppliedStorageIndexID);

            Site.Log.Add(
                TestTools.LogEntryKind.Debug,
                "When the ReturnAppliedStorageIndexIdEntries flag is not set, the server will not return AppliedStorageIndexID, actually it {0} return",
                notInlcudeStorageIndex ? "does not" : "does");

            Site.Assert.IsTrue(
                notInlcudeStorageIndex,
                "When the ReturnAppliedStorageIndexIdEntries flag is not set, the server will not return AppliedStorageIndexID");
        }
        public void TestCase_S13_TC07_PutChanges_Prioriy()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create the first Put changes subRequest with Priority attribute value set to 0.
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuidFirst;
            List<DataElement> dataElementsFirst = DataElementUtils.BuildDataElements(System.Text.Encoding.UTF8.GetBytes("First Content"), out storageIndexExGuidFirst);
            PutChangesCellSubRequest putChangeFirst = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuidFirst);
            putChangeFirst.Priority = 0;
            cellRequest.AddSubRequest(putChangeFirst, dataElementsFirst);

            // Create the second Put changes subRequest with Priority attribute value set to 100.
            ExGuid storageIndexExGuidSecond;
            List<DataElement> dataElementsSecond = DataElementUtils.BuildDataElements(System.Text.Encoding.UTF8.GetBytes("Second Content"), out storageIndexExGuidSecond);
            PutChangesCellSubRequest putChangeSecond = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuidSecond);
            putChangeSecond.Priority = 100;
            cellRequest.AddSubRequest(putChangeSecond, dataElementsSecond);

            // Send PutChanges subRequest to the protocol server.
            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes succeed.");

            // Query changes from the protocol server.
            CellSubRequestType queryChange = SharedTestSuiteHelper.CreateCellSubRequestEmbeddedQueryChanges(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID());
            response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { queryChange });
            cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);
            this.Site.Assert.AreEqual<ErrorCodeType>(
                ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes succeed.");
        }
        public void TestCase_S13_TC17_PutChanges_ReturnAppliedStorageIndexIdEntries_One()
        {
            if (!Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 99108, this.Site))
            {
                Site.Assume.Inconclusive("Implementation does not support the Additional Flags.");
            }

            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Create a putChanges cellSubRequest without specified ExpectedStorageIndexExtendedGUID attribute and Imply Null Expected if No Mapping flag set to zero
            FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
            ExGuid storageIndexExGuid;
            List<DataElement> dataElements = DataElementUtils.BuildDataElements(SharedTestSuiteHelper.GenerateRandomFileContent(this.Site), out storageIndexExGuid);
            PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), storageIndexExGuid);

            // Make the ReturnAppliedStorageIndexIdEntries  value to 1.
            putChange.IsAdditionalFlagsUsed = true;
            putChange.ReturnAppliedStorageIndexIdEntries = 1;
            cellRequest.AddSubRequest(putChange, dataElements);

            CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());
            CellStorageResponse response = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { cellSubRequest });
            CellSubResponseType cellSubResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(response, 0, 0, this.Site);

            this.Site.Assert.AreEqual<ErrorCodeType>(
               ErrorCodeType.Success,
                SharedTestSuiteHelper.ConvertToErrorCodeType(cellSubResponse.ErrorCode, this.Site),
                "Test case cannot continue unless the put changes operation on the file {0} succeed.",
                this.DefaultFileUrl);

            FsshttpbResponse putChangeResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(cellSubResponse, this.Site);
            SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putChangeResponse, this.Site);

            bool isVerifyR99044 = putChangeResponse.CellSubResponses[0].GetSubResponseData<PutChangesSubResponseData>().PutChangesResponse != null
                          && !new ExGuid().Equals(putChangeResponse.CellSubResponses[0].GetSubResponseData<PutChangesSubResponseData>().PutChangesResponse.AppliedStorageIndexID);

            Site.Log.Add(
                TestTools.LogEntryKind.Debug,
                "When the ReturnAppliedStorageIndexIdEntries flag is set, the server will return AppliedStorageIndexID, actually it {0} return",
                isVerifyR99044 ? "does" : "does not");

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // Verify MS-FSSHTTPB requirement: MS-FSSHTTPB_R99044
                Site.CaptureRequirementIfIsTrue(
                         isVerifyR99044,
                         "MS-FSSHTTPB",
                         99044,
                         @"[Additional Flags] A – Return Applied Storage Index Id Entries (1 bit): A bit that specifies that the storage indexes that are applied to the storage as part of the Put Changes will be returned in a Storage Index specified in the Put Changes Response by the Applied Storage Index Id (section 2.2.3.1.3).");

                // Verify MS-FSSHTTPB requirement: MS-FSSHTTPB_R99108
                Site.CaptureRequirement(
                         "MS-FSSHTTPB",
                         99108,
                         @"[Appendix B: Product Behavior] Additional Flags is supported by SharePoint Server 2013.");
            }
            else
            {
                Site.Assert.IsTrue(
                    isVerifyR99044,
                    @"[Additional Flags] A - Return Applied Storage Index Id Entries (1 bit): A bit that specifies that the storage indexes that are applied to the storage as part of the Put Changes will be returned in a Storage Index specified in the Put Changes Response by the Applied Storage Index Id.");
            }
        }
        public void TestCase_S15_TC03_Download_UploadPartial()
        {
            string fileUrl = Common.GetConfigurationPropertyValue("BigFile", this.Site);
            string uploadFileUrl = SharedTestSuiteHelper.GenerateNonExistFileUrl(Site);
            bool partial = false;

            Knowledge knowledge = null;

            // Set the limit number of upload tries, this will allow 500000 * 10 bytes size file to be download and complete upload.
            int limitNumberOfPartialUpload = 10;
            do
            {
                this.InitializeContext(fileUrl, this.UserName01, this.Password01, this.Domain);

                // Create query changes request with allow fragments flag with the value false.
                FsshttpbCellRequest cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
                QueryChangesCellSubRequest queryChange = SharedTestSuiteHelper.BuildFsshttpbQueryChangesSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), 0, false, false, true, 0, true, true, 0, null, 500000, null, knowledge);
                cellRequest.AddSubRequest(queryChange, null);
                CellSubRequestType cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());

                CellStorageResponse cellStorageResponse = this.Adapter.CellStorageRequest(fileUrl, new SubRequestType[] { cellSubRequest });
                CellSubResponseType subResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(cellStorageResponse, 0, 0, this.Site);
                this.Site.Assert.AreEqual<ErrorCodeType>(
                    ErrorCodeType.Success,
                    SharedTestSuiteHelper.ConvertToErrorCodeType(subResponse.ErrorCode, this.Site),
                    "Test case cannot continue unless the query changes succeed.");

                FsshttpbResponse queryResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(subResponse, this.Site);
                SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(queryResponse, this.Site);
                QueryChangesSubResponseData data = queryResponse.CellSubResponses[0].GetSubResponseData<QueryChangesSubResponseData>();
                partial = data.PartialResult;
                knowledge = data.Knowledge;

                this.InitializeContext(uploadFileUrl, this.UserName01, this.Password01, this.Domain);
                cellRequest = SharedTestSuiteHelper.CreateFsshttpbCellRequest();
                PutChangesCellSubRequest putChange = new PutChangesCellSubRequest(SequenceNumberGenerator.GetCurrentFSSHTTPBSubRequestID(), null);
                putChange.Partial = partial ? 1 : 0;
                putChange.PartialLast = partial ? 0 : 1;
                putChange.StorageIndexExtendedGUID = partial ? null : data.StorageIndexExtendedGUID;

                if (partial)
                {
                    var storageIndex = queryResponse.DataElementPackage.DataElements.FirstOrDefault(e => e.DataElementType == DataElementType.StorageIndexDataElementData);
                    if (storageIndex != null)
                    {
                        queryResponse.DataElementPackage.DataElements.Remove(storageIndex);
                    }
                }

                cellRequest.AddSubRequest(putChange, queryResponse.DataElementPackage.DataElements);
                cellSubRequest = SharedTestSuiteHelper.CreateCellSubRequest(SequenceNumberGenerator.GetCurrentToken(), cellRequest.ToBase64());

                cellStorageResponse = this.Adapter.CellStorageRequest(uploadFileUrl, new SubRequestType[] { cellSubRequest });
                subResponse = SharedTestSuiteHelper.ExtractSubResponse<CellSubResponseType>(cellStorageResponse, 0, 0, this.Site);
                this.Site.Assert.AreEqual<ErrorCodeType>(
                    ErrorCodeType.Success,
                    SharedTestSuiteHelper.ConvertToErrorCodeType(subResponse.ErrorCode, this.Site),
                    "Test case cannot continue unless the query changes succeed.");

                FsshttpbResponse putResponse = SharedTestSuiteHelper.ExtractFsshttpbResponse(subResponse, this.Site);
                SharedTestSuiteHelper.ExpectMsfsshttpbSubResponseSucceed(putResponse, this.Site);

                // Decrease the number of upload tries.
                limitNumberOfPartialUpload--;
            }
            while (partial && limitNumberOfPartialUpload > 0);

            this.StatusManager.RecordFileUpload(uploadFileUrl);
        }