public void ICanSerializeAndDeserializeAChangeRequestPassthroughWithNullFields() { var responseObject = new PassthroughResponse() { Data = null, Error = null }; // SERIALIZE THE RESPONSE var serializedPassthroughResponse = new ClusterProvisioningServerPayloadConverter(); var serializedOpResponse = serializedPassthroughResponse.SerailizeChangeRequestResponse(responseObject); // now deseialize it var deserialized = new PayloadConverter().DeserializeConnectivityResponse(serializedOpResponse); }
public void ICanSerializeAndDeserializeAGetOperationStatusWithNilData() { var serializedOpResponse = "<PassthroughResponse xmlns='http://schemas.microsoft.com/hdinsight/2013/05/management' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><Data i:nil='true'/><Error><StatusCode>NotFound</StatusCode><ErrorId>INVALID_PASSTHROUGHREQUEST</ErrorId><ErrorMessage>INVALID_PASSTHROUGHREQUEST</ErrorMessage></Error></PassthroughResponse>"; // now deseialize it var deserialized = new PayloadConverter().DeserializeConnectivityResponse(serializedOpResponse); Assert.IsNotNull(deserialized, "Nothing was returned from the deserializer."); Assert.IsNotNull(deserialized.ErrorDetails, "No error object was present after deserialization."); Assert.AreEqual(deserialized.ErrorDetails.ErrorId, "INVALID_PASSTHROUGHREQUEST"); Assert.AreEqual(deserialized.ErrorDetails.ErrorMessage, "INVALID_PASSTHROUGHREQUEST"); }
public void ICanSerializeAndDeserializeAGetOperationStatusWithNoErrorDetails() { var responseObject = new UserChangeOperationStatusResponse() { OperationType = UserChangeOperationType.Enable, UserType = UserType.Http, RequestIssueDate = DateTime.UtcNow, State = UserChangeOperationState.Completed, Error = null }; var passthroughOpStatus = new PassthroughResponse() { Data = responseObject, Error = null }; // serialize the non error response var serializedPassthroughResponse = new ClusterProvisioningServerPayloadConverter(); var serializedOpResponse = serializedPassthroughResponse.SerailizeChangeRequestResponse(passthroughOpStatus); // now deseialize it var deserialized = new PayloadConverter().DeserializeConnectivityStatus(serializedOpResponse); Assert.IsNotNull(deserialized, "Nothing was returned from the deserializer."); Assert.IsNotNull(deserialized.Data, "No data object was present after deserialization."); Assert.AreEqual(responseObject.OperationType.ToString(), deserialized.Data.OperationType.ToString(), "The OperationType did not match after deserialization."); Assert.AreEqual(responseObject.RequestIssueDate, deserialized.Data.RequestIssueDate, "The IssueDate did not match after deserialization."); Assert.AreEqual(responseObject.State.ToString(), deserialized.Data.State.ToString(), "The State did not match after deserialization."); Assert.AreEqual(responseObject.UserType.ToString(), deserialized.Data.UserType.ToString(), "The user type not match after deserialization."); }
public void ICanSerializeAndDeserializeAGetOperationStatusWithErrorDetails() { var errorStatusCode = HttpStatusCode.NotAcceptable; var errorIdDetails = "Error123"; var errorMessageDetails = "This is an error!"; ErrorDetails errorDetails = new ErrorDetails() { StatusCode = errorStatusCode, ErrorId = errorIdDetails, ErrorMessage = errorMessageDetails }; var userChangeResponse = new UserChangeOperationStatusResponse() { OperationType = UserChangeOperationType.Enable, UserType = UserType.Http, RequestIssueDate = DateTime.UtcNow, State = UserChangeOperationState.Completed, Error = errorDetails }; var responseObject = new PassthroughResponse() { Data = userChangeResponse, Error = errorDetails }; // SERIALIZE THE RESPONSE var serializedPassthroughResponse = new ClusterProvisioningServerPayloadConverter(); var serializedOpResponse = serializedPassthroughResponse.SerailizeChangeRequestResponse(responseObject); // now deseialize it var deserialized = new PayloadConverter().DeserializeConnectivityStatus(serializedOpResponse); Assert.IsNotNull(deserialized, "Nothing was returned from the deserializer."); Assert.IsNotNull(deserialized.ErrorDetails, "No error object was present after deserialization."); Assert.AreEqual(responseObject.Error.ErrorId, deserialized.ErrorDetails.ErrorId, "The Error Id did not match after deserialization."); Assert.AreEqual(responseObject.Error.ErrorMessage, deserialized.ErrorDetails.ErrorMessage, "The error message did not match after deserialization."); Assert.AreEqual(responseObject.Error.StatusCode, deserialized.ErrorDetails.StatusCode, "The status code did not match after deserialization."); Assert.IsNotNull(deserialized.Data, "No data object was present after deserialization."); Assert.AreEqual(userChangeResponse.OperationType.ToString(), deserialized.Data.OperationType.ToString(), "The OperationType did not match after deserialization."); Assert.AreEqual(userChangeResponse.RequestIssueDate, deserialized.Data.RequestIssueDate, "The IssueDate did not match after deserialization."); Assert.AreEqual(userChangeResponse.State.ToString(), deserialized.Data.State.ToString(), "The State did not match after deserialization."); Assert.AreEqual(userChangeResponse.UserType.ToString(), deserialized.Data.UserType.ToString(), "The user type not match after deserialization."); Assert.IsNotNull(deserialized.Data.ErrorDetails, "No error object was present after deserialization."); Assert.AreEqual(userChangeResponse.Error.ErrorId, deserialized.Data.ErrorDetails.ErrorId, "The (inner) Error Id did not match after deserialization."); Assert.AreEqual(userChangeResponse.Error.ErrorMessage, deserialized.Data.ErrorDetails.ErrorMessage, "The (inner) error message did not match after deserialization."); Assert.AreEqual(userChangeResponse.Error.StatusCode, deserialized.Data.ErrorDetails.StatusCode, "The (inner) status code did not match after deserialization."); }
public async Task UnregisterSubscriptionLocation(string location) { await Task.Delay(TimeSpan.FromMilliseconds(1)); lock (locker) { var managementClient = ServiceLocator.Instance.Locate<IHDInsightManagementRestClientFactory>().Create(this.credentials, IntegrationTestBase.GetAbstractionContext(), false); var payload = managementClient.ListCloudServices().WaitForResult(); var clusters = new PayloadConverter().DeserializeListContainersResult(payload.Content, this.credentials.DeploymentNamespace, this.credentials.SubscriptionId); if (clusters.Any(cluster => cluster.Location == location)) { throw new InvalidOperationException("Cannot unregister a subscription location if it contains clusters"); } List<string> registeredLocations; if (!subcriptions.TryGetValue(credentials.SubscriptionId, out registeredLocations)) throw new InvalidOperationException("Invalid subscription"); // The service doesn't fail if the location wasn't registered if (!registeredLocations.Any(registeredLocation => string.Equals(registeredLocation, location))) { var resolver = ServiceLocator.Instance.Locate<ICloudServiceNameResolver>(); string regionCloudServicename = resolver.GetCloudServiceName(this.credentials.SubscriptionId, this.credentials.DeploymentNamespace, location); throw new HttpLayerException( HttpStatusCode.NotFound, string.Format("The cloud service with name {0} was not found.", regionCloudServicename)); } registeredLocations.Remove(registeredLocations.First(registeredLocation => string.Equals(registeredLocation, location))); } }