chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi,

how to fake dependencies of a Product (DLLs in Visual-Studio) that has a License (licx based)?

We use a licensed/bought compontend called TxTextControl. This component requires a licenses.licx File.
We cannot use Isolate.Fake.Dependencies<TextControl>()because we receive a license error. How to use Fake Dependencies with DLLs that require a License *

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.ComponentModel.LicenseException : Für die folgende Control wurde keine gültige Lizenz gefunden:TXTextControl.TextControl

Regards from Germany,

Deniz
asked by Roche Lunaire (600 points)

1 Answer

0 votes
Hi Deniz,

Fake Dependencies is a power api that helps to create a real object that has dependencies.
It saves you the code that creates all the dependencies of the type you want to instantiate and pass it to its ctor.
If one of the dependencies isn't trivial, you'll have to fake it yourself.

The signature of this api is:
UnderTest real = Isolate.Fake.Dependencies<UnderTest>([args])

You can fakeinstantiate some of the dependencies manually and pass them into the the Fake.Dependencies method ([args]), and it will fake the rest of the dependencies for you.

See example:
[TestFixture]
class TestClass
{
    [Test]
    public void Test()
    {
        var dep2 = new Dep2();
        var underTest = Isolate.Fake.Dependencies<UnderTest>(dep2);
        underTest.print();
    }
}

public class UnderTest
{
    private Dep1 d1;
    private Dep2 d2;

    public UnderTest(Dep1 d_1 , Dep2 d_2)
    {
        d1 = d_1;
        d2 = d_2;
    }

    public void print()
    {
        d1.print();
        d2.print();
    }
}

public class Dep1
{
    public void print()
    {
        Console.WriteLine("inside Dep1");
    }
}

public class Dep2
{
    public void print()
    {
        Console.WriteLine("inside Dep2");
    }
}
The output of this test is "inside Dep2" since dep1 is fake and dep2 is real.


As for the dependency on the license, you can fake TxTextControl separately so that its state doesn't effect TextControl and then pass it to Fake.Dependencies.

You can find more info here.
Let me know if it helps.
answered by alex (17k points)
...