Telerik Forums
JustMock Forum
0 answers
375 views

I have a test case to test my EF repository getallasync call as follows:

// Arrange
var systemsData = new List<SystemEntity>
{
new SystemEntity { SystemId = 1, Full_Year_Standings = true, Season_StartDate = DateTime.Now, Season_EndDate = DateTime.Now },
new SystemEntity { SystemId = 2, Full_Year_Standings = false, Season_StartDate = DateTime.Now, Season_EndDate = DateTime.Now },
new SystemEntity { SystemId = 3, Full_Year_Standings = true, Season_StartDate = DateTime.Now, Season_EndDate = DateTime.Now }
};

var mockContext = Mock.Create<BetCenterContext>(Behavior.Loose);
Mock.Arrange(() => mockContext.Set<SystemEntity>()).ReturnsCollection(systemsData);

var systemRepository = new SystemRepository(mockContext);

// Act
var result = await systemRepository.GetAllAsync();

 

Calling the following method:

 

public async Task<List<SystemEntity>> GetAllAsync()
{
var collToReturn = await _context.Set<SystemEntity>().ToListAsync();

return collToReturn;
}

The arranged mock returns a null result and throws InvalidOperationException - The source 'IQueryable' doesn't IAsyncEnumerable...'

How do I arrange the mock to return the correct value?

     
Edward
Top achievements
Rank 1
 asked on 05 Jun 2023
0 answers
158 views

Hi,

I'm interested in Telerik JustMock, so I'm installing and testing a trial version of JustMock.
The worry is that my development environment is disconnected from the Internet, so when I purchase the full version, it cannot be installed.
Are there any problems with the installation and operation of the full version even in an environment where the Internet is disconnected?

Thank you.
CB
Top achievements
Rank 1
 updated question on 08 Apr 2022
0 answers
205 views

I want the Mock to return the SQL statement and Not execute the statement. This is what i have done but it keeps running the "connection.execution(SQL)".  

                         

 

string SQL = "";

            Mock.Arrange(() => connection.Execute(Arg.AnyString, null, null, null, null)).DoInstead((string arg1) => { SQL = arg1; }).IgnoreInstance().Returns(1);



            WebApiProject.Controllers.DeleteController dc = new WebApiProject.Controllers.DeleteController();
           
            dc.Post(mockedDeleteObject);

            Assert.IsTrue(SQL == $"DELETE FROM TEST WHERE 1=1");

 

 

Post{

                string SQL;
                SQL = $"delete from {TableName}  where  {WhereClause} ";

                con.Execute(SQL,parameters );}

 

 

 

But it keeps running the sql executable statement

 

 

 

Ope
Top achievements
Rank 1
 asked on 03 Mar 2022
0 answers
35 views

Hi.

My configuration is: Visual Studio 2015 preview + JustMock Q2 2015 (2015.2.512.4)

Apparently static mocks don't work for me when i execute them from Windows Universal unit test project. It seems like the mock is not applied at all and the actual code is executed. For example here exception is not thrown:

Mock.SetupStatic(typeof(Assert), Behavior.Strict);
Mock.Arrange(() => Assert.IsTrue(Arg.AnyBool)).Throws(new ArgumentException());
Assert.IsTrue(true);

The same code though executes correctly and exception is thrown when i execute it from the regular unit test project.

Thank you.

 

Anton
Top achievements
Rank 1
 asked on 15 May 2015
0 answers
75 views
  • Parallel test execution fails with NCrunch
    • At this stage JustMock does not support parallel test execution via NCrunch. To execute JustMock tests with NCrunch set the Allow Parallel Test Execution option to false within the solution or disable parallel execution on a global level by setting the Max number of processing threads setting to 1.
  • Debugging Azure application fails if IntelliTrace 2012 and JustMock are linked
    • Possible workaround is to clear the link between both the profilers from the JustMock Configuration window. More details here.
  • "Unable to obtain public key for StrongNameKeyPair" exception in non-elevated tests
    • Such exception may occur if the Crypto\RSA folder does not have Read & execute or List folder contents permissions. To fix this you need to set them manually. To find the folder use this path - %appdata%\Microsoft\Crypto\rsa. More details here.  
Telerik Admin
Top achievements
Rank 1
Iron
 asked on 02 Jan 2014
0 answers
31 views
Nevermind.  It was a problem with having a static that was being re-used, not a problem with JustMock.  (please delete this post if possible)
Micah
Top achievements
Rank 1
 asked on 21 Aug 2013
0 answers
100 views
Recently, there were several client reports about interference between some of the default JustMock shortcuts inside Visual Studio. The conflicting shortcuts were the ones, used for enabling and disabling the JustMock profiler (JustMock.EnableProfiler and JustMock.DisableProfiler). The default keys for these commands were:
  • Ctrl + Alt + [
  • Ctrl + Alt + ]
It appeared these combinations are commonly used for typing the following symbols: { or [ and } or ]. The issue is possible to appear only on a certain keyboard layouts (e.g. Italian, Canadian-French, etc.)

This is already fixed in the upcoming JustMock official release. We have changed the shortcuts to not interfere with the user environment in such ways. The new shortcuts for enabling and disabling the profiler will be:
  • Ctrl + Shift + [     -     for JustMock.EnableProfiler
  • Ctrl + Shift + ]     -     for JustMock.DisableProfiler

As a workaround, until the next version is out, you can change the shortcuts from inside Visual Studio by performing the following:
  1. From Tools menu, go to Options;
  2. Navigate to Environment > Keyboard;
  3. Inside the "Show commands containing" text box write: JustMock
  4. Then find JustMock.EnableProfiler and JustMock.DisableProfiler and remove or change their shortcuts as you want (you can also change the rest of the JustMock shortcuts if required). Note that, you will need to remove the old shortcuts in order to disable them.
Telerik Admin
Top achievements
Rank 1
Iron
 asked on 08 Aug 2013
0 answers
98 views
Since JustMock Q1 2013 release we marked Mock.DoNotUseProfiler() method as an obsolete method. This can break your test project build.

We recommend updating your unit tests and avoid using it as it is considered bad practice. In case you have to call  Mock.DoNotUseProfiler() method you can vote here http://feedback.telerik.com/Project/105/Feedback/Details/42251-make-mock-donotuseprofiler-method-non-obsolete
Mihail
Top achievements
Rank 1
 asked on 28 Feb 2013
0 answers
41 views
Hello all,

I try to test if controller object has assigned a method to an event (see sample code at the end). 

I have a controller object, which gets two objects (getCalled & raiseEvent) via an interface. The object getCalled provides a 
method which should be assigned to an event of the object raiseEvent. This should be preformed from within the controller object.
The event can only occur after the raiseEvent.Start method has been called.

I thought, I write an Arrange statement, where the method getCalled.callMe must be called.
Additionally I write an Arrange statement, where an event should be raised, when the raiseEvent.Start method gets called.
Now I create the controller and call the method controller.Start. In this method the the method raiseEvent.Start will be called, which should rasie the Event raiseEvent.calledEvent, which should call the method getCalled.CallMe.
But the testrunner asserts with the message
"Setup contains calls that are marked as "MustBeCalled" but actually never called"

What do I make wrong?

best regards
  Bernhard

Here is the sample code

    using NUnit.Framework;

    using Telerik.JustMock;
    using Telerik.JustMock.Helpers;

    public interface IGetCalled
    {
        void CallMe(EventArgs arg);
    }

    public interface IRaiseEvent
    {
         event EventHandler<EventArgs> calledEvent;
         void Start();
    }

    public class Controller
    {
         private IRaiseEvent raiseEvent;
         private IGetCalled  getCalled;

         public Controller(IGetCalled getCalled, IRaiseEvent raiseEvent)
         {
             this.raiseEvent = raiseEvent;
             this.getCalled  = getCalled; 
     
             this.raiseEvent.calledEvent += (s, e) => this.getCalled.CallMe(e);         
         }
                        
         public void Start()
         {
             raiseEvent.Start();   
         }
    }

    [TestFixture]
    public class test
    {
        [Test]
        public void TestRaiseEvent()
        {
            IRaiseEvent raiseEvent = Mock.Create<IRaiseEvent>();
            IGetCalled getCalled = Mock.Create<IGetCalled>();

            getCalled.Arrange(x => x.CallMe(new EventArgs())).MustBeCalled();
            Mock.Arrange(() => raiseEvent.Start()).Raises(() => raiseEvent.calledEvent += null, new EventArgs());
            var controller = new Controller(getCalled, raiseEvent);

            controller.Start();
            getCalled.Assert();
        }
    }
Bernhard
Top achievements
Rank 1
 asked on 01 Oct 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?