Files
dotnet-runtime/src/libraries/System.Linq.Queryable/tests/IntersectTests.cs
T
Daniel Harvey 252cdc5e95 Bulk updates of tests for AssertExtensions (dotnet/corefx#18491)
Bulk update to AssertExtensions.Throws for AOT support. This doesn't disable Assert.Throws.

Commit migrated from https://github.com/dotnet/corefx/commit/b43b4df2e0e2182154bb0f425cb4a61bc1269828
2017-04-18 09:52:02 -07:00

89 lines
2.9 KiB
C#

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Xunit;
namespace System.Linq.Tests
{
public class IntersectTests : EnumerableBasedTests
{
[Fact]
public void BothEmpty()
{
int[] first = { };
int[] second = { };
Assert.Empty(first.AsQueryable().Intersect(second.AsQueryable()));
}
[Fact]
public void FirstNullCustomComparer()
{
IQueryable<string> first = null;
string[] second = { "ekiM", "bBo" };
var ane = AssertExtensions.Throws<ArgumentNullException>("source1", () => first.Intersect(second.AsQueryable(), new AnagramEqualityComparer()));
}
[Fact]
public void SecondNullCustomComparer()
{
string[] first = { "Tim", "Bob", "Mike", "Robert" };
IQueryable<string> second = null;
var ane = AssertExtensions.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Intersect(second, new AnagramEqualityComparer()));
}
[Fact]
public void FirstNullNoComparer()
{
IQueryable<string> first = null;
string[] second = { "ekiM", "bBo" };
var ane = AssertExtensions.Throws<ArgumentNullException>("source1", () => first.Intersect(second.AsQueryable()));
}
[Fact]
public void SecondNullNoComparer()
{
string[] first = { "Tim", "Bob", "Mike", "Robert" };
IQueryable<string> second = null;
var ane = AssertExtensions.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Intersect(second));
}
[Fact]
public void SingleNullWithEmpty()
{
string[] first = { null };
string[] second = new string[0];
Assert.Empty(first.AsQueryable().Intersect(second.AsQueryable(), EqualityComparer<string>.Default));
}
[Fact]
public void CustomComparer()
{
string[] first = { "Tim", "Bob", "Mike", "Robert" };
string[] second = { "ekiM", "bBo" };
string[] expected = { "Bob", "Mike" };
Assert.Equal(expected, first.AsQueryable().Intersect(second.AsQueryable(), new AnagramEqualityComparer()));
}
[Fact]
public void Intersect1()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Intersect((new int[] { 1, 2, 3 }).AsQueryable()).Count();
Assert.Equal(2, count);
}
[Fact]
public void Intersect2()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Intersect((new int[] { 1, 2, 3 }).AsQueryable(), EqualityComparer<int>.Default).Count();
Assert.Equal(2, count);
}
}
}