#region ========================================================================= USING ===================================================================================== using FluentAssertions; using Lumina.Application.Common.Converters; using Lumina.Application.UnitTests.Common.Converters.Fixtures; using Lumina.Domain.Common.Primitives; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; #endregion namespace Lumina.Application.UnitTests.Common.Converters; /// /// Contains unit tests for the class. /// [ExcludeFromCodeCoverage] public class OptionalJsonConverterFactoryTests { private readonly OptionalJsonConverterFactory _factory; /// /// Initializes a new instance of the class. /// public OptionalJsonConverterFactoryTests() { _factory = new OptionalJsonConverterFactory(); } [Fact] public void CanConvert_WhenTypeIsOptional_ShouldReturnTrue() { // Arrange Type typeToConvert = typeof(Optional); // Act bool result = _factory.CanConvert(typeToConvert); // Assert result.Should().BeTrue(); } [Fact] public void CanConvert_WhenTypeIsNotOptional_ShouldReturnFalse() { // Arrange Type typeToConvert = typeof(string); // Act bool result = _factory.CanConvert(typeToConvert); // Assert result.Should().BeFalse(); } [Fact] public void CanConvert_WhenTypeIsGenericButNotOptional_ShouldReturnFalse() { // Arrange Type typeToConvert = typeof(List); // Act bool result = _factory.CanConvert(typeToConvert); // Assert result.Should().BeFalse(); } [Fact] public void CreateConverter_WhenTypeIsOptionalString_ShouldReturnCorrectConverterType() { // Arrange Type typeToConvert = typeof(Optional); JsonSerializerOptions options = new(); // Act JsonConverter converter = _factory.CreateConverter(typeToConvert, options); // Assert converter.Should().BeOfType>(); } [Fact] public void CreateConverter_WhenTypeIsOptionalInt_ShouldReturnCorrectConverterType() { // Arrange Type typeToConvert = typeof(Optional); JsonSerializerOptions options = new(); // Act JsonConverter converter = _factory.CreateConverter(typeToConvert, options); // Assert converter.Should().BeOfType>(); } [Fact] public void CreateConverter_WhenTypeIsOptionalCustomClass_ShouldReturnCorrectConverterType() { // Arrange Type typeToConvert = typeof(Optional); JsonSerializerOptions options = new(); // Act JsonConverter converter = _factory.CreateConverter(typeToConvert, options); // Assert converter.Should().BeOfType>(); } }