Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created tests that show the collections contains methods work #2187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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; }
}
}
}