[CSHARP-4337] Use correct serializer for conditional result Created: 27/Sep/22  Updated: 28/Oct/23  Resolved: 07/Oct/22

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: None
Fix Version/s: 2.18.0

Type: Bug Priority: Major - P3
Reporter: Boris Dogadov Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File repro.cs    
Issue Links:
Related
related to CSHARP-3315 LINQ3: Serializers should implement E... Backlog
Case:
Backwards Compatibility: Fully Compatible

 Description   

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

 

 

 



 Comments   
Comment by Githook User [ 07/Oct/22 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4337: Use correct serializer for conditional result.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/ca00c14f882ff88234697a23f585c95648d9c031

Generated at Wed Feb 07 21:47:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.