-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
how to set datetime for grpc field #1228
Comments
I think that there is an issue with the Timestamp field, I need to investigate. |
can you please try preview version 1.6.11-ci-19550 ? |
sure i will test and reply here |
but WireMock.Net 1.6.11-ci-19550 was not found. An approximate best match of WireMock.Net 1.6.11 was resolved. |
See this page for info on how to use preview packages: |
hey @StefH it did not work. |
Can you share the proto file? |
sure, here u go syntax = "proto3";
import "google/protobuf/timestamp.proto";
package Policy2;
service PolicyService2 {
rpc GetVersion (GetVersionRequest) returns (GetVersionResponse);
rpc GetVersion2 (GetVersion2Request) returns (GetVersion2Response);
}
// REQUEST/RESPONSE DEFINITIONS
message GetVersion2Request {
Client Client = 1;
}
message GetVersion2Response {
string Version = 1;
}
message GetVersionRequest {
Client Client = 1;
}
message GetVersionResponse {
string Version = 1;
google.protobuf.Timestamp DateHired = 2;
}
message Client {
string CorrelationId = 1;
enum Clients {
Unknown = 0;
QMS = 1;
BillingCenter = 2;
PAS = 3;
Payroll = 4;
Portal = 5;
SFO = 6;
QuoteAndBind = 7;
LegacyConversion = 8;
BindNow = 9;
PaymentPortal = 10 ;
PricingEngine = 11;
}
Clients ClientName = 2;
} code: This below works: var res = JsonConvert.DeserializeObject(
"{ \"Version\" : \"DevTr1\", \"DateHired\" : \"2022-09-13T00:00:00Z\" }"
); This below is not working: Policy2.GetVersionResponse res1 = new() { Version = "DevTr1", DateHired = Timestamp.FromDateTime(DateTime.UtcNow) }; |
Can you try this preview? |
@StefH datetime issue is fixed in this preview but the namespace is still not working. here is the namespace line i added in my proto using NarrowIntegrationTest.Lookup;
|
@GomesNayagam syntax = "proto3";
option csharp_namespace = "NarrowIntegrationTest.Lookup";
import "google/protobuf/timestamp.proto";
package Policy;
service PolicyService {
rpc GetVersion (GetVersionRequest) returns (GetVersionResponse);
}
message GetVersionRequest {
Client Client = 1;
}
message GetVersionResponse {
string Version = 1;
google.protobuf.Timestamp DateHired = 2;
Client Client = 3;
}
message Client {
string CorrelationId = 1;
enum Clients {
Unknown = 0;
QMS = 1;
BillingCenter = 2;
PAS = 3;
Payroll = 4;
Portal = 5;
SFO = 6;
QuoteAndBind = 7;
LegacyConversion = 8;
BindNow = 9;
PaymentPortal = 10 ;
PricingEngine = 11;
}
Clients ClientName = 2;
} and this c# test code: [Fact]
public async Task WireMockServer_WithBodyAsProtoBuf_Enum_UsingPolicyGrpcGeneratedClient()
{
// Arrange
const int seconds = 1722301323;
const int nanos = 12300;
const string version = "test";
const string correlationId = "correlation";
var definition = await System.IO.File.ReadAllTextAsync("./Grpc/policy.proto");
using var server = WireMockServer.Start(useHttp2: true);
server
.Given(Request.Create()
.UsingPost()
.WithPath("/Policy.PolicyService/GetVersion")
.WithBody(new NotNullOrEmptyMatcher())
)
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/grpc")
.WithTrailingHeader("grpc-status", "0")
.WithBodyAsProtoBuf(definition, "NarrowIntegrationTest.Lookup.GetVersionResponse",
new GetVersionResponse
{
Version = version,
DateHired = new Timestamp
{
Seconds = seconds,
Nanos = nanos
},
Client = new NarrowIntegrationTest.Lookup.Client
{
ClientName = NarrowIntegrationTest.Lookup.Client.Types.Clients.BillingCenter,
CorrelationId = correlationId
}
}
)
);
// Act
var channel = GrpcChannel.ForAddress(server.Url!);
var client = new PolicyService.PolicyServiceClient(channel);
var reply = await client.GetVersionAsync(new GetVersionRequest());
// Assert
reply.Version.Should().Be(version);
reply.DateHired.Should().Be(new Timestamp { Seconds = seconds, Nanos = nanos });
reply.Client.ClientName.Should().Be(NarrowIntegrationTest.Lookup.Client.Types.Clients.BillingCenter);
reply.Client.CorrelationId.Should().Be(correlationId);
} And it works fine. |
@StefH apologies, type in my code forgot to update the namespace in this line |
which version the fix available to use? @StefH |
Today I'll release an official new version on NuGet. |
This throws "Bad Response"
The text was updated successfully, but these errors were encountered: