Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

1.2 KB
Raw Blame
using Grand.SharedKernel.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Grand.SharedKernel.Tests.Extensions;

[TestClass]
public class ExtendedLinqTests
{
    [TestMethod]
    public void CartesianProductTest()
    {
        var sampleList = new List<SampleObject> {
            new() { Id = "1", Name = "name1" },
            new() { Id = "1", Name = "name2" },
            new() { Id = "3", Name = "name3" }
        };

        var cartesianProduct = sampleList.GroupBy(x => x.Id).CartesianProduct().ToList();
        Assert.HasCount(2, cartesianProduct);
    }

    [TestMethod]
    public void ContainsAnyTest_True()
    {
        var sampleList = new List<int> { 1, 2, 3, 4 };
        Assert.IsTrue(sampleList.ContainsAny(new List<int> { 2, 3 }));
    }

    [TestMethod]
    public void ContainsAnyTest2_True()
    {
        var sampleList = new List<int> { 1, 2, 3, 4 };
        Assert.IsTrue(sampleList.ContainsAny(new List<int> { 2, 5 }));
    }

    [TestMethod]
    public void ContainsAnyTest_False()
    {
        var sampleList = new List<int> { 1, 2, 3, 4 };
        Assert.IsFalse(sampleList.ContainsAny(new List<int> { 5, 6 }));
    }
}