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

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

Closed
colinangusmackay opened this issue Dec 6, 2021 · 4 comments
Closed
Labels
Milestone

Comments

@colinangusmackay
Copy link

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.

@SimonCropp
Copy link
Member

dont worry about the PR. I think i was too eager with this change https://github.com/VerifyTests/Discussions/discussions/13

@ChristopherL-STCU i think @colinangusmackay is correct here.

@ChristopherL-STCU
Copy link

So instead of the change made in 14.8.0 I could use DefaultValueHandling.Include and it would have have produced the results I was looking for?

@SimonCropp
Copy link
Member

nd it would have have produced the results I was looking for?

i dont know. give it a try

@ChristopherL-STCU
Copy link

Indeed it does. Thanks

@SimonCropp SimonCropp added this to the 14.8.1 milestone Dec 7, 2021
@SimonCropp SimonCropp added the Bug label Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants