Skip to content

Boolean properties with false or null are missing from the output. #447

@colinangusmackay

Description

@colinangusmackay

Preamble

  • Visual Studio 2019
  • .NET 5.0
  • Verify.Xunit 14.8.0

Describe the bug

On upgrading to Verify.Xunit 14.8.0 (from 14.7.0) some tests started failing. On closer examination it looks like Boolean values are being handled slightly differently and are now missing from some output. false values are missing, and if it is a nullable Boolean then null values are missing too. This means that there isn't any effective difference between null or false in the output for a nullable Boolean property.

The following has no effect either:

verifySettings.ModifySerialization(settings =>
{
  settings.AddExtraSettings(serializerSettings =>
    serializerSettings.DefaultValueHandling = DefaultValueHandling.Include);
});

Minimal Repro

using System.Threading.Tasks;
using DiffEngine;
using Newtonsoft.Json;
using VerifyTests;
using VerifyXunit;
using Xunit;

namespace VerifyCheck
{
    [UsesVerify]
    public class VerifyBooleanChecks
    {
        public class Properties
        {
            public bool Boolean { get; init; }

            public bool? NullableBoolean { get; init; }
        }

        public VerifyBooleanChecks()
        {
            DiffTools.UseOrder(DiffTool.VisualStudioCode);
        }

        [Theory]
        [InlineData(false, null)]
        [InlineData(false, false)]
        [InlineData(false, true)]
        [InlineData(true, true)]
        [InlineData(true, null)]
        [InlineData(true, false)]
        public async Task OutputOfPropertiesAsync(bool boolean, bool? nullableBoolean)
        {
            var check = new Properties
            {
                Boolean = boolean,
                NullableBoolean = nullableBoolean,
            };

            var verifySettings = new VerifySettings();
            verifySettings.UseParameters(boolean, nullableBoolean);
            await Verifier.Verify(check, verifySettings);
        }
    }
}

Only true is ever output. For example, when Boolean is false, NullableBoolean is null the output is:

{}

For Boolean is true, NullableBoolean is null:

{
  "Boolean": true
}

Submit a PR that fixes the bug

I do not have a PR to fix this issue at present. I will try and create one within the next 48 hours. If it is obvious where the issue may lie, please point me in that direction or let me know if you are fixing it instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions