Telerik Forums
JustMock Forum
1 answer
146 views
Hi,

In Visual Studio, my shortcut to "Step into" while I'm debugging is F8.

When I'm into a test in debug mode and I press F8 to step into and when I'm on a line like Mock.Arrange or any other instruction using JustMock, the system is trying to enter in the code of JustMock. 

In my visual studio, I have enable just my code in debugging options.

I have no problem with any other third party control in the sens that F8 don't try to step into the code of the third party.

It's very weird.

Here is what it show in the immediate when I press F8 on a line with JustMock instruction:

Step into: Stepping over non-user code 'System.Linq.Expressions.Expression.Constant'
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Step into: Stepping over non-user code 'Telerik.JustMock.Mock.<bool>.'

Public Sub Execute_SimpleRequest_ReturnsTrue()
   Dim executor As New DatabaseExecutor
 
   executor.Connection = New Connection
 
   Mock.Arrange(Function() executor.Connection.Open).Returns(True)
 
   Assert.AreEqual(True, executor.Execute)
End Sub

These messages are shown on the line Mock.Arrange....

The reason why I use Step into instead of Step over is just because I want systematically to enter in any functions of my code. Remember before answering that I have no problem with other third party like your, Infragistics, DevExpress, ActiveReports, etc...

Thank you very much.
Michel Corbin
Top achievements
Rank 1
 answered on 31 Dec 2010
1 answer
112 views
To be honest I haven't really tried JustMock as of yet, but we've recently ran into some issues with OpenAccess where some updates have broken some functionality...

So as I understand it, the Mocking tool can "Fake" a database?

Is it possible to write some tests to create an OA object, then commit that object, but the database end is handled by JustMock?

Is that how this all works together? :)
Ricky
Telerik team
 answered on 01 Dec 2010
2 answers
112 views
Hi, I'm trying to evaluate JustMock for the team. Trying to convert some Moq tests to JustMocks and I'm getting an error like:

Test method Implementation.Test.HealthCheckHandlerTest.active_endpoints_returns_results_using_JustMock threw exception:
System.TypeAccessException: Attempt by method 'PrivateApiProxy_Interceptor_38cce20ce0d04bd6b91832ef4a05927c.Intercept(Implementation.PrivateApiAccess.PrivateApiProxy, Boolean ByRef)' to access type 'System.Collections.Generic.IEnumerable`1<Implementation.PrivateApiAccess.PrivateApiResponse>' failed.

Strangely, although I initialized them as strict, the calls seem to be falling through into the implementation.

I'm in a bit of a hurry, so I've simply remove some of the namespaces to protect the inocent. Can you tell me what I might be doing wrong to recieve this error. I may be able to write something stand alone that I can share, but it is annoying when you get an unhandle exception from the framework.
Ricky
Telerik team
 answered on 30 Nov 2010
1 answer
199 views

Hi,

I'm trying out the JustMock and getting it up and running on my local dev box (Windows 7 x64) with VS 2010 installed was no problem. However, I'm having problem getting the tests to run on our Windows 2003 build server where there's no VS installed.

I have added the <Import ...> and <JustMockStart> + <JustMockStop> in my build script, but it seems like the CLR profiler won't start when running on the build server. Am I missing something? Do I need to download and install CLR Profiler for .Net 2.0 (http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=a362781c-3870-43be-8926-862b40aa0cd0&displaylang=en) on the build server? Or is VS required?

- kjetil

Ricky
Telerik team
 answered on 05 Nov 2010
2 answers
127 views
Please see the narrowed down code-example below.

What I expect is the method IsElf() to return a value of TRUE.
When I debug the UnitTest, mensMock.Leeftijd returns a value of 11. When I look at the value of actual, it's value = false???
It seems that the Mock object is not 'routing' the call as expected...

When I use the Behaviour.CallOriginal setting (which is not documented BTW) when Creating the Mock everything works as expected. Loose and Strict mode both fail.

I really like your concept of mocking, could you please tell me what I'm doing wrong?

Kind regards from Holland & TIA,

Ronald.
----
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;
using PatrickMocks;
namespace PatrickMocks
{
    public class Mens
    {
        public int Leeftijd { getset; }
        public virtual bool IsElf()
        {
//            this.Foo();
            return (this.Leeftijd == 11);
        }
        public virtual void Foo()
        {
            this.Leeftijd++;
            this.Leeftijd--;
        }
    }
}
namespace MockTest
{
    [TestClass()]
    public class MensTest
    {
        [TestMethod()]
        public void IsElfTest()
        {
            // Arrange
            Mens mensMock = Mock.Create<PatrickMocks.Mens>();
            //Mens mensMock = Mock.Create<PatrickMocks.Mens>(Behavior.CallOriginal);             //<== THIS WORKS OK!!!
            Mock.Arrange(() => mensMock.Foo()).CallOriginal().MustBeCalled();

            // Act
            bool expected = true// TODO: Initialize to an appropriate value
            bool actual = true;
            mensMock.Leeftijd = 11;
            actual = mensMock.IsElf();

            // Assert
            Assert.AreEqual(expected, actual);
            Mock.Assert(mensMock);       // Check dat deze method gedraaid heeft!
        }
    }
}
Ricky
Telerik team
 answered on 03 Nov 2010
5 answers
169 views
Hi,

is there any way to mock the the call to SPSecurity.RunWithElevatedPrivileges delegate, e.g.

...
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Code to unit test
});
...

Basically, I'd like to test the code passed as an anonymous delegate to the SPSecurity.RunWithElevatedPrivileges(), but am not able to mock the call to the SPSecurity.RunWithElevatedPrivileges() to simply bypass SharePoint and just execute whatever is passed in.

Any suggestions?

Regards, Robert
Ricky
Telerik team
 answered on 27 Oct 2010
4 answers
107 views
I seem to be having problems with mocking final methods (or any other elevated features).  even running the examples fails.  Take the following for instance...

 [TestMethod]
        public void ShouldTreatSetupsForTwoDifferentInstancesDifferently()
        {
            var foo1 = Mock.Create<Foo>();
            var foo2 = Mock.Create<Foo>();

            Mock.Arrange(() => foo2.Echo(Arg.IsAny<int>())).Returns(10);
            Mock.Arrange(() => foo1.Echo(Arg.IsAny<int>())).Returns((int arg) => arg);
       
            Assert.Equal(foo2.Echo(12), 10);
            Assert.Equal(foo1.Echo(12), 12);
        }

I expect both of these asserts to return true but the first fails as the call to echo returns 36.  I have the 'advanced' features turned on from the justmock menu (VS2008SP1) but no matter what I try it just wont pass.

Any help greatly appreciated,

Leom
Ricky
Telerik team
 answered on 26 Oct 2010
1 answer
109 views
Hello,

I got a question or sort of functionallity request.
After a little while working with JustMock, I found out that the Assert(action) communicates with Arrange(action).

I will show you a sample of how the code works how it is now

//Arrange
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting1.Name)).Returns(moduleSetting1.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting2.Name)).Returns(moduleSetting2.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting3.Name)).Returns(moduleSetting3.Value).MustBeCalled();
  
//Act
_presenter.Load();
  
//Assert
Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting1.Name), Occurs.Exactly(1));
Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting2.Name), Occurs.Exactly(1));
Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting3.Name), Occurs.Exactly(1));

Well in the sample I got 3 module settings but in the real code i got like 12. Now I want to validate how much times it is cast with 1 code rule not 12. I thougth about the below solution but it always says it has been called once.

//Arrange
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting1.Name)).Returns(moduleSetting1.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting2.Name)).Returns(moduleSetting2.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting3.Name)).Returns(moduleSetting3.Value).MustBeCalled();
  
//Act
_presenter.Load();
  
//Assert
Mock.Assert(() => _mock.ThisIsAMethod(module, Arg.AnyString), Occurs.Exactly(3));

This woulth be a good solution because it saves me a lot of code. Hope this is possible some how or will be possible in the next update.

Thanks in advance,
Jeroen Speldekamp
Ricky
Telerik team
 answered on 18 Oct 2010
3 answers
127 views
Hi,

We're using TFS2010, and we think we've installed JustMock correctly on the server, but everytime we run the build any test using the Static mocking is failing and everything else passes.

The documentation only seems to deal with the 2008 build scripts, is there a 2010 version anywhere?

Thanks,
John
Ricky
Telerik team
 answered on 24 Sep 2010
1 answer
134 views
Hi,

I'm trying to mock a RegisterType call on a mock Unity Container, but it's not being called.  I've recreated the test as follows:

        [TestMethod]
        public void TestMethod1()
        {
            IUnityContainer mockContainer = Mock.Create<IUnityContainer>();
            Mock.Arrange(() => mockContainer.RegisterType<IConcrete, Concrete>()).Returns(mockContainer);

            Class1 consumingClass = new Class1(mockContainer);

            consumingClass.RegisterStuffInUnity();

            Mock.Assert(() => mockCOntainer.RegisterType<IConcrete, Concrete>(), Occurs.Once());
        }

IConcrete and Concrete are empty, obviously Concrete implements IConcrete.

Class1 is very simple as follows:

    public class Class1
    {
        private readonly IUnityContainer _container;

        public Class1(IUnityContainer container)
        {
            _container = container;
        }

        public void RegisterStuffInUnity()
        {
            var bob = _container.RegisterType<IConcrete, Concrete>();
        }
    }

Any ideas?

Thanks,
John
Ricky
Telerik team
 answered on 22 Sep 2010
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?