Skip to content

Commit

Permalink
Regenerate Google.Cloud.AutoML.V1 (#3584)
Browse files Browse the repository at this point in the history
Modifies long-running operations to give them response/metadata types
  • Loading branch information
yoshi-automation authored and jskeet committed Oct 8, 2019
1 parent ac8db54 commit fb2b456
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 132 deletions.
Expand Up @@ -45,7 +45,26 @@ public async Task CreateDatasetAsync()
LocationName parent = new LocationName("[PROJECT]", "[LOCATION]");
Dataset dataset = new Dataset();
// Make the request
Operation response = await autoMlClient.CreateDatasetAsync(parent, dataset);
Operation<Dataset, OperationMetadata> response =
await autoMlClient.CreateDatasetAsync(parent, dataset);

// Poll until the returned long-running operation is complete
Operation<Dataset, OperationMetadata> completedResponse =
await response.PollUntilCompletedAsync();
// Retrieve the operation result
Dataset result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Dataset, OperationMetadata> retrievedResponse =
await autoMlClient.PollOnceCreateDatasetAsync(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Dataset retrievedResult = retrievedResponse.Result;
}
// End snippet
}

Expand All @@ -59,15 +78,33 @@ public void CreateDataset()
LocationName parent = new LocationName("[PROJECT]", "[LOCATION]");
Dataset dataset = new Dataset();
// Make the request
Operation response = autoMlClient.CreateDataset(parent, dataset);
Operation<Dataset, OperationMetadata> response =
autoMlClient.CreateDataset(parent, dataset);

// Poll until the returned long-running operation is complete
Operation<Dataset, OperationMetadata> completedResponse =
response.PollUntilCompleted();
// Retrieve the operation result
Dataset result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Dataset, OperationMetadata> retrievedResponse =
autoMlClient.PollOnceCreateDataset(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Dataset retrievedResult = retrievedResponse.Result;
}
// End snippet
}

/// <summary>Snippet for CreateDatasetAsync</summary>
public async Task CreateDatasetAsync_RequestObject()
{
// Snippet: CreateDatasetAsync(CreateDatasetRequest,CallSettings)
// Additional: CreateDatasetAsync(CreateDatasetRequest,CancellationToken)
// Create client
AutoMlClient autoMlClient = await AutoMlClient.CreateAsync();
// Initialize request argument(s)
Expand All @@ -77,7 +114,26 @@ public async Task CreateDatasetAsync_RequestObject()
Dataset = new Dataset(),
};
// Make the request
Operation response = await autoMlClient.CreateDatasetAsync(request);
Operation<Dataset, OperationMetadata> response =
await autoMlClient.CreateDatasetAsync(request);

// Poll until the returned long-running operation is complete
Operation<Dataset, OperationMetadata> completedResponse =
await response.PollUntilCompletedAsync();
// Retrieve the operation result
Dataset result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Dataset, OperationMetadata> retrievedResponse =
await autoMlClient.PollOnceCreateDatasetAsync(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Dataset retrievedResult = retrievedResponse.Result;
}
// End snippet
}

Expand All @@ -94,7 +150,26 @@ public void CreateDataset_RequestObject()
Dataset = new Dataset(),
};
// Make the request
Operation response = autoMlClient.CreateDataset(request);
Operation<Dataset, OperationMetadata> response =
autoMlClient.CreateDataset(request);

// Poll until the returned long-running operation is complete
Operation<Dataset, OperationMetadata> completedResponse =
response.PollUntilCompleted();
// Retrieve the operation result
Dataset result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Dataset, OperationMetadata> retrievedResponse =
autoMlClient.PollOnceCreateDataset(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Dataset retrievedResult = retrievedResponse.Result;
}
// End snippet
}

Expand Down
Expand Up @@ -34,106 +34,6 @@ namespace Google.Cloud.AutoML.V1.Tests
/// <summary>Generated unit tests</summary>
public class GeneratedAutoMlClientTest
{
[Fact]
public void CreateDataset()
{
Mock<AutoMl.AutoMlClient> mockGrpcClient = new Mock<AutoMl.AutoMlClient>(MockBehavior.Strict);
mockGrpcClient.Setup(x => x.CreateOperationsClient())
.Returns(new Mock<Operations.OperationsClient>().Object);
CreateDatasetRequest expectedRequest = new CreateDatasetRequest
{
ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"),
Dataset = new Dataset(),
};
Operation expectedResponse = new Operation
{
Name = "name3373707",
Done = true,
};
mockGrpcClient.Setup(x => x.CreateDataset(expectedRequest, It.IsAny<CallOptions>()))
.Returns(expectedResponse);
AutoMlClient client = new AutoMlClientImpl(mockGrpcClient.Object, null);
LocationName parent = new LocationName("[PROJECT]", "[LOCATION]");
Dataset dataset = new Dataset();
Operation response = client.CreateDataset(parent, dataset);
Assert.Same(expectedResponse, response);
mockGrpcClient.VerifyAll();
}

[Fact]
public async Task CreateDatasetAsync()
{
Mock<AutoMl.AutoMlClient> mockGrpcClient = new Mock<AutoMl.AutoMlClient>(MockBehavior.Strict);
mockGrpcClient.Setup(x => x.CreateOperationsClient())
.Returns(new Mock<Operations.OperationsClient>().Object);
CreateDatasetRequest expectedRequest = new CreateDatasetRequest
{
ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"),
Dataset = new Dataset(),
};
Operation expectedResponse = new Operation
{
Name = "name3373707",
Done = true,
};
mockGrpcClient.Setup(x => x.CreateDatasetAsync(expectedRequest, It.IsAny<CallOptions>()))
.Returns(new Grpc.Core.AsyncUnaryCall<Operation>(Task.FromResult(expectedResponse), null, null, null, null));
AutoMlClient client = new AutoMlClientImpl(mockGrpcClient.Object, null);
LocationName parent = new LocationName("[PROJECT]", "[LOCATION]");
Dataset dataset = new Dataset();
Operation response = await client.CreateDatasetAsync(parent, dataset);
Assert.Same(expectedResponse, response);
mockGrpcClient.VerifyAll();
}

[Fact]
public void CreateDataset2()
{
Mock<AutoMl.AutoMlClient> mockGrpcClient = new Mock<AutoMl.AutoMlClient>(MockBehavior.Strict);
mockGrpcClient.Setup(x => x.CreateOperationsClient())
.Returns(new Mock<Operations.OperationsClient>().Object);
CreateDatasetRequest request = new CreateDatasetRequest
{
ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"),
Dataset = new Dataset(),
};
Operation expectedResponse = new Operation
{
Name = "name3373707",
Done = true,
};
mockGrpcClient.Setup(x => x.CreateDataset(request, It.IsAny<CallOptions>()))
.Returns(expectedResponse);
AutoMlClient client = new AutoMlClientImpl(mockGrpcClient.Object, null);
Operation response = client.CreateDataset(request);
Assert.Same(expectedResponse, response);
mockGrpcClient.VerifyAll();
}

[Fact]
public async Task CreateDatasetAsync2()
{
Mock<AutoMl.AutoMlClient> mockGrpcClient = new Mock<AutoMl.AutoMlClient>(MockBehavior.Strict);
mockGrpcClient.Setup(x => x.CreateOperationsClient())
.Returns(new Mock<Operations.OperationsClient>().Object);
CreateDatasetRequest request = new CreateDatasetRequest
{
ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"),
Dataset = new Dataset(),
};
Operation expectedResponse = new Operation
{
Name = "name3373707",
Done = true,
};
mockGrpcClient.Setup(x => x.CreateDatasetAsync(request, It.IsAny<CallOptions>()))
.Returns(new Grpc.Core.AsyncUnaryCall<Operation>(Task.FromResult(expectedResponse), null, null, null, null));
AutoMlClient client = new AutoMlClientImpl(mockGrpcClient.Object, null);
Operation response = await client.CreateDatasetAsync(request);
Assert.Same(expectedResponse, response);
mockGrpcClient.VerifyAll();
}

[Fact]
public void UpdateDataset()
{
Expand Down

0 comments on commit fb2b456

Please sign in to comment.