Repository navigation
Add comprehensive serialization unit tests for all models - #358
Merged
Merged
Conversation
Add a Models/ folder under Serializer tests following the pattern from the server-side Exceptionless repo. Each model has its own test class with three-part named tests (Arrange/Act/Assert) covering: - Event (with nested data models, tags, special characters) - EnvironmentInfo (all properties, OS name/version JsonProperty attrs) - Error (nested inner errors, stack frames, modules, target method) - InnerError (chain nesting, target method, data dictionary) - SimpleError (modules, inner hierarchy, @ext key) - SimpleInnerError (nesting, null stack trace) - RequestInfo (headers, cookies, query string, post data, known keys) - UserInfo (identity, name, data, unicode, trimming) - UserDescription (email, description, data, trimming) - ManualStackingInfo (title, signature data, constructors) - ClientConfiguration (version, settings, case-insensitive keys) - Module (dates, is_entry, data dictionary) - Method (generic arguments, parameters, signature target) - StackFrame (file path, line/column, parameters, generic args) - Parameter (type namespace, generic arguments, data) - StackFrameCollection (ordering, complete frame properties) - ModuleCollection (multiple modules, data preservation) - ParameterCollection (multiple params with generic args) - GenericArguments (empty, single, multiple, ordering) - TagSet (case insensitivity, special characters) - DataDictionary (mixed types, key casing, @ prefixes) - SettingsDictionary (known keys, boolean/int parsing) - SerializerContractAssertions helper All 155 tests pass and validate: - Snake_case property naming in JSON output - Round-trip serialize/deserialize data preservation - Correct handling of nested objects and collections - Special character escaping and Unicode support - Known data key constants Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds model-focused serialization unit tests for the Exceptionless JSON serializer, expanding coverage across client models, data models, collection types, and serializer contract assertions.
Changes:
- Adds serialization and round-trip tests for events, errors, request/user/environment data, configuration, and stacking metadata.
- Adds collection serialization tests for tags, modules, stack frames, parameters, generic arguments, settings, and data dictionaries.
- Introduces a shared helper for asserting expected JSON property naming.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
test/Exceptionless.Tests/Serializer/Models/ClientConfigurationSerializerTests.cs |
Adds serialization tests for client configuration and settings. |
test/Exceptionless.Tests/Serializer/Models/DataDictionarySerializerTests.cs |
Adds coverage for data dictionary serialization behavior. |
test/Exceptionless.Tests/Serializer/Models/EnvironmentInfoSerializerTests.cs |
Adds tests for environment info property naming and round-trip behavior. |
test/Exceptionless.Tests/Serializer/Models/ErrorSerializerTests.cs |
Adds tests for full error models, stack traces, modules, and target methods. |
test/Exceptionless.Tests/Serializer/Models/EventSerializerTests.cs |
Adds event serialization and nested known-data model tests. |
test/Exceptionless.Tests/Serializer/Models/GenericArgumentsSerializerTests.cs |
Adds array serialization tests for generic argument collections. |
test/Exceptionless.Tests/Serializer/Models/InnerErrorSerializerTests.cs |
Adds tests for nested inner errors, data, stack traces, and target methods. |
test/Exceptionless.Tests/Serializer/Models/ManualStackingInfoSerializerTests.cs |
Adds tests for manual stacking info constructors and signature data. |
test/Exceptionless.Tests/Serializer/Models/MethodSerializerTests.cs |
Adds method serialization tests for parameters, generic args, and metadata. |
test/Exceptionless.Tests/Serializer/Models/ModuleCollectionSerializerTests.cs |
Adds module collection serialization and round-trip tests. |
test/Exceptionless.Tests/Serializer/Models/ModuleSerializerTests.cs |
Adds module property, date, boolean, and data tests. |
test/Exceptionless.Tests/Serializer/Models/ParameterCollectionSerializerTests.cs |
Adds parameter collection serialization tests. |
test/Exceptionless.Tests/Serializer/Models/ParameterSerializerTests.cs |
Adds parameter property, generic argument, and data tests. |
test/Exceptionless.Tests/Serializer/Models/RequestInfoSerializerTests.cs |
Adds request info tests for headers, cookies, query string, post data, and known keys. |
test/Exceptionless.Tests/Serializer/Models/SerializerContractAssertions.cs |
Adds shared JSON contract assertion helpers. |
test/Exceptionless.Tests/Serializer/Models/SettingsDictionarySerializerTests.cs |
Adds settings dictionary serialization and typed lookup tests. |
test/Exceptionless.Tests/Serializer/Models/SimpleErrorSerializerTests.cs |
Adds simple error serialization and hierarchy tests. |
test/Exceptionless.Tests/Serializer/Models/SimpleInnerErrorSerializerTests.cs |
Adds simple inner error serialization and nesting tests. |
test/Exceptionless.Tests/Serializer/Models/StackFrameCollectionSerializerTests.cs |
Adds stack frame collection serialization tests. |
test/Exceptionless.Tests/Serializer/Models/StackFrameSerializerTests.cs |
Adds stack frame property, path, parameter, and generic argument tests. |
test/Exceptionless.Tests/Serializer/Models/TagSetSerializerTests.cs |
Adds tag set serialization and case-insensitivity tests. |
test/Exceptionless.Tests/Serializer/Models/UserDescriptionSerializerTests.cs |
Adds user description serialization and trimming tests. |
test/Exceptionless.Tests/Serializer/Models/UserInfoSerializerTests.cs |
Adds user info serialization, unicode, special character, and trimming tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Assert.NotNull(json); | ||
|
|
||
| foreach (string propertyName in propertyNames) | ||
| Assert.DoesNotContain($"\"{propertyName}\"", json); |
Comment on lines
+180
to
+185
| // Act | ||
| string json = serializer.Serialize(request); | ||
|
|
||
| // Assert | ||
| Assert.Contains("\"post_data\"", json); | ||
| Assert.Contains("\"Name\"", json); |
…json constants - Add SerializerTestBase with Serializer, Serialize(), Deserialize<T>(), RoundTrip<T>() helpers - Remove SerializerContractAssertions (partial assertions replaced with whole-string) - Rewrite all 22 model test classes to extend SerializerTestBase - All JSON strings are const with /* lang=json */ IDE hint comments - Assert.Equal(expected, actual) on full JSON strings — no more Contains() - Add DataDictionaryConverter tests: JObject→compact string, JArray→compact string - Add RequestInfoConverter test: JObject PostData→indented string - Add EnvironmentInfo o_s_name/o_s_version explicit [JsonProperty] attribute test - Add Event KnownDataKeys constants validation test - Add Theory tests for all Event.KnownTypes - Set LangVersion=11.0 in test project for raw string literals Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Bug: RequestInfoConverter only checked 'PostData is JObject' — a JSON array body (e.g. REST POST with array payload) left PostData as a raw JArray instead of converting it to a string. Any downstream code expecting PostData to be null or a string would silently receive a JArray. Fix: extend the check to cover JArray by casting to JToken before calling .ToString(), which preserves the existing indented-string formatting. Regression test: Deserialize_RequestInfoArrayPostData_ConvertsToString confirms the fix — the test fails before the fix, passes after. Also move every '/* lang=json */' comment from inline (= /* lang=json */ "...") to its own line above the const declaration per project style convention. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Complete overhaul of the serialization unit test suite. 127 tests, 0 failures.
What changed
New:
SerializerTestBaseA shared base class for all model tests providing:
Serializer—DefaultJsonSerializerinstanceSerialize()/Deserialize<T>()helpersRoundTrip<T>()helper for round-trip testsRemoved:
SerializerContractAssertionsDeleted entirely. Partial
Contains()checks replaced with exact full-JSONAssert.Equal().All 22 model test classes rewritten
Every test now:
SerializerTestBaseprivate const stringwith/* lang=json */IDE hint comments using raw string literals ("""...""")Assert.Equal(expected, actual)— never partial checksNew converter coverage
DataDictionaryConverter— two dedicated tests verify the converter behavior:Deserialize_DataDictionary_JObjectValuesBecomeCompactStrings— nested{"key":"val"}→ compact stringDeserialize_DataDictionary_JArrayValuesBecomeCompactStrings— nested["a","b"]→ compact stringRequestInfoConverter— dedicated test verifies:Deserialize_RequestInfo_JsonObjectPostData_ConvertsToIndentedString— JObject PostData →JObject.ToString()indented formatSpecial casing coverage
EnvironmentInfo.OSNameandOSVersionuse explicit[JsonProperty("o_s_name")]/[JsonProperty("o_s_version")]attributes — tests verify the exact serialized key namesError/SimpleErrorderived-class properties (modules) serialize before base-class properties — tests verify property orderEvent.KnownDataKeysconstants test verifies all@prefix key valuesAdditional coverage
Theorytest covers allEvent.KnownTypes(error, usage, log, 404, session)RequestInfo.KnownDataKeys(@browser,@os,@is_bot, etc.) tested via complete JSON assertionSettingsDictionary.KnownKeysconstants (@@DataExclusions,@@log:*) verifiedTest results