/// <summary> /// Verifies the data service response. /// </summary> /// <param name="responseData">The expected data for the response.</param> /// <param name="response">The response to verify.</param> /// <param name="cachedOperationsFromResponse">The individual operation responses, pre-enumerated and cached</param> /// <exception cref="TaupoNotSupportedException"> /// When exception is expected in the response data /// </exception> public void VerifyDataServiceResponse(DataServiceResponseData responseData, DataServiceResponse response, IList <OperationResponse> cachedOperationsFromResponse) { ExceptionUtilities.CheckArgumentNotNull(responseData, "responseData"); ExceptionUtilities.CheckArgumentNotNull(response, "response"); ExceptionUtilities.CheckArgumentNotNull(cachedOperationsFromResponse, "cachedOperationsFromResponse"); ExceptionUtilities.CheckAllRequiredDependencies(this); this.Assert.AreEqual(responseData.IsBatchResponse, response.IsBatchResponse, "Verifying if it's a batch response."); this.Assert.AreEqual(responseData.BatchStatusCode, response.BatchStatusCode, "Verifying batch status code."); //// No batch headers verification //// Note: verifying order of operation responses as well as the content. this.Assert.AreEqual(responseData.Count, cachedOperationsFromResponse.Count, "Unexpected number of operation responses in data service response"); for (int responseOrder = 0; responseOrder < responseData.Count; responseOrder++) { var operationResponseData = responseData[responseOrder]; var currentResponse = cachedOperationsFromResponse[responseOrder]; ChangeOperationResponseData changeResponseData = operationResponseData as ChangeOperationResponseData; if (changeResponseData != null) { ChangeOperationResponse changeResponse = currentResponse as ChangeOperationResponse; this.Assert.IsNotNull(changeResponse, GetVerificationFailureMessage(responseOrder, "Unexpected type of the operation response.\r\nExpected: {0}\r\nActual: {1}", typeof(ChangeOperationResponse).FullName, currentResponse)); this.VerifyChangeOperationResponse(changeResponseData, changeResponse, responseOrder); } else { throw new TaupoNotSupportedException( GetVerificationFailureMessage(responseOrder, "Verification for the operation response data of type '{0}' is not supported by this verifier.", operationResponseData.GetType().FullName)); } } }
private void VerifyChangeOperationResponse(ChangeOperationResponseData expected, ChangeOperationResponse actual, int responseOrder) { this.Assert.IsNotNull(actual.Descriptor, GetVerificationFailureMessage(responseOrder, "Change operation response descriptor should not be null!")); this.VerifyDescriptor(expected.DescriptorData, actual.Descriptor, responseOrder); this.Assert.AreEqual( expected.StatusCode, actual.StatusCode, GetVerificationFailureMessage(responseOrder, "Status code verification failed for the change operation response data: {0}.", expected)); // No headers verification // Verify exceptions if (!string.IsNullOrEmpty(expected.ExceptionId)) { throw new TaupoNotSupportedException( string.Format( CultureInfo.InvariantCulture, "Change operation response data with order {0} has non-null exception id '{1}'. This verifier does not support exception verification.", responseOrder, expected.ExceptionId)); } this.Assert.IsNull(actual.Error, GetVerificationFailureMessage(responseOrder, "Unexpected exception thrown:\r\n{0}", actual.Error)); this.Assert.AreEqual( expected.DescriptorData.State.ToProductEnum(), actual.Descriptor.State, GetVerificationFailureMessage(responseOrder, "Descriptor State verification failed for the change operation response data: {0}.", expected)); }
private void UpdateResponse(DataServiceResponseData responseData, DescriptorData descriptor, HttpResponseData response) { var operationResponse = new ChangeOperationResponseData(descriptor); operationResponse.StatusCode = (int)response.StatusCode; foreach (var header in response.Headers) { operationResponse.Headers.Add(header.Key, header.Value); } responseData.Add(operationResponse); }