Telerik Forums
JustMock Forum
7 answers
294 views
All tests run fine when my Test Settings are set to Local.testsettings.  But when I switched to using CodeCoverage.runsettings (so I can configure my code coverage settings), I get the "profiler is not enabled" error message.

I am using the default runsettings example file found here: http://msdn.microsoft.com/en-us/library/jj635153.aspx

Q: Is is possible to use JustMock profiler with runsettings?

Visual Studio Premium 2012.
Kaloyan
Telerik team
 answered on 05 Jun 2013
1 answer
128 views
HI,
I too need have the need of running the unit test case from msbuild using mstest in TFS. We want to use mstest specifically in the TFS 2010. So JustMock ruuner. My test case running perfectly fine from Visual 2010 by enabling profiler on from the Telerik menu in visual studion 2010.

Can you help me to get the step of configuring the  existing TFS build definition so that profiler is enabled. As of now the error is profiler need to enabled.

Thanks
Mohd Moyeen
mohd.moyeen@allscripts.com

Kaloyan
Telerik team
 answered on 05 Jun 2013
1 answer
123 views

Hi,

I want to mock the StreamReader constructor below so the unit test can pass that statement without failing. All the samples of mocking mscorlib relies on mocking a method, but I want to mock the constructor, how do I do that?

I don't want to create a valid file and pass a valid pathToFile.

We are currently using version 2013.1.507, please provide a sample that works on this version.

Thanks,
Gustavo

public class MyClass
{
   public static string DoSomething(string pathToFile)
 
   {
 
       TextReader xmlTextReader = new StreamReader(pathToFile);
 
       //some method logic
 
      //returns a string
 
   }
 
}
Kaloyan
Telerik team
 answered on 05 Jun 2013
7 answers
77 views
Hello everybody,
I face to such a problem that that raged in my head. So I need your help to solve it.
I've a user control and a method CalculatePreviewArea like that:
public partial class Control_Inside : UserControl
{
//some properties...  
//(private) method1()
//(private) method2()
 private void CalculatePreviewArea(out double width, out double height)
        {
          
           //some logic here...         
           //FillArea is dependency property of User Control
            width = FillArea.Width;
            height =FillArea.Height;
             
            double Sys_Width =  SystemParameters.WorkArea.Width;
            double Sys_Height = SystemParameters.WorkArea.Height;
            Window window = Application.Current.MainWindow;
            Point location_From_Screen = window.PointToScreen(new Point(0.0, 0.0));
             
 
            if (location_From_Screen.X + width - Fill_Area.X >= Sys_Width)
                width =Sys_Width + (location_From_Screen.X - Fill_Area.X);
             
            //....
           }
Now I've to unit test for this method (CalculatePreviewArea) using JustMock. I created a mock user control , I also set FillArea value successfull, but there is no way to access Application.Current.Windows. When I debug the test,it always return null. I need your helps to test this, thanks.
Kaloyan
Telerik team
 answered on 31 May 2013
3 answers
176 views
Hi,

I'd like to mock internal class in test project. I added InternalsVisibleToAttribute to JustMock and my test assembly, but in Silverlight I'm getting this error: TypeLoadException: Access is denied: 'Xtd.SomeClass`2+SomeSubClass[Xtd.Period,Xtd.Container]'.
w System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
w System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
w System.Reflection.Emit.TypeBuilder.CreateType()
w Telerik.JustMock.DynamicProxy.TypeEmitter.CreateType()
w Telerik.JustMock.DynamicProxy.Proxy.CreateType()
w Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
w Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
w Telerik.JustMock.DynamicProxy.Proxy.Create(Type target, Action`1 action)
w Telerik.JustMock.MockManager.CreateProxy(Type targetType, Container container)
w Telerik.JustMock.MockManager.CreateInstance(Container container)
w Telerik.JustMock.MockManager.SetupMock(Behavior behavior, Boolean static)
w Telerik.JustMock.MockManager.CreateInstance()
w Telerik.JustMock.Mock.Create(Type target, Behavior behavior, Object[] args)
w Telerik.JustMock.Mock.Create[T](Behavior behavior, Object[] args)
w Xtd.Tests.SomeClassTests.Initialize()

Everything works in WPF, but in silverlight no.

This is code which fails under Silverlight:
Mock.Create<SomeClass<Period, Container>.SomeSubClass>(Telerik.JustMock.Behavior.CallOriginal);

I'm using JusMock 2012.3.1016.3.
Kaloyan
Telerik team
 answered on 31 May 2013
3 answers
120 views
Hi, how do I mock the examble below?

I want o mock the Datetime method that is called inside the class.

Also, how to mock mscorlib methods for the whole class and not for a particular method?

Thanks,
Gustavo
public static class MyStaticClass
{
     public static string MyStaticMethod()
     {
          return Datetime.Now.ToString() + "anotherRandomString";
     }
}
Kaloyan
Telerik team
 answered on 29 May 2013
3 answers
136 views
Hi All,
I hope you can help me with this. I am using a full version of JustMock and am attempting to mock a large class with multiple dependencies. Automocking seemed to be the way to go for this (unit) test. So I referenced the Telerik.JustMock.Container dll in my project, added the proper using statement and wrote the following simple test:

public void TestAutoMock()
{
// Arrange

var autoMockMFContainer = new MockingContainer<MyCustomClass>();

autoMockMFContainer.Instance.EstablishMyEmployee(10000, 2, 100007, 2, true, false);
}

This seems simple enough but it fails with a NullReferenceException. "Instance" is null. I am new to JustMock so I suspect the problem may lie with the project references or some configuration item but I don't know what it is. 

Can anyone offer any suggestions as to how I might get the Instance to not be null?

Thanks
MM
Kaloyan
Telerik team
 answered on 29 May 2013
3 answers
310 views
Hi,

I have a unit test where I assert that a certain action will call a method on a mock dependency object by using Mock.Assert().  I want to ensure that the action I take calls the method on the mock object exactly once.  The problem is that the setup of the unit test creates a scenario where the method of the mock object will also be called, so when I assert that the call to the mock object happened just once it fails because it has actually been called more than once.

Is there a way to "reset" the call tracking of methods on mock objects?  I basically want to tell JustMock that at a certain point, whatever calls have happened to my mock objects should be discarded and the call counter should basically start at 0 again.

Am I missing something in the framework or is there another way I should do this?

Jerrie
Kaloyan
Telerik team
 answered on 29 May 2013
3 answers
155 views
HI,

I tried to create mock of difficult custom type, but I always have an exception like
System.TypeLoadException: System.TypeLoadException: Method 'UnloadRecursive' on type 'BaseProxy+...' 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..

I tried to use attribute InternalsVisibleTo like <Assembly: InternalsVisibleTo("Telerik.JustMock.Dynamic")> but it didn't solve the problem. I tried to create mock of parent types, all fine. I tried to use MockingContainer, but this no matter, because our type haven't external dependencies. I can't to find where the problem.

What you can to suggest me?


Thanks
Kaloyan
Telerik team
 answered on 28 May 2013
12 answers
551 views
Hi,

I'm currently using the trial of JustMock to write some demo tests for our code. We are using Sitecore CMS and it uses a lot of static properties.

I have this very simple class I want to use for some testing and I have mocked the static property Item on the Context like so:

public class when_accessing_the_context_item_it_should_return_the_name
    {
        static string _result;

        Establish context = () =>
            {
                Mock.SetupStatic(typeof(Sitecore.Context), StaticConstructor.Mocked);

                var mockItem = Mock.Create<Item>();
                Mock.Arrange(() => mockItem.Name).Returns("thename");
                Mock.Arrange(() => Sitecore.Context.Item).Returns(mockItem);
            };

        Because of = () =>
        {
            _result = new MyRendering().Render();
        };

        It should_return_the_name_of_the_item = () =>
        {
            _result.ShouldEqual("thename");
        };


    }

    public class MyRendering
    {
        public string Render()
        {
            return Sitecore.Context.Item.Name;
        }
    }

However when running the test I get an exception:

System.ArgumentNullException: Value cannot be null.
Parameter name: itemID
   at Telerik.JustMock.DynamicProxy.ProxyFactory.CreateInstance(Type type, Object[] extArgs)
   at Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
   at Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
   at Telerik.JustMock.DynamicProxy.Proxy.Create(Type type, Action`1 action)
   at Telerik.JustMock.MockManager.CreateProxy(Type targetType, Container container)
   at Telerik.JustMock.MockManager.CreateMock(Container& container)
   at Telerik.JustMock.MockManager.SetupMock(Behavior behavior, Boolean isStaticType)
   at Telerik.JustMock.MockManager.CreateInstance()
   at Telerik.JustMock.Mock.Create(Type target, Behavior behavior, Object[] args)
   at Telerik.JustMock.Mock.Create(Type target, Object[] args)
   at Telerik.JustMock.Mock.Create[T]()
   at Demo.Tests.When_accessing_the_context_item_it_should_return_the_name.<.ctor>b__0() in 

Why am I seeing this exception, am I doing something wrong?
Kaloyan
Telerik team
 answered on 28 May 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?