Skip to content

Commit

Permalink
fixes for getting the samples to work (#570)
Browse files Browse the repository at this point in the history
* fixes for getting the samples to work

* add ut
  • Loading branch information
vinayada1 authored Jan 30, 2021
1 parent aa41915 commit 7f9d23c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions samples/Client/DaprClient/InvokeServiceGrpcExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public override async Task RunAsync(CancellationToken cancellationToken)
{
using var client = new DaprClientBuilder().Build();

Console.WriteLine("Invoking grpc balance");
var request = new GetAccountRequest() { Id = "17", };
var account = await client.InvokeMethodGrpcAsync<GetAccountRequest, Account>("grpcsample", "getaccount", request, cancellationToken);
Console.WriteLine($"Received grpc balance {account.Balance}");

Console.WriteLine("Invoking grpc deposit");
var data = new GrpcServiceSample.Generated.Transaction() { Id = "17", Amount = 99 };
account = await client.InvokeMethodGrpcAsync<Transaction, Account>("grpcsample", "deposit", data, cancellationToken);
var deposit = new GrpcServiceSample.Generated.Transaction() { Id = "17", Amount = 99 };
var account = await client.InvokeMethodGrpcAsync<GrpcServiceSample.Generated.Transaction, Account>("grpcsample", "deposit", deposit, cancellationToken);
Console.WriteLine("Returned: id:{0} | Balance:{1}", account.Id, account.Balance);
Console.WriteLine("Completed grpc deposit");

Console.WriteLine("Invoking grpc withdraw");
var withdraw = new Transaction() { Id = "17", Amount = 10, };
await client.InvokeMethodGrpcAsync("grpcsample", "withdraw", data, cancellationToken);
var withdraw = new GrpcServiceSample.Generated.Transaction() { Id = "17", Amount = 10, };
await client.InvokeMethodGrpcAsync("grpcsample", "withdraw", withdraw, cancellationToken);
Console.WriteLine("Completed grpc withdraw");

Console.WriteLine("Invoking grpc balance");
var request = new GetAccountRequest() { Id = "17", };
account = await client.InvokeMethodGrpcAsync<GetAccountRequest, Account>("grpcsample", "getaccount", request, cancellationToken);
Console.WriteLine($"Received grpc balance {account.Balance}");
}
}
}
1 change: 1 addition & 0 deletions src/Dapr.Client/DaprClientGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private async Task MakePublishRequest(
if (content != null)
{
envelope.Data = content;
envelope.DataContentType = "application/json";
}

if (metadata != null)
Expand Down
2 changes: 2 additions & 0 deletions test/Dapr.Client.Test/PublishEventApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public async Task PublishEventAsync_CanPublishTopicWithData()
var request = await GrpcUtils.GetRequestFromRequestMessageAsync<PublishEventRequest>(entry.Request);
var jsonFromRequest = request.Data.ToStringUtf8();

request.DataContentType.Should().Be("application/json");
request.PubsubName.Should().Be(TestPubsubName);
request.Topic.Should().Be("test");
jsonFromRequest.Should().Be(JsonSerializer.Serialize(publishData, daprClient.JsonSerializerOptions));
Expand Down Expand Up @@ -63,6 +64,7 @@ public async Task PublishEventAsync_CanPublishTopicWithData_WithMetadata()
var request = await GrpcUtils.GetRequestFromRequestMessageAsync<PublishEventRequest>(entry.Request);
var jsonFromRequest = request.Data.ToStringUtf8();

request.DataContentType.Should().Be("application/json");
request.PubsubName.Should().Be(TestPubsubName);
request.Topic.Should().Be("test");
jsonFromRequest.Should().Be(JsonSerializer.Serialize(publishData, daprClient.JsonSerializerOptions));
Expand Down

0 comments on commit 7f9d23c

Please sign in to comment.