Telerik Forums
JustMock Forum
3 answers
575 views

Hi,

 

I'd like to test the implementation of the my abstract class, but I'm not able to intercept the constructor of the base class.

Here the snippet code:

 

public abstract class Base
{
    public virtual void Start(IContext context)
    {
         \\ do something
    }
}
public class Child : Base
{
    public override void Start(IContext context)
    {
         \\ do something
    }
}

 

I'd like to test it like this:

private Base mBase;
private Child mPlugin;
 
[TestInitialize]
public void Initialize()
{
   mBase = Mock.Create<Base>(Constructor.Mocked);
   mPlugin = new Child();
}
 
[TestMethod]
public void TestStart()
{
    IContext mockContext = Mock.Create<IContext>();
    Mock.Arrange(() => mBase.Start(mockContext)).DoNothing();
     
    // test plugin code
     
    mPlugin.Start(mockContext);
}

 

What is wrong?

 

Thanks,

Ste

 

Mihail
Telerik team
 answered on 10 Jun 2019
2 answers
80 views
Instance creation timed out and aborted 
Lyubomir Rusev
Telerik team
 answered on 28 May 2019
1 answer
501 views

I am trying out JustMock, so maybe I have made some beginners mistake. But I cannot get tests to run with coverage.

I am using: VS2019 16.0.4, Just Mock 2019.2.508.1 (in Trial mode), ReSharper / DotCover 2019.1.1. JustMock has been linked to both DotCover and VS2019 Code Coverage.

I normally run with the ReSharper test runner and use DotCover for coverage. That works OK for JustMock with the profiler disabled with or without coverage or with the profiler enabled but then only without code coverage.

DotCover "Cover all tests" hangs after the build with all unit tests shown as pending. VS GUI is responsive, about 5% CPU load, but nothing is happening.

I also tested the built in VS test runner and coverage measurement. Same picture test runs OK as long as you do not ask for coverage. Use "Analyze code coverage > All tests" in VS gives the same behavior as with the ReSharper / DotCover. 

Any suggestions?

/Mats

Mihail
Telerik team
 answered on 21 May 2019
3 answers
123 views

Hi

I try to fake the getitems method on a list i the sharepoint clientcontext. For some reason its always returning no elements. Can someone put me in the right direction?

ClientContext context = Isolate.Fake.NextInstance<ClientContext>();
            List list = Isolate.Fake.Instance<List>();
            ListItem fakeListItem = Isolate.Fake.Instance<ListItem>();
            List<ListItem> listItems = new List<ListItem> { fakeListItem, fakeListItem, fakeListItem };
 
            Isolate.WhenCalled(() => list.GetItems(null)).WillReturnCollectionValuesOf(listItems);
            Isolate.WhenCalled(() => context.Web.Lists.GetByTitle(string.Empty)).WillReturn(list);
            Isolate.WhenCalled(() => context.Load(list)).IgnoreCall();
            Isolate.WhenCalled(() => context.ExecuteQuery()).IgnoreCall();
 
            // Act
            var cut = new ClassUnderTest();
            int itemsCount = cut.GetListItemsCount(string.Empty, string.Empty);

           

Here itemsCount returns always 0 elements. Am I using a wrong context/instance?

 

GetListItemsCount is doing the following

using (ClientContext clientContext = new ClientContext(siteUrl))
                {
                    List theList = clientContext.Web.Lists.GetByTitle(listTitle);
                    CamlQuery q = CamlQuery.CreateAllItemsQuery();
                    var items = theList.GetItems(q);
                    clientContext.Load(theList);
                    clientContext.Load(items);
 
                    clientContext.ExecuteQuery();
 
                    return items.Count;
                }

 

Nothing special so far.

 

Ivo
Telerik team
 answered on 15 May 2019
1 answer
521 views
I am trying to test a derived class constructor, but keep hitting code in the base class constructor  This post(https://www.telerik.com/forums/mock-base-class-constructor#PUXW928ic0SPaEl3wK8Mxg) shows how to mock a base class constructor, but it does not work if the base class is abstract.
Mike
Top achievements
Rank 1
 answered on 26 Apr 2019
4 answers
782 views

I have a unit test that creates a mocked instance of a class and arranges some of its properties. The test then executes some extension methods of that class.

When I run the test under visual studio 2017 (JustMock 2019.1.207.1) my tests pass. When I run the same test using the VsTest v2 build task the test fails due to an unarranged mock on the class which corresponds to a call of an extension method.

The code looks something like :

public class Person {
  public string Name { get; }
}
 
public static PersonExtensions {
  public int NameLength(this Person person) {
    return person.Name.Length;
  }
}
 
var fakePerson = Mock.Create<Person>(Behavoir.Strict);
Mock.Arrange(() => fakePerson.Name).Returns("Toto"):
 
var expected = 4;
var actual = fakePerson.NameLength(); // <--- exception here
 
// ...etc.


First strange thing is the test works in visual studio but on the build server.
Second strange thing is the exception says I have declared a strict mock on the PersonExtensions static class :

Telerik.JustMock.Core.StrictMockException: Called unarranged member 'Int32 NameLength(Person)' on strict mock of type 'PersonExtensions'<br>at Telerik.JustMock.Core.Behaviors.StrictBehavior.Process(Invocation invocation)
at Telerik.JustMock.Core.MocksRepository.DispatchInvocation(Invocation invocation)
at Telerik.JustMock.Core.ProfilerInterceptor.DispatchInvocation(Invocation invocation)
at Telerik.JustMock.Core.ProfilerInterceptor.InterceptCall(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, Object[] data)
at PersonExtensions.NameLength(Person person)...

If I could reproduce the error in visual studio it would be easier to find a way around it, I will probably do some CallOriginal arranges on the extension methods of the class.

Have you any ideas ?

Thanks,

 

Rob

Mihail
Telerik team
 answered on 15 Apr 2019
10 answers
208 views

Does JuckMock supports mocking the static classes in unit test that runs in parallel? 

I know JuckMock supports Elevated Mocking but does it work in unit tests that runs against each other in parallel?

 

Mihail
Telerik team
 answered on 01 Apr 2019
3 answers
4.6K+ views

Hi,

 

I'm trying to mock a Dictionary.TryGetValue method based on what's described in this thread to no avail.

What I've tried so far:

var dictionary = Mock.Create<Dictionary<string, HashSet<SomeClass>>>();
 
HashSet<SomeClass> expected = new HashSet<SomeClass>();
expected.Add(new SomeClass(param1, param2));
Mock.Arrange(() => dictionary.TryGetValue(Arg.AnyString, out expected)).Returns(true);

However, when ever I run the test, I get a null in the out object.

To give some context, not sure it impacts or not, the test spans a service running in a separate thread. The mocked dictionary is successfully inserted via a PrivateAccessor. 

Thanks in advance,

JP

 

Ivo
Telerik team
 answered on 29 Mar 2019
1 answer
96 views

Hey all, 

New to mocking so bare with me :-)

trying to create a mock up of and AzureConnection within my function app. To create the connection to Azure i have a class "AzureConnection.cs that initiates a connection to Azure using "IAuthenticated Authenticate" iam able to Mock this without issues, but when i try to arrange my connection to always return a specific TenantId it fails!

            var AzureConnectionMock = Mock.Create<AzureConnection>(Behavior.Loose);
            Mock.Arrange(() => AzureConnectionMock.AzureAuthenticated.TenantId)
                .Returns("MyTenantID");

Maybe iam doing this completely wrong, thus hopping someone could help?

Thx

Lyubomir Rusev
Telerik team
 answered on 08 Feb 2019
2 answers
71 views

Hello,

From this link for 2019 R1, we see that it supports .NET Core 2.0:  https://www.telerik.com/support/whats-new/justmock/release-history/justmock-2019-r1

It's commendable to have .NET Core support in JustMock, but 2.0 has been EOL since 01 Oct 2018:  https://github.com/dotnet/announcements/issues/86

Does 2019 R1 also support .NET Core 2.1 (which is an LTS version) and 2.2?  If so, would you please update the announcement at the first link to make that immediately clear?  If not, is there a timeline for .NET Core 2.1 and 2.2 support?  I'll be removing the .NET Core 2.0 SDK from our TFS build servers soon due to the recent security issue, which will not be patched in .NET Core 2.0.

Finally, .NET Core 1.0 and 1.1 are also LTS versions.  Does the announcement of .NET Core 2.0 support include support for 1.0 and 1.2?  Regardless of the answer, would you please update the announcement at the first link to clarify that?

Thanks in advance for any illumination you can provide.

 

Regards,

Tom Slavens

Platform Configuration Architect, Software Services

Veterans United Home Loans

 

Platform
Top achievements
Rank 1
 answered on 30 Jan 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Michael
Top achievements
Rank 1
Iron
Wilfred
Top achievements
Rank 1
Alexander
Top achievements
Rank 2
Iron
Iron
Matthew
Top achievements
Rank 1
Iron
ibra
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Michael
Top achievements
Rank 1
Iron
Wilfred
Top achievements
Rank 1
Alexander
Top achievements
Rank 2
Iron
Iron
Matthew
Top achievements
Rank 1
Iron
ibra
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?