Skip to content
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

SerializationService #16

Merged
merged 15 commits into from
Aug 30, 2024
Merged

SerializationService #16

merged 15 commits into from
Aug 30, 2024

Conversation

StefanGreve
Copy link
Member

@StefanGreve StefanGreve commented Aug 30, 2024

Subtask 1

  • Fix release build error: serialization and deserialization requires a JsonSerializerContext when trimming is enabled.
  • Add a minimal working example in the documentation

Subtask 2

  • Define ISerializationService and add doc strings
  • Implement SerializationService
  • Implement AddSerializationService
  • Publish a new version of AdvancedSystems.Core.Abstractions
  • Write unit tests for SerializationService and AddSerializationService

Subtask 3

  • Refactor CachingService and use SerializationService instead
  • Register SerializationService in AddCachingService as scoped service
  • Update unit tests (CachingServiceFixture, CachingServiceTests)

@StefanGreve StefanGreve added enhancement New feature or request feature New feature tests Work on test suite labels Aug 30, 2024
@StefanGreve StefanGreve added this to the Version 8.0.0-alpha milestone Aug 30, 2024
@StefanGreve StefanGreve self-assigned this Aug 30, 2024
@StefanGreve
Copy link
Member Author

Two things:

  1. Turns out it is not possible to mock service methods that use stack-types in their method signature (see also: https://github.com/orgs/Advanced-Systems/discussions/2)
  2. Making CachingService dependent on SerializationService may sound nice in theory, but is actually much harder to test due to the aforementioned reason, but also because I don't see a straightforward way to use Returns with Setup and a generic method signature.

For instance, this [1] doesn't work:

this.SerializationService
            .Setup(s => s.Serialize(It.IsAny<It.IsAnyType>(), It.IsAny<JsonTypeInfo<It.IsAnyType>>()))
            .Returns((object value, JsonTypeInfo<object> typeInfo) =>
            {
                return ObjectSerializer.Serialize(value, typeInfo).ToArray();
            });

Class fixture type 'AdvancedSystems.Core.Tests.Fixtures.CachingServiceFixture' threw in its constructor
---- System.ArgumentException : Invalid callback. Setup on method with parameters (byte[], JsonTypeInfo<It.IsAnyType>) cannot invoke callback with parameters (byte[], JsonTypeInfo).

[1] https://docs.educationsmediagroup.com/unit-testing-csharp/moq/generic-methods

@StefanGreve StefanGreve marked this pull request as ready for review August 30, 2024 20:47
@StefanGreve StefanGreve force-pushed the serialization_service branch from e1c36ee to 674f89d Compare August 30, 2024 20:52
@StefanGreve StefanGreve merged commit 109f994 into master Aug 30, 2024
5 checks passed
@StefanGreve StefanGreve deleted the serialization_service branch August 30, 2024 20:55
@StefanGreve StefanGreve linked an issue Aug 30, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature New feature tests Work on test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SerializationService
1 participant