Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4337

Use correct serializer for conditional result

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.18.0
    • Affects Version/s: None
    • Component/s: LINQ3
    • None
    • Fully Compatible

      The attached repro.cs was used as a basis for developing a full set of related tests. For the actual tests see the changes in master.

      The full set of tests uses the following types:

      public class C
      {
          public int Id { get; set; }
      
          public E I1 { get; set; }
          public E I2 { get; set; }
      
          [BsonRepresentation(BsonType.String)] public E S1 { get; set; }
          [BsonRepresentation(BsonType.String)] public E S2 { get; set; }
      }
      
      public enum E { E1 = 1, E2 }
      

      The key fact is that I1 and I2 are represented as integers, whereas S1 and S2 are represented as strings.

      And the following test cases were added:

      // the following cases should use the correct representation in the predicate
      d => d.I1 == E.E1 ? true : false
      d => d.S1 == E.E1 ? true : false
      d => E.E1 == d.I1 ? true : false
      d => E.E1 == d.S1 ? true : false
      
      // the following test case should use the representation from the serializer registry
      true ? E.E1 : E.E2
      
      // the following test cases should use the representation implied by the predicate for the result
      d.I1 == E.E1 ? E.E1 : E.E2
      d.S1 == E.E1 ? E.E1 : E.E2
      
      // the following test cases should use the representation implied by the ifTrue/ifFalse clauses for the result
      d.I1 == E.E1 ? d.I1 : E.E2
      d.I1 == E.E1 ? d.I1 : d.I2
      d.I1 == E.E1 ? d.S1 : E.E2
      d.I1 == E.E1 ? E.E1 : d.I2
      d.I1 == E.E1 ? E.E1 : d.S2
      d.I1 == E.E1 ? d.S1 : d.S2
      d.S1 == E.E1 ? d.I1 : E.E2
      d.S1 == E.E1 ? d.I1 : d.I2
      d.S1 == E.E1 ? d.S1 : E.E2
      d.S1 == E.E1 ? E.E1 : d.I2
      d.S1 == E.E1 ? E.E1 : d.S2
      d.S1 == E.E1 ? d.S1 : d.S2
      
      
      // the following test cases should throw because the ifTrue/ifFalse clauses have conflicting representations
      d.I1 == E.E1 ? d.I1 : d.S2
      d.I1 == E.E1 ? d.S1 : d.I2
      

       

       

       

        1. repro.cs
          0.8 kB
          Boris Dogadov

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            boris.dogadov@mongodb.com Boris Dogadov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: