Telerik Forums
JustMock Forum
2 answers
83 views
I grabbed Alpha 3 this morning from NuGet and I seem to be unable to mock EF6 the way I would normally mock OpenAccess. When I try a simple:

var test = Mock.Create<DemoEntities>();

I get a TypeLoadException:

Method 'CallValidateEntity' on type 'DemoEntitiesProxy+53c69f86fe444525a693c487adc77799' from assembly 'Telerik.JustMock.Dynamic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a method that is not visible from that assembly.

Any thoughts?
Kaloyan
Telerik team
 answered on 11 Mar 2013
14 answers
1.1K+ views
I am using JustMock in ~140 tests, and am experiencing some strange issues with a group of test failing when the entire set of test is run, but passing when run independently.  Currently it takes 3 test runs for all test to pass, with no changes to the code between runs.

They seem to be failing because mocks are not correctly intercepting method/property calls.

Are there any known issue with the mocks interfering with each other when used in multiple tests?  Due to legacy library use there is a lot of Final and Static mocking in the tests, could this have something to do with it?
Kaloyan
Telerik team
 answered on 08 Mar 2013
1 answer
268 views
I would like to stop the JustMock Expired dialog from popping up everytime I start Visual Studio. How do I do this?
Kaloyan
Telerik team
 answered on 05 Mar 2013
0 answers
167 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
3 answers
116 views
I have generated code, with this constructor:

internal Priority(Int32 priorityId, String name, Int32 rank, Int32 expirationBuffer, Boolean isLiveMicrophone, Boolean isEmergency, Boolean isRepeated, Int32 repeatBuffer, Single levelAdjustment, Boolean isInterruptible, Int32 percentAvailable)

When I mock the GetAll() method of the class (that calls the above constructor), it throws the "JIT Compiler encountered an internal limitation." error:

Mock.Arrange(() => Dvams.Priority.GetAll()).Returns(new Dvams.PriorityList());
var p = Dvams.Priority.GetAll();

JustMock version 2012.2.813.9.
If I modify the generated code to use only 8 parameters, it works fine. (I cant really modify the generated code in production)
Ran on another developers computer, same JustMock version, it works fine. (WHY?)

Any ideas as to how and/or why this is happening?  I would think JustMock would bypass the internals of GetAll(), ignoring the constructor, but it doesnt seem to be the case (at least on my computer).

Thanks,
Brian
Brian Pratt
Top achievements
Rank 1
 answered on 28 Feb 2013
4 answers
125 views
So, I am able to fake out static properties like DateTime.Now from the examples, but I'm having issues faking out the FileInfo objects if I create a new instance of the class in my libraries.  Can anyone help fix the code below?

// MyLibraryClass.cs
public class MyLibraryClass
{
        public void FileInfoDeleteMember(string filename)
        {
            var fi = new FileInfo(filename);
            fi.Delete();
        }
}



// FileInfoTests   
    [TestClass]
    public class FileInfoTests
    {
        static FileInfoTests()
        {
            Mock.Replace<FileInfo>(x => x.Delete()).In<MyLibraryClass>(c => c.FileInfoDeleteMember(Arg.AnyString));            
        }

        [TestMethod]
        public void ShouldNotDeleteFileWhenCalled()
        {
            var called = false;            
            var mlc = new MyLibraryClass();

            Mock.Arrange(() => new FileInfo(Arg.AnyString).Delete()).DoInstead(() => called = true);
                                   
            mlc.FileInfoDeleteMember(@"C:\test.txt");            
            Assert.AreEqual(called, true);            
        }
    }




Kaloyan
Telerik team
 answered on 25 Feb 2013
2 answers
146 views
Hello,

I have installed the commercial version of JustMock. When I run a NUnit-Test using the ReSharper-TestRunner in Visual Studio 2010 the JustMock Profiler is never enabled (Telerik.JustMock.IsProfilerEnabled=false). In the Visual Studio menu 'Telerik -> JustMock -> Enable Profiler' is grayed out (disabling and enabling didn't help ). The Windows EventViewer shows that the profiler has been started:

.NET Runtime version 4.0.30319.296 - The profiler was loaded successfully. Profiler CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'. Process ID (decimal): 4288. Message ID: [0x2507].
Any ideas whats going wrong?

Thanks, Tobias

Kaloyan
Telerik team
 answered on 22 Feb 2013
1 answer
127 views
Help me to complete the test methods for below code
I have one method OrderProducts in Shop class  which  place the order or request new stock when products are not there.
Can you help me mock the local call and external call.
There is method OrderProducts and against each line of the code I provided the comments what I want to mock in the Testmethods. 

Copy paste the below code in one .cs file of JustMockTest project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
  
 
namespace Business
{
    public class Shop
    {
        public Shop() { }
        public void OrderProducts()
        {
            LogInfo log = new LogInfo();//From the test method should be able to  skip  this constructor assume there is big amount of the dependent code in the constructor   
            CategoryType cat = new CategoryType();
            cat.Level = 2; //From the test method should be able to set cat.Level equal to 10
            var categories = CategoryHelper.GetCategories(cat); //want pass cat level 3 and return any three item
            this.CategoriesList = categories;
            bool retval = true; //From the test method should be able to set retval equal to false
            IProductService productProxy = WCFServicesInstance.GetWCFServiceInstance<IProductService>();
             
            List<Product> productlist = productProxy.ProductsByCategories(log, CategoriesList);
            
           if(productlist.Count>0)
           {
                
               int orderID=PlacetheOrder(productlist); //From the test method should be able to call another method like DoInstead
 
           }
           else 
           {
               RequestNewStock(productlist);//From the test method should be able to call another method like DoInstead
           }
 
             OnClose(); //From the test method should be able to ignore the call
        }
 
        private int PlacetheOrder(List<Product> productlist)
        {
            throw new NotImplementedException();
        }
 
        private void RequestNewStock(List<Product> productlist)
        {
            throw new NotImplementedException();
        }
 
        private void OnClose()
        {
             throw new NotImplementedException();
        }
        private  List<Category> categoriesList;
 
        public  List<Category> CategoriesList
        {
            get { return categoriesList;}
            set { categoriesList = value;}
        }
     
 
 
 
    }
 
    public class Product
    {
    }
 
    public class LogInfo
    {
    }
    public class Category
    {
       private string name;
 
    public string Name
    {
        get { return name;}
        set { name = value;}
    }
     
    }
    public class CategoryType
    {
        private int level;
 
        public int Level
        {
            get { return level; }
            set { level = value; }
        }
         
    }
 
    public class CategoryHelper
    {
       public static List<Category> GetCategories(CategoryType cat)
        {
            throw new NotImplementedException();//This making external call
        }
    }
 
    public interface IProductService : IDisposable
    {
      
     List<Product> ProductsByCategories(LogInfo log,List<Category> CategoriesList);
    }
    public class WCFServicesInstance
    {
 
        public WCFServicesInstance() { }
        public static T GetWCFServiceInstance<T>() where T : class, IDisposable
        {
            T retVal;
                       
            retVal = GetProxyInstance<T>().ProxyContract;
            return retVal;
        }
        public static WCFServiceProxy<T> GetProxyInstance<T>() where T : class
        {
             
            WCFServiceProxy<T> wcfProxy = null;
            #region There is external call that gives the instance
            //External dlll that gives instance of WCFServiceProxy<T>
            #endregion
            return wcfProxy;
        }
    }
    public class WCFServiceProxy<T> : ClientBase<T> where T : class
    {
        public WCFServiceProxy() {}
        public T ProxyContract { get; set; }
    }
}
 
Here are the tried test method.  You can paste it another .cs file

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Business;
using Telerik.JustMock;
namespace JustMockTestProject
{
    [TestClass]
    public class ShopTest
    {
        [TestMethod]
        public void OrderProductsPlaceOrderTest()
        {
            #region Arrange
            var loginfo = Mock.Create<v>();
            CategoryType cat = new CategoryType();
            cat.Level = 3;
           //  Mock.Arrange(() => CategoryHelper.GetCategories(cat)).Returns(cat);
            #endregion
            #region Act
            Shop target = new Shop();
            target.OrderProducts();
            #endregion
            #region Assert
            //Assert that Order is place i.e PlacetheOrder is called(mock version)
 
            #endregion
        }
 
        [TestMethod]
        public void OrderProductsRequestNewStockTest()
        {
            #region Arrange
            #endregion
            #region Act
            Shop target = new Shop();
            target.OrderProducts();
            #endregion
            #region Assert
            //Assert that Product are Requested for the new stock i.e RequestNewStock is called (mock version)
            #endregion
        }
    }
}


Kaloyan
Telerik team
 answered on 15 Feb 2013
4 answers
223 views
If I'm have a class as a parameter to a mocked method, what does JustMock use to determine whether the parameters match or not?

e.g.

public class Bi
{
    protected bool Equals(Bi other)
    {
        return I == other.I;
    }
 
    public override int GetHashCode()
    {
        return I;
    }
 
    public override bool Equals(object obj)
    {
        return base.Equals(obj);
    }
    public int I { get; set; }
}
 
public interface IR
{
    bool Get(Bi bi);
}
 
public class G
{
    private readonly IR _r;
 
    public G(IR r)
    {
        _r = r;
    }
 
    public bool M()
    {
        var bi = new Bi {I = 1};
        return _r.Get(bi);
    }
}
 
[TestFixture]
public class Test
{
    [Test]
    public void Test1()
    {
        var bi = new Bi {I = 1};
        var r = Mock.Create<IR>();
 
        Mock.Arrange(() => r.Get(bi)).Returns(true);
        var g = new G(r);
        var b = g.M();
        Assert.That(b, Is.True);
    }
 
}
No matter what I do, I can't seem to get  the BI parameter to match correctly.
I've tried Equals and a bunch of the interfaces for testing equality and none seem to get called.
Do I need to use the Arg.Matches or should this work and I'm just missing something?
Mihail
Telerik team
 answered on 14 Feb 2013
5 answers
208 views
I installed the JustMock Q3 2012 SP2 trial version.
I am getting the above error. I also attached the stack trace.
Do let me any step i missed while running the sample test cases.

Thanks
Mohd Moyeen
Kaloyan
Telerik team
 answered on 12 Feb 2013
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?