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

Strange little null bug for Nullable enum types in complex types. #66

Open
KnightSwordAG opened this issue Aug 26, 2020 · 0 comments
Open

Comments

@KnightSwordAG
Copy link

So I have an object like this:

public class CptExtension
    {
        public int Id { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }
        public bool Active { get; set; }
        public DateTime EffectiveDate { get; set; }
        public DateTime? RetireDate { get; set; }
        public CodeClassification? CodeClassification { get; set; }
        public IList<EdsModifier> DisallowedModifiers { get; set; } = new List<EdsModifier>();
        public Subcategory? SubCategory { get; set; }
        public ContrastSetting? ContrastSetting { get; set; }
        public BusinessUsage? BusinessUsage { get; set; }
        public FamilyIndicator? FamilyIndicator { get; set; }
        public MultiProcCode? MultiProcCode { get; set; }
    }

I have setup my mapping with this:

        public void SetupDapperCalls(int? id = null, string code = null, object model = null)
        {
            if (id.HasValue)
            {
                DbConnection.SetupDapperAsync(c => c.QueryAsync<CptExtension>(It.IsAny<string>(), null, null, null, CommandType.StoredProcedure))
                    .ReturnsAsync(CptExtensions.Where(x => x.Id == id.Value));
                return;
            }

            if (!string.IsNullOrWhiteSpace(code))
            {
                DbConnection.SetupDapperAsync(c =>
                        c.QueryAsync<CptExtension>(It.IsAny<string>(), null, null, null, CommandType.StoredProcedure))
                    .ReturnsAsync(CptExtensions.Where(x => x.Code.Equals(code, StringComparison.OrdinalIgnoreCase)));
                return;
            }

            if (model != null)
            {
                return;
            }

            DbConnection.SetupDapperAsync(c =>
                    c.QueryAsync<CptExtension>(It.IsAny<string>(), null, null, null, CommandType.StoredProcedure))
                .ReturnsAsync(CptExtensions);
        }

When the test call is made, the nullable enum types all return null. So my subsequent query integrity checks all fail, since the data is corrupted in transit. Now I know this is the fault of the mapping, but it shouldn't be there at all, my expected values should be unaltered as a result of the mock mapping. So, any ideas?

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

No branches or pull requests

1 participant