-
-
Notifications
You must be signed in to change notification settings - Fork 213
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 force a formatted DateTime to return a string? #1028
Comments
@felipetofoli I think the only solution for you would be not to use Like: "{\n \"timestamp\": \"{{ DateTime.UtcNow \\\"yyMMddhhmmss\\\" }}\",\n \"timestamp2\": \"{{ DynamicLinq.Expression 'DateTime.UtcNow.ToString(\\\"yyMMddhhmmss\\\")' }}\",\n \"timestamp3\": \"{{ String.Format (DateTime.UtcNow) \\\"yyMMddhhmmss\\\" }}\",\n}" |
@felipetofoli is this ok for you? |
Hi @StefH ! Yes, the I am thinking about using C# mappings instead (to avoid the inline configurations). According to the other issues, the Or should I use |
I'm not 100% sure anymore if that enim option works as intended So for now use c# mappings or a body as string. |
@StefH, I've just tested the c# mappings, but they are returning a number either - instead of a string: server
.Given(Request
.Create()
.WithPath(new ExactMatcher("/datetime-test"))
.UsingPost())
.RespondWith(Response
.Create()
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new
{
timestamp = "{{ DateTime.UtcNow \"yyMMddhhmmss\" }}",
})
.WithTransformer()); Response: {"timestamp":231207053817} Is there any other configuration to do? Thanks, |
Sorry. In that case : use a string instead of json. I need to think in how to change the internal logic. |
First of all, thanks for this amazing lib! :)
I have to apply a specific format (
"yyMMddhhmmss"
) to a DateTime and receive a string as the result. I tried multiple approaches, but I always receive an integer, instead of a string.So my question is: How to force a formatted DateTime to return a string?
Example:
The above JSON configuration returns the following result:
The expected/desired result:
I already tried wrapping the configuration with double quotes, using
String.Append
to append an empty string (""
), but I wasn't able to get the expected/desired result.Please let me know if any other information is needed!
Thanks!
The text was updated successfully, but these errors were encountered: