Skip to content

Commit

Permalink
Merge pull request #2187 from visschersm/bug/#652-IEnumerableContains
Browse files Browse the repository at this point in the history
Created tests that show the collections contains methods work
  • Loading branch information
JKamsker authored Jun 4, 2024
2 parents bfc0375 + bc8a0e5 commit 78cd8bb
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions LiteDB.Tests/Database/Contains_Tests.cs
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; }
}
}
}

0 comments on commit 78cd8bb

Please sign in to comment.