-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Created tests that show the collections contains methods work
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 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,96 @@ | ||
using LiteDB; | ||
using FluentAssertions; | ||
using Xunit; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System; | ||
|
||
namespace LiteDB.Tests.Database | ||
{ | ||
public class Contains_Tests | ||
{ | ||
[Fact] | ||
public void ArrayContains_ShouldHaveCount1() | ||
{ | ||
var random = new Random(); | ||
var randomValue = random.Next(); | ||
|
||
using(var database = new LiteDatabase(new MemoryStream())) | ||
{ | ||
var collection = database.GetCollection<ItemWithEnumerable>(); | ||
collection.Insert(new ItemWithEnumerable | ||
{ | ||
Array = new int[] { randomValue } | ||
}); | ||
|
||
var result = collection.Find(i => i.Array.Contains(randomValue)).ToList(); | ||
result.Should().HaveCount(1); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void EnumerableAssignedArrayContains_ShouldHaveCount1() | ||
{ | ||
var random = new Random(); | ||
var randomValue = random.Next(); | ||
|
||
using(var database = new LiteDatabase(new MemoryStream())) | ||
{ | ||
var collection = database.GetCollection<ItemWithEnumerable>(); | ||
collection.Insert(new ItemWithEnumerable | ||
{ | ||
Enumerable = new int[] { randomValue } | ||
}); | ||
|
||
var result = collection.Find(i => i.Enumerable.Contains(randomValue)).ToList(); | ||
result.Should().HaveCount(1); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void EnumerableAssignedListContains_ShouldHaveCount1() | ||
{ | ||
var random = new Random(); | ||
var randomValue = random.Next(); | ||
|
||
using(var database = new LiteDatabase(new MemoryStream())) | ||
{ | ||
var collection = database.GetCollection<ItemWithEnumerable>(); | ||
collection.Insert(new ItemWithEnumerable | ||
{ | ||
Enumerable = new List<int> { randomValue } | ||
}); | ||
|
||
var result = collection.Find(i => i.Enumerable.Contains(randomValue)).ToList(); | ||
result.Should().HaveCount(1); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ListContains_ShouldHaveCount1() | ||
{ | ||
var random = new Random(); | ||
var randomValue = random.Next(); | ||
|
||
using(var database = new LiteDatabase(new MemoryStream())) | ||
{ | ||
var collection = database.GetCollection<ItemWithEnumerable>(); | ||
collection.Insert(new ItemWithEnumerable | ||
{ | ||
List = new List<int> { randomValue } | ||
}); | ||
|
||
var result = collection.Find(i => i.List.Contains(randomValue)).ToList(); | ||
result.Should().HaveCount(1); | ||
} | ||
} | ||
|
||
public class ItemWithEnumerable | ||
{ | ||
public int[] Array { get; set; } | ||
public IEnumerable<int> Enumerable { get; set; } | ||
public IList<int> List { get; set; } | ||
} | ||
} | ||
} |