forked from litedb-org/LiteDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/mbdavid/LiteDB
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
using System.Linq; | ||
|
||
namespace LiteDB.Tests.Issues | ||
{ | ||
public class Issue2112_Tests | ||
{ | ||
private BsonMapper _mapper = new BsonMapper(); | ||
|
||
[Fact] | ||
public void Serialize_covariant_collection_has_type() | ||
{ | ||
IA a = new A { Bs = new List<B> { new B() } }; | ||
|
||
var docA = _mapper.Serialize<IA>(a).AsDocument; | ||
var docB = docA["Bs"].AsArray[0].AsDocument; | ||
|
||
Assert.True(docA.ContainsKey("_type")); | ||
Assert.True(docB.ContainsKey("_type")); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_covariant_collection_succeed() | ||
{ | ||
IA a = new A { Bs = new List<B> { new B() } }; | ||
var serialized = _mapper.Serialize<IA>(a); | ||
|
||
var deserialized = _mapper.Deserialize<IA>(serialized); | ||
|
||
Assert.Equal(1, deserialized.Bs.Count); | ||
} | ||
|
||
interface IA | ||
{ | ||
// at runtime this will be a List<B> | ||
IReadOnlyCollection<IB> Bs { get; set; } | ||
} | ||
|
||
class A : IA | ||
{ | ||
public IReadOnlyCollection<IB> Bs { get; set; } | ||
} | ||
|
||
interface IB | ||
{ | ||
|
||
} | ||
|
||
class B : IB | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters