Skip to content

Add comprehensive serialization unit tests for all models - #358

Merged
niemyjski merged 3 commits into
mainfrom
niemyjski/serialization-test-coverage
May 31, 2026
Merged

niemyjski merged 3 commits into
mainfrom
niemyjski/serialization-test-coverage

Conversation

@niemyjski

@niemyjski niemyjski commented May 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Complete overhaul of the serialization unit test suite. 127 tests, 0 failures.

What changed

New: SerializerTestBase

A shared base class for all model tests providing:

  • Serializer — DefaultJsonSerializer instance
  • Serialize() / Deserialize<T>() helpers
  • RoundTrip<T>() helper for round-trip tests

Removed: SerializerContractAssertions

Deleted entirely. Partial Contains() checks replaced with exact full-JSON Assert.Equal().

All 22 model test classes rewritten

Every test now:

  • Extends SerializerTestBase
  • Stores JSON fixtures as private const string with /* lang=json */ IDE hint comments using raw string literals ("""...""")
  • Asserts the complete JSON string — Assert.Equal(expected, actual) — never partial checks
  • Follows Arrange / Act / Assert structure with three-part test names

New converter coverage

DataDictionaryConverter — two dedicated tests verify the converter behavior:

  • Deserialize_DataDictionary_JObjectValuesBecomeCompactStrings — nested {"key":"val"} → compact string
  • Deserialize_DataDictionary_JArrayValuesBecomeCompactStrings — nested ["a","b"] → compact string

RequestInfoConverter — dedicated test verifies:

  • Deserialize_RequestInfo_JsonObjectPostData_ConvertsToIndentedString — JObject PostData → JObject.ToString() indented format

Special casing coverage

  • EnvironmentInfo.OSName and OSVersion use explicit [JsonProperty("o_s_name")] / [JsonProperty("o_s_version")] attributes — tests verify the exact serialized key names
  • Error/SimpleError derived-class properties (modules) serialize before base-class properties — tests verify property order
  • Event.KnownDataKeys constants test verifies all @ prefix key values

Additional coverage

  • Theory test covers all Event.KnownTypes (error, usage, log, 404, session)
  • All RequestInfo.KnownDataKeys (@browser, @os, @is_bot, etc.) tested via complete JSON assertion
  • SettingsDictionary.KnownKeys constants (@@DataExclusions, @@log:*) verified

Test results

Passed: 127, Failed: 0, Skipped: 11 (JsonStorageSerializerTests – separate concern)

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>
Copilot AI review requested due to automatic review settings May 31, 2026 01:56
@niemyjski niemyjski self-assigned this May 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
niemyjski and others added 2 commits May 30, 2026 21:18
…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>
@CLAassistant

CLAassistant commented May 31, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@niemyjski
niemyjski merged commit 2b9a0c5 into main May 31, 2026
7 of 8 checks passed
@niemyjski
niemyjski deleted the niemyjski/serialization-test-coverage branch May 31, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

⌂ 换网址