Power-Fx icon indicating copy to clipboard operation
Power-Fx copied to clipboard

Cannot use JSON function on own record types

Open Robulane opened this issue 2 years ago • 0 comments

The following unit test fails but it should not.

    public class LazyRecordType : RecordType
    {
        public LazyRecordType()
        {
        }

        public override IEnumerable<string> FieldNames => new string[1] { "SubProperty" };

        public override bool TryGetFieldType(string name, out FormulaType type)
        {
            var subrecord = RecordType.Empty();
            subrecord = subrecord.Add("x", FormulaType.String);

            type = subrecord;
            return true;
        }

        public override bool Equals(object other)
        {
            return true;
        }

        public override int GetHashCode()
        {
            return 1;
        }
    }

    [Fact]
    public void Json_IncludeBinaryData_AllowSideEffects()
    {
        var config = new PowerFxConfig();
        config.EnableJsonFunctions();

        var engine = new RecalcEngine(config);

        var record = RecordType.Empty();
        record = record.Add("Property", new LazyRecordType());

        var formulaParams = RecordType.Empty();
        formulaParams = formulaParams.Add("Var", record);

        var result = engine.Check(
            "JSON(Var)",
            formulaParams);

        Assert.True(result.IsSuccess);
    }

Robulane avatar Feb 06 '24 16:02 Robulane