Telerik Forums
JustMock Forum
3 answers
239 views
I'm using Visual Studio 2013. 

I've configured JustMock to "run together with JustMock" all detected profilers, however I'm seeing this exception:

Test Name: IndexPageTest
Test FullName: XXXXXXX.XXXX.Tests.Transport.TransportControllerTests.IndexPageTest
Test Source: c:\XXXXXXXXXXX\XXXXXweb\User Interface\Tests\Transport\TransportControllerTests.cs : line 24
Test Outcome: Failed
Test Duration: 0:00:00

Result Message: Unable to create instance of class XXXXXXX.XXXX.Tests.Transport.TransportControllerTests. 
Error: Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'XXXXXXX.XXXX.Web.Application.Core.Providers.UserProfileProvider'. 
The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {B61B010D-1035-48A9-9833-32C2A2CDC294} (from process environment)
Disable the profilers or link them from the JustMock configuration utility. Restart Visual Studio and/or the test runner after linking..
Result StackTrace:
at Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)
   at Telerik.JustMock.Core.MocksRepository.InterceptStatics(Type type, IEnumerable`1 mixins, IEnumerable`1 supplementaryBehaviors, IEnumerable`1 fallbackBehaviors, Boolean mockStaticConstructor)
   at Telerik.JustMock.MockBuilder.InterceptStatics(MocksRepository repository, Type type, Nullable`1 behavior, Boolean mockStaticConstructor)
   at Telerik.JustMock.Mock.<>c__DisplayClass67.<SetupStatic>b__66()
   at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal(Action guardedAction)
   at Telerik.JustMock.Mock.SetupStatic(Type staticType, StaticConstructor staticConstructor)
   at XXXXXXX.XXXX.Tests.Common.ControllerTestBase..ctor() in c:\XXXXXXXXXXX\XXXXXweb\User Interface\Tests\Patient\TransportTest.cs:line 75
   at XXXXXXX.XXXX.Tests.Transport.TransportControllerTests..ctor()


Help!

Thanks in advance,
-bill 
Stefan
Telerik team
 answered on 31 Jul 2014
5 answers
176 views
I am trying to mock this for a unit test... I need help getting all items in here mocked. what I have done does not work and it seems like that the mocks never get hit when they are supposed to. I know that a few of the items are part of our library and may not work on your  machines but if you could help please get it on track and I can run it and straighten it out if needed.

public static string GetEnumDisplayName<T>(string enumName)
        {
            string retVal = null;
            MemberInfo memberInfo = typeof(T).GetMember(enumName).FirstOrDefault();
            if (memberInfo != null)

            {
                object[] customAtts = memberInfo.GetCustomAttributes(typeof(IDisplayName), false);
                if (customAtts != null && customAtts.Length > 0)
                {
                    retVal = ((IDisplayName)customAtts[0]).DisplayName;
                }
                //
                if (retVal == null)
                {
                    customAtts = memberInfo.GetCustomAttributes(typeof(GeneralDisplayNameAttribute), false);
                    if (customAtts != null && customAtts.Length > 0)
                    {
                        retVal = ((GeneralDisplayNameAttribute)customAtts[0]).DisplayName;
                    }
                }
            }
            return retVal;
        }
Matthew
Top achievements
Rank 1
 answered on 29 Jul 2014
5 answers
121 views
[TestFixture]
public class Class1
{
    public class Individual
    {
         
    }
    public class Family : Collection<Individual>
    {
         
    }
    public interface ITest
    {
        int Test(Family family);
    }
 
    [Test]
    public void Test()
    {
        var family1 = new Family();
        var family2 = new Family();
 
        var test = Mock.Create<ITest>();
        Mock.Arrange(() => test.Test(family1)).Returns(1).MustBeCalled();
        Mock.Arrange(() => test.Test(family2)).Returns(2).MustBeCalled();
 
        var result = test.Test(family1) + test.Test(family2);
 
        Mock.Assert(test);
    }
}
In the code as written I get an error:
Occurrence expectation failed. Expected at least 1 call. Calls so far: 0
Arrange expression: () => test.Test(family1).

However, when I change the code to not have Family based on Collection<Individual> it works.

This does not seem correct.  Is this a bug, or am I missing something on how JustMock is matching these parameters?

Eric Gurney
Stefan
Telerik team
 answered on 24 Jul 2014
5 answers
106 views
Greetings,

I downloaded JuckMocked, open the VB.NET solution, did a build and got a good deal of errors in various statements in regards to Lambda inline functions. Now I could go in and figure them out easily but I am not here for that but instead to evaluate this product hence my thread.

BTW: No issues with the C# solution.

Open with VS2012 Ultimate
Kaloyan
Telerik team
 answered on 18 Jul 2014
1 answer
189 views
Am I correct in saying that when using the AutoMocking container to assert a call on a dependency, you *have* to create some form of expectation which is then asserted (e.g. with AssertAll), rather than just defining the assertion at the end?

For example, the following works:
[TestMethod]
public void Test()
{
 var c = new MockingContainer<Target>();
 c.Arrange<ITargetDependency>(x => x.ShouldBeCalled());

 c.Instance.WorkYourMagic();

 c.AssertAll(); // will fail if WorkYourMagic does not call ITargetDependency.ShouldBeCalled()
}

However, this does not...
[TestMethod]
public void Test()
{
 var c = new MockingContainer<Target>();

 c.Instance.WorkYourMagic();

 c.Assert<ITargetDependency>(x => x.ShouldBeCalled()); // Always claims WorkYourMagic does not call ITargetDependency.ShouldBeCalled()
}

Regards,
Nick
Stefan
Telerik team
 answered on 18 Jul 2014
1 answer
117 views
The following works:
using NUnit.Framework;
using Telerik.JustMock.AutoMock;
 
namespace AutoMockBug
{
    public interface IBar
    {
        void DoNothing();
    }
 
    public class Baz
    {
        public IBar Bar;
        public Baz(IBar bar)
        {
            Bar = bar;
        }
    }
 
    [TestFixture]
    public class Class1
    {
        [Test]
        public void test()
        {
            var container = new MockingContainer<Baz>();
            container.Arrange<IBar>(x => x.DoNothing()).OccursOnce();
 
            container.Instance.Bar.DoNothing();
 
            container.Assert();
        }
    }
}

This doesn't work:
using NUnit.Framework;
using Telerik.JustMock.AutoMock;
 
namespace AutoMockBug
{
    public interface IFoo
    {
        IBar GetBar();
    }
 
    public interface IBar
    {
        void DoNothing();
    }
 
    public class Baz
    {
        public IFoo Foo;
        public Baz(IFoo foo)
        {
            Foo = foo;
        }
    }
 
    [TestFixture]
    public class Class1
    {
        [Test]
        public void test()
        {
            var container = new MockingContainer<Baz>();
            container.Arrange<IBar>(x => x.DoNothing()).OccursOnce();
 
            container.Instance.Foo.GetBar().DoNothing();
 
            container.Assert();
        }
    }
}
Stefan
Telerik team
 answered on 18 Jul 2014
4 answers
328 views
On another forum I found out how to mock the Operational context in this snippet

what I want to do is mock the endpoint in it now, My unit test here needs to test all aspects and I am having issues actually mocking the endpoint

truthfully I do not know what needs to be mocked or how but I know what I want the end result to be. I just need to be able to get endpoint to not be null and set
retVal = endpoint.Address;
Ive tried so many things that I could not get a result 

The code:

        public static string GetCallerIPAddress()
        {
            string retVal = null;
            if (OperationContext.Current != null)
            {
                MessageProperties prop = OperationContext.Current.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                if (endpoint != null)
                {
                    retVal = endpoint.Address;
                }
            }
            return retVal;
        }
Stefan
Telerik team
 answered on 18 Jul 2014
3 answers
147 views
01.public class Foo
02.{
03.    public Bar Bar;
04. 
05.    public Foo(Bar bar)
06.    {
07.        Bar = bar;
08.    }
09.}
10. 
11.public class Bar
12.{
13.    public IBaz Baz;
14. 
15.    public Bar(IBaz baz)
16.    {
17.        Baz = baz;
18.    }
19.}
20. 
21.public interface IBaz
22.{
23.    String GetString();
24.}
25. 
26.[Test]
27.public void when()
28.{
29.    var foo = new MockingContainer<Foo>();
30.    foo.Arrange<IBaz>(baz => baz.GetString()).Returns("Rawr!");
31. 
32.    var actualResult = foo.Instance.Bar.Baz.GetString();
33. 
34.    Assert.AreEqual("Rawr!", actualResult);
35.}

Given the above code, a null reference exception is thrown on line 32.

I am using NInject to do constructor dependency injection.  I have a large hierarchy of classes that take in their dependencies in their constructors as Foo and Bar do above.  I want all of my concrete classes to be instantiated and only have the interfaces get mocked.  In the above example, I want a real Bar constructed and a real Foo constructed but I want IBaz to be mocked.

I am aware that in the above scenario I could just manually construct a Foo, passing in a manually constructed Bar, but in my scenario, the dependency hierarchy is large and complex and interfaces wrap all external (not my code calls).  Is there an easy way to tell the MockingContainer<Foo> that it should mock all interfaces but not mock any concrete classes (actually instantiate them).

As I said, I am using Ninject to instantiate my classes and it does the right thing everywhere.  I understand that the automocking container is backed by Ninject.  Is there a way I can bind certain interfaces/classes to JustMock?  In the above example I could do something like:

kernel.Bind<IBaz>().To<Mock<IBaz>>()?  That way I could just use Ninject to instantiate my object hierarchy, but tell it which interfaces I want it to bind to JustMock mocked instances.
Stefan
Telerik team
 answered on 18 Jul 2014
15 answers
215 views
Hi all,

 I was wondering if JusyMock could easily "intercept" object creation and replace them with fakes created on the fly?

I'm trying to unit test a method that, amongs other things, creates an instance of an object of a certain type and then uses it.  The instance is NOT injected into the method and so I cannot control what instance is used inside the method...

I know that some other mocking framework do support Future Objects mocking.  Is it the case with JustMock ?

Thanks for your time,

Vincent Grondin

EDIT:   I think I need the "Weaver" library to accomplish this, can someone from telerik tell me if this library is included in the FREE version of JustMock? 
Kaloyan
Telerik team
 answered on 16 Jul 2014
3 answers
373 views
Hi,

Looking at getting JustMock but have a simple license question. If say in a dev team of 20, only 10 would write unit tests, but the unit tests are in the solution, would the remaining 10 developers that don't have a JustMock license be able to build and run the unit tests?

Thanks for your help

Graham
Joseph
Telerik team
 answered on 14 Jul 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?