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.
add support for Contains in IEnumerable litedb-org#652
- Loading branch information
Rytis Ilciukas
committed
Jul 18, 2017
1 parent
34e8a79
commit 74222c8
Showing
3 changed files
with
67 additions
and
2 deletions.
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,58 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace LiteDB.Tests.Database | ||
{ | ||
[TestClass] | ||
public class LinqContainsTests | ||
{ | ||
private TempFile _tempFile; | ||
private LiteDatabase _database; | ||
private LiteCollection<ItemWithEnumerable> _collection; | ||
|
||
public class ItemWithEnumerable | ||
{ | ||
public int[] Array { get; set; } | ||
|
||
public IEnumerable<int> Enumerable { get; set; } | ||
} | ||
|
||
[TestInitialize] | ||
public void Init() | ||
{ | ||
_tempFile = new TempFile(); | ||
_database = new LiteDatabase(_tempFile.Filename); | ||
_collection = _database.GetCollection<ItemWithEnumerable>("items"); | ||
|
||
var item = new ItemWithEnumerable() | ||
{ | ||
Array = new int[] { 1 }, | ||
Enumerable = new List<int>() { 2 }, | ||
}; | ||
|
||
_collection.Insert(item); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
_database.Dispose(); | ||
_tempFile.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public void ArrayContains() | ||
{ | ||
var result = _collection.Find(i => i.Array.Contains(1)).ToList(); | ||
Assert.AreEqual(1, result.Count); | ||
} | ||
|
||
[TestMethod] | ||
public void ListContains() | ||
{ | ||
var result = _collection.Find(i => i.Enumerable.Contains(2)).ToList(); | ||
Assert.AreEqual(1, result.Count); | ||
} | ||
} | ||
} |
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
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