Progress Telerik JustMock

Mock DLL Imports

  • JustMock allows you to easily mock methods marked with the DLLImport attribute and test your code in isolation from such 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 DLL Imports Overview

    The DLLImport is a storage class attribute that represents a Microsoft-specific extension to the C and C++ languages. With such extensions, you can import C and C++ DLLs and use them in C# or VB code. This inevitably makes your code dependent on calls to the C or C++ API.

    JustMock allows you to easily mock methods marked with the DLLImport attribute and test your code in isolation from such dependencies.

    public class Foo
    {
        [DllImport("Kernel32.dll")]
        public static extern int GetCurrentProcessId();
    }
     
    ...
     
    [TestMethod]
    public void FormatCurrentProcessId_OnExecute_ShouldReturnExpected()
    {
        var expected = 3500;
      
        // Arrange
        Mock.Arrange(() => Foo.GetCurrentProcessId()).Returns(expected);
      
        // Act
        var myFoo = new Foo();
        var actual = myFoo.FormatCurrentProcessId();
      
        // Assert
        Assert.AreEqual(string.Format("The current process ID is {0}", expected), actual);
    }

    Mock DLL Imports documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.