Progress Telerik JustMock

Mock LINQ Queries

  • JustMock enables you to easily mock LINQ queries to isolate parts of your code from their dependencies.
  • This feature is a part of the fastest, most flexible and complete mocking tool for crafting unit tests.
  • Our award-winning support team is dedicated to assisting you with any questions and issues you may have during your application development.
Mock everything
Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • Mocking LINQ Queries Overview

    Language-integrated queries, also known as LINQ, are a set of technologies based on integrating query capabilities directly into the C# & VB languages. They are very popular and widely used thanks to offering a common syntax for querying any type of data source, decreasing  development time by catching errors at compile-time, etc.

    JustMock enables you to easily mock LINQ queries to isolate parts of your code from their dependencies.
    [TestMethod]
    public void ShouldAssertWithCustomSelect()
    {
        var simpleDataInstance = new SimpleData();
     
        // ARRANGE - When simpleDataInstance.Products_GET is called,
        //           it should return expected collection.
        Mock.Arrange(() => simpleDataInstance.Products)
            .ReturnsCollection(ReturnExpextedCollectionOfProducts());
     
        // ACT - Applying a LINQ query for simpleDataMock.Products.
        var actual = (from p in simpleDataInstance.Products
                      where p.UnitsInStock == 50
                      select p.ProductID).SingleOrDefault();
     
        // ASSERT
        Assert.AreEqual(2, actual);
    }

    Mocking LINQ Queries documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.