-
-
Notifications
You must be signed in to change notification settings - Fork 163
DateTimes Formatting / Serializing Issue #1441
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
Comments
where do the docs say ISO 8601? |
I've been looking deep into the docs trying to understand the datetime serialization and I think I assumed it was all from Verify. It appears that the exact statement I was thinking of is from Argon. Argon is referenced often in spots like And the Argon docs say that it uses ISO-8601 So by inference I figured it would be the same, but I guess that was my mistake. Either way I've figured out the TreatAsString method and got that working to format the datetimes in ISO-8601 :) Here's the code I got working if anyone faces the same issue as me in the future
|
Wait I take it back it isn't resolved, the TreatAsString works fine when I pass it just a DateTime but when I have an object which contains a datetime it doesnt work. Setup
Expected Output
Actual Output
|
does this explain it https://github.com/VerifyTests/Verify/blob/main/docs/type-to-string-mapping.md ? |
Verify has custom serialization for dates |
out of curiosity why do u not want to scrub those datetimes? dont they change every time the test runs if they are consistent, perhaps the Named Date and Times feature would make more sense https://github.com/VerifyTests/Verify/blob/main/docs/dates.md#named-date-and-times |
I see so TreatAsString only works for when you directly pass a datetime in, it doesnt work for properties. So is there no way to set the ISO format for the output? The reason I'd like to do this is so that we can take the outputs of some tests and use it to test/debug other parts of our system. Currently we have to manually fixup the dates to valid json before they can be used. I have Explicit tests which are only run to retrieve the output, we scrub the datetimes for our standard tests. |
can u share the full code of one of your explicit tests? |
bump |
Apologies, been away over the Easter weekend. Here is a sample, nothing too fancy. /// <summary>
/// This test will generate a working canonical that can be used for testing the target-side system. The date formats will need to be slightly modified to work.
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
[Theory(DisplayName = "", Explicit = true)]
//[MemberData(nameof(ValidPayloads))]
[InlineData(TestInputs.CompGradeChange)]
public async Task CreateWorkingCanonical(string source)
{
// Arrange
EnvelopeCanonical? actualSentMessage = null;
// Custom class
Mock<IMessageManager> messageManagerMock = new();
messageManagerMock.Setup(
x => x.SendToTopic(It.IsAny<EnvelopeCanonical>())
.Callback<EnvelopeCanonical>(
message => actualSentMessage = message);
var inputRequest = TestDataFactory.CreateHttpRequest(TestInputs.ReadFile(source));
// Act
await payrollFunction.Run(inputRequest);
// Assert
await Verify(actualSentMessage)
.UseFileName($"{Path.GetFileNameWithoutExtension(source)}_Canonical")
.DontScrubDateTimes()
.DontScrubGuids()
.UseStrictJson();
} |
IMO you should use this approach
|
Thanks very much that seems to meet my requirements. Appreciate your help and you shining some light in this area :) |
glad u found a way forward |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
When datetimes are serialized, they are using the below format which is not ISO 8601 as the docs say.
Output:
Verify Settings:
Version:
Minimum Repro:
Input
Expected Output:
2025-04-17T00:41:27.7349436Z
Actual Output
2025-04-17 00:41:27.7349436 Utc
I dont think I'm doing anything outside of the defaults so should be trivial to replicate. If I'm missing something please let me know.
Thanks!
The text was updated successfully, but these errors were encountered: