Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder Response.FromValue parameters #7919

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void MockClient()

// Setup client method
mock.Setup(c => c.Get("Key", It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(Response.FromValue(mockResponse.Object, ConfigurationModelFactory.ConfigurationSetting("Key", "Value")));
.Returns(Response.FromValue(ConfigurationModelFactory.ConfigurationSetting("Key", "Value"), mockResponse.Object));

// Use the client mock
ConfigurationClient client = mock.Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ public virtual async Task<Response<bool>> HasChangedAsync(ConfigurationSetting s
etag = etag.Trim('\"');
}

return Response.FromValue(response, setting.ETag != new ETag(etag));
return Response.FromValue(setting.ETag != new ETag(etag), response);

default:
throw await response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -917,7 +917,7 @@ public virtual Response<bool> HasChanged(ConfigurationSetting setting, Cancellat
etag = etag.Trim('\"');
}

return Response.FromValue(response, setting.ETag != new ETag(etag));
return Response.FromValue(setting.ETag != new ETag(etag), response);

default:
throw response.CreateRequestFailedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public partial class ConfigurationClient
private static async Task<Response<ConfigurationSetting>> CreateResponseAsync(Response response, CancellationToken cancellation)
{
ConfigurationSetting result = await ConfigurationServiceSerializer.DeserializeSettingAsync(response.ContentStream, cancellation).ConfigureAwait(false);
return Response.FromValue(response, result);
return Response.FromValue(result, response);
}

private static Response<ConfigurationSetting> CreateResponse(Response response)
{
return Response.FromValue(response, ConfigurationServiceSerializer.DeserializeSetting(response.ContentStream));
return Response.FromValue(ConfigurationServiceSerializer.DeserializeSetting(response.ContentStream), response);
}

private static Response<ConfigurationSetting> CreateResourceModifiedResponse(Response response)
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/src/Operation{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public virtual async ValueTask<Response<T>> WaitCompletionAsync(CancellationToke
await UpdateStatusAsync(cancellationToken).ConfigureAwait(false);
if (HasCompleted)
{
return Response.FromValue(_response, Value);
return Response.FromValue(Value, _response);
}
await Task.Delay(PollingInterval, cancellationToken).ConfigureAwait(false);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/src/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class Response : IDisposable

protected internal abstract IEnumerable<HttpHeader> EnumerateHeaders();

public static Response<T> FromValue<T>(Response response, T value)
public static Response<T> FromValue<T>(T value, Response response)
{
return new ValueResponse<T>(response, value);
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/tests/ResponseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ResponseTests
[Test]
public void ValueIsAccessible()
{
var response = Response.FromValue(response: null, new TestPayload("test_name"));
var response = Response.FromValue(new TestPayload("test_name"), response: null);
TestPayload value = response.Value;

Assert.IsNotNull(value);
Expand All @@ -21,7 +21,7 @@ public void ValueIsAccessible()
[Test]
public void ValueObtainedFromCast()
{
var response = Response.FromValue(response: null, new TestPayload("test_name"));
var response = Response.FromValue(new TestPayload("test_name"), response: null);
TestPayload value = response;

Assert.IsNotNull(value);
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/Azure.Identity/src/AadIdentityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private async Task<AccessToken> SendAuthRequestAsync(Request request, Cancellati
{
AccessToken result = await DeserializeAsync(response.ContentStream, cancellationToken).ConfigureAwait(false);

return Response.FromValue(response, result);
return Response.FromValue(result, response);
}

throw await response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
Expand All @@ -162,7 +162,7 @@ private AccessToken SendAuthRequest(Request request, CancellationToken cancellat
{
AccessToken result = Deserialize(response.ContentStream);

return Response.FromValue(response, result);
return Response.FromValue(result, response);
}

throw response.CreateRequestFailedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public virtual Response<byte[]> BackupCertificate(string name, CancellationToken
{
Response<CertificateBackup> backup = _pipeline.SendRequest(RequestMethod.Post, () => new CertificateBackup(), cancellationToken, CertificatesPath, name, "/backup");

return Response.FromValue(backup.GetRawResponse(), backup.Value.Value);
return Response.FromValue(backup.Value.Value, backup.GetRawResponse());
}
catch (Exception e)
{
Expand Down Expand Up @@ -579,7 +579,7 @@ public virtual async Task<Response<byte[]>> BackupCertificateAsync(string name,
{
Response<CertificateBackup> backup = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new CertificateBackup(), cancellationToken, CertificatesPath, name, "/backup").ConfigureAwait(false);

return Response.FromValue(backup.GetRawResponse(), backup.Value.Value);
return Response.FromValue(backup.Value.Value, backup.GetRawResponse());
}
catch (Exception e)
{
Expand Down Expand Up @@ -1303,7 +1303,7 @@ public virtual Response<IList<Contact>> SetContacts(IEnumerable<Contact> contact
{
Response<ContactList> contactList = _pipeline.SendRequest(RequestMethod.Put, new ContactList(contacts), () => new ContactList(), cancellationToken, ContactsPath);

return Response.FromValue(contactList.GetRawResponse(), contactList.Value.ToList());
return Response.FromValue(contactList.Value.ToList(), contactList.GetRawResponse());
}
catch (Exception e)
{
Expand All @@ -1329,7 +1329,7 @@ public virtual async Task<Response<IList<Contact>>> SetContactsAsync(IEnumerable
{
Response<ContactList> contactList = await _pipeline.SendRequestAsync(RequestMethod.Put, new ContactList(contacts), () => new ContactList(), cancellationToken, ContactsPath).ConfigureAwait(false);

return Response.FromValue(contactList.GetRawResponse(), contactList.Value.ToList());
return Response.FromValue(contactList.Value.ToList(), contactList.GetRawResponse());
}
catch (Exception e)
{
Expand All @@ -1352,7 +1352,7 @@ public virtual Response<IList<Contact>> GetContacts(CancellationToken cancellati
{
Response<ContactList> contactList = _pipeline.SendRequest(RequestMethod.Get, () => new ContactList(), cancellationToken, ContactsPath);

return Response.FromValue(contactList.GetRawResponse(), contactList.Value.ToList());
return Response.FromValue(contactList.Value.ToList(), contactList.GetRawResponse());
}
catch (Exception e)
{
Expand All @@ -1375,7 +1375,7 @@ public virtual async Task<Response<IList<Contact>>> GetContactsAsync(Cancellatio
{
Response<ContactList> contactList = await _pipeline.SendRequestAsync(RequestMethod.Get, () => new ContactList(), cancellationToken, ContactsPath).ConfigureAwait(false);

return Response.FromValue(contactList.GetRawResponse(), contactList.Value.ToList());
return Response.FromValue(contactList.Value.ToList(), contactList.GetRawResponse());
}
catch (Exception e)
{
Expand All @@ -1398,7 +1398,7 @@ public virtual Response<IList<Contact>> DeleteContacts(CancellationToken cancell
{
Response<ContactList> contactList = _pipeline.SendRequest(RequestMethod.Delete, () => new ContactList(), cancellationToken, ContactsPath);

return Response.FromValue(contactList.GetRawResponse(), contactList.Value.ToList());
return Response.FromValue(contactList.Value.ToList(), contactList.GetRawResponse());
}
catch (Exception e)
{
Expand All @@ -1421,7 +1421,7 @@ public virtual async Task<Response<IList<Contact>>> DeleteContactsAsync(Cancella
{
Response<ContactList> contactList = await _pipeline.SendRequestAsync(RequestMethod.Delete, () => new ContactList(), cancellationToken, ContactsPath).ConfigureAwait(false);

return Response.FromValue(contactList.GetRawResponse(), contactList.Value.ToList());
return Response.FromValue(contactList.Value.ToList(), contactList.GetRawResponse());
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private Response<T> ParseResponse<T>(Response response, T result)
case 202:
case 204:
result.Deserialize(response.ContentStream);
return Response.FromValue(response, result);
return Response.FromValue(result, response);
default:
throw response.CreateRequestFailedException();
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ public virtual Response<byte[]> BackupKey(string name, CancellationToken cancell
{
Response<KeyBackup> backup = _pipeline.SendRequest(RequestMethod.Post, () => new KeyBackup(), cancellationToken, KeysPath, name, "/backup");

return Response.FromValue(backup.GetRawResponse(), backup.Value.Value);
return Response.FromValue(backup.Value.Value, backup.GetRawResponse());
}
catch (Exception e)
{
Expand Down Expand Up @@ -870,7 +870,7 @@ public virtual async Task<Response<byte[]>> BackupKeyAsync(string name, Cancella
{
Response<KeyBackup> backup = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new KeyBackup(), cancellationToken, KeysPath, name, "/backup").ConfigureAwait(false);

return Response.FromValue(backup.GetRawResponse(), backup.Value.Value);
return Response.FromValue(backup.Value.Value, backup.GetRawResponse());
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public virtual async Task<Response<byte[]>> BackupSecretAsync(string name, Cance
{
Response<VaultBackup> backup = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new VaultBackup(), cancellationToken, SecretsPath, name, "/backup").ConfigureAwait(false);

return Response.FromValue(backup.GetRawResponse(), backup.Value.Value);
return Response.FromValue(backup.Value.Value, backup.GetRawResponse());
}
catch (Exception e)
{
Expand Down Expand Up @@ -663,7 +663,7 @@ public virtual Response<byte[]> BackupSecret(string name, CancellationToken canc
{
Response<VaultBackup> backup = _pipeline.SendRequest(RequestMethod.Post, () => new VaultBackup(), cancellationToken, SecretsPath, name, "/backup");

return Response.FromValue(backup.GetRawResponse(), backup.Value.Value);
return Response.FromValue(backup.Value.Value, backup.GetRawResponse());
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Response<T> CreateResponse<T>(Response response, T result)
where T : IJsonDeserializable
{
result.Deserialize(response.ContentStream);
return Response.FromValue(response, result);
return Response.FromValue(result, response);
}

public DiagnosticScope CreateScope(string name)
Expand Down
26 changes: 14 additions & 12 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ private async Task<Response<BlobDownloadInfo>> DownloadInternal(

// Wrap the FlattenedDownloadProperties into a BlobDownloadOperation
// to make the Content easier to find
return Response.FromValue(response.GetRawResponse(), new BlobDownloadInfo(response.Value));
return Response.FromValue(new BlobDownloadInfo(response.Value), response.GetRawResponse());
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2348,12 +2348,13 @@ await BlobRestClient.Blob.SetHttpHeadersAsync(
operationName: "Azure.Storage.Blobs.Specialized.BlobBaseClient.SetHttpHeaders",
cancellationToken: cancellationToken)
.ConfigureAwait(false);
return Response.FromValue(response.GetRawResponse(), new BlobInfo
{
LastModified = response.Value.LastModified,
ETag = response.Value.ETag,
BlobSequenceNumber = response.Value.BlobSequenceNumber
});
return Response.FromValue(
new BlobInfo
{
LastModified = response.Value.LastModified,
ETag = response.Value.ETag,
BlobSequenceNumber = response.Value.BlobSequenceNumber
}, response.GetRawResponse());
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2503,11 +2504,12 @@ await BlobRestClient.Blob.SetMetadataAsync(
operationName: "Azure.Storage.Blobs.Specialized.BlobBaseClient.SetMetadata",
cancellationToken: cancellationToken)
.ConfigureAwait(false);
return Response.FromValue(response.GetRawResponse(), new BlobInfo
{
LastModified = response.Value.LastModified,
ETag = response.Value.ETag
});
return Response.FromValue(
new BlobInfo
{
LastModified = response.Value.LastModified,
ETag = response.Value.ETag
}, response.GetRawResponse());
}
catch (Exception ex)
{
Expand Down
31 changes: 16 additions & 15 deletions sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,22 +692,23 @@ await BlobRestClient.Container.GetPropertiesAsync(

// Turn the flattened properties into a BlobContainerItem
var uri = new BlobUriBuilder(Uri);
return Response.FromValue(response.GetRawResponse(), new BlobContainerItem(false)
{
Name = uri.BlobContainerName,
Metadata = response.Value.Metadata,
Properties = new BlobContainerProperties()
return Response.FromValue(
new BlobContainerItem(false)
{
LastModified = response.Value.LastModified,
ETag = response.Value.ETag,
LeaseStatus = response.Value.LeaseStatus,
LeaseState = response.Value.LeaseState,
LeaseDuration = response.Value.LeaseDuration,
PublicAccess = response.Value.BlobPublicAccess,
HasImmutabilityPolicy = response.Value.HasImmutabilityPolicy,
HasLegalHold = response.Value.HasLegalHold
}
});
Name = uri.BlobContainerName,
Metadata = response.Value.Metadata,
Properties = new BlobContainerProperties()
{
LastModified = response.Value.LastModified,
ETag = response.Value.ETag,
LeaseStatus = response.Value.LeaseStatus,
LeaseState = response.Value.LeaseState,
LeaseDuration = response.Value.LeaseDuration,
PublicAccess = response.Value.BlobPublicAccess,
HasImmutabilityPolicy = response.Value.HasImmutabilityPolicy,
HasLegalHold = response.Value.HasLegalHold
}
}, response.GetRawResponse());
}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ public virtual Response<BlobContainerClient> CreateBlobContainer(
{
BlobContainerClient container = GetBlobContainerClient(blobContainerName);
Response<BlobContainerInfo> response = container.Create(publicAccessType, metadata, cancellationToken);
return Response.FromValue(response.GetRawResponse(), container);
return Response.FromValue(container, response.GetRawResponse());
}

/// <summary>
Expand Down Expand Up @@ -1052,7 +1052,7 @@ public virtual async Task<Response<BlobContainerClient>> CreateBlobContainerAsyn
{
BlobContainerClient container = GetBlobContainerClient(blobContainerName);
Response<BlobContainerInfo> response = await container.CreateAsync(publicAccessType, metadata, cancellationToken).ConfigureAwait(false);
return Response.FromValue(response.GetRawResponse(), container);
return Response.FromValue(container, response.GetRawResponse());
}
#endregion CreateBlobContainer

Expand Down
Loading