Telerik Forums
JustMock Forum
1 answer
122 views
Hi,

After migrating from 2010 Q1 to 2011 Q2, I am facing an issue with Mock.Create<T>() :

I Have a default constructor which is declared after an overloaded constructor (in which i have checks for invalid values).
When I use Mock.Create<T>(), the first constructor is called (not the default one). Thus, I Get an exception from my checks that I didn't have before. Instead I Want Mock.Create<T>() use my default constructor for mocking my type.

Here is a code that describe the problem (I am using MsTests) :

public class ClassToMock
{
    public int Member { getset; }
    
    public ClassToMock(int member)
    {
        // Performs some checks
        if (member <= 0)
            throw new ArgumentException("Member must be positive");
 
        Member = member;
    }
 
    public ClassToMock()
    {
 
    }
}
 
public class ClassToMock2
{
    public int Member { getset; }
 
    public ClassToMock2()
    {
 
    }
 
    public ClassToMock2(int member)
    {
        // Performs some checks
        if (member <= 0)
            throw new ArgumentException("Member must be positive");
 
        Member = member;
    }
 }

[TestMethod]
public void TestMethod1()
{
    var classToMock = Mock.Create<ClassToMock>(); => Throws ArgumentException
    Assert.IsNotNull(classToMock);
}
 
[TestMethod]
public void TestMethod2()
{
    var classToMock2 = Mock.Create<ClassToMock2>();
    Assert.IsNotNull(classToMock2);
}
Thanks for your help.

Link for sources : http://www.fileserve.com/file/9MFQj6v/JustMockTestProject1.rar


Ricky
Telerik team
 answered on 21 Sep 2011
1 answer
217 views
Hi, 
I am trying to configure my build server with JustMock (Trial Version 2011.2.713). I am using TFS 2010.  

  1. I installed JustMock on the build server.
  2. I followed the steps to have my BuildTemplate.xaml modify the environment variables described in this post.


I get the following error:
Unit Test Adapter threw exception: 
Type 'Telerik.JustMock.MockException' in assembly 'Telerik.JustMock, Version=2011.2.713.2, Culture=neutral, PublicKeyToken=8b221631f7271365' is not marked as serializable..

I also get a warning:
Warning: Test Run deployment issue: The assembly or module 'Telerik.CodeWeaver.Hook' directly or indirectly referenced by the test container 'd:\builds\agents\internal\3\myapp\myapp_main_ci\binaries\myapp.test.dll' was not found.

Thanks for your help.
Ricky
Telerik team
 answered on 20 Sep 2011
3 answers
612 views
Hello,

I just encounter a problem when I run multiple tests. Tests run successfully when run indiviually but fail when run in batch.

I am re-mocking the same objects in each tests and I noticed that one of the created mock is using the same proxy key as a previous test !

Do I have to "clear" something between each test ? How ?

Thanks,

Michel
Ricky
Telerik team
 answered on 14 Sep 2011
1 answer
48 views
Can we, at some point in the near future, expect to see Help Viewer compatible help installed locally when installing JustMock?

-- 
Stuart
Ricky
Telerik team
 answered on 12 Sep 2011
3 answers
261 views

I am just starting with JustMock and have a question related to your example in documentation on this page:

    http://www.telerik.com/help/justmock/basic-usage-mock-internal-types-via-proxy.html

I have classes similar to this sample ( internal is not important here it could be public ):

internal class FooInternal
{
    internal FooInternal()
    {
        builder = new StringBuilder();
    }
      
    public StringBuilder Builder
    {
        get
        {
            return builder;
        }
    }
      
    private StringBuilder builder; 
}

What I would like to do is to get my class (FooInternal in this case) to instanciate a Mock of another class (StringBuilder here)...

The only way I can see this possible is by mocking the (FooInternal) constructor itself. Is this possible ?

Thanks !


Ricky
Telerik team
 answered on 09 Sep 2011
1 answer
90 views
Hello,

I downloaded your trial version to mock Entity Framework. Our model contains Function Imports (Stored Procedures) that return an generic object called ObjectResul. This object is a sealed with a internal constructor that contains internal objects as paramters. When I try to Mock this object I get using the folloing line of code :

var tmock = Mock.Create<ObjectResult<GetMedicationPlural_Result>>();

I get the following error:

Constructor on type 'System.Data.Objects.ObjectResult`1[[Mdrx.Note.Data.GetMedicationPlural_Result, NoteServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' not found.

Any suggestions ?

Thanks
Ricky
Telerik team
 answered on 05 Sep 2011
5 answers
830 views
Hi Telerik Team,

I have some couple of doubts in Telerik JustMock Trial Edition which i am trying to do sample project in order to startwith.Based on the success we will go for integration with bigger entity framework projects.



1.  Brief description of my tiny sample project:-  Here GetProjectsTest(), connects to database and returns the number of projects in the form of generic List and then i compared with existing project instance 'tom' which is then added to generic list. Suppose both hard coded value and the other which i get from database are equal then the result is passed.

My aim is to check whether i am able to work with project even when the database service is not available.


//sample code

using TestProject1; - This is the project where i am having all my classes.


 [TestMethod()]
        public void GetProjectsTest()
        {
            
           // Assert.IsFalse(Mock.IsProfilerEnabled);
            //Arrange
            Project tom = new Project() { ProjectID = 1, ProjectName = "iris" };

            List<Project> lstpers = new List<Project>();

            lstpers.Add(tom);

            //Mock.SetupStatic<ProjectManager>(Behavior.Strict);
            Mock.Arrange(() => ProjectManager.GetProjects()).Returns(lstpers);

            //Act + Assert
            Assert.AreEqual(ProjectManager.GetProjects(), lstpers);
        }



when i try to debug the above code , it throws the following errors:-

Locating source for 'c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs'. (No checksum.)
The file 'c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs' does not exist.
Looking in script documents for 'c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs'...
Looking in the projects for 'c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs'.
The file was not found in a project.
Looking in directory 'E:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\'...
Looking in directory 'E:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'...
Looking in directory 'E:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\'...
Looking in directory 'E:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs.
The debugger could not locate the source file 'c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs'.


2. Please explain step by step , so that i could understand what happens when i debug my code , when JustMock is disabled in Telerik Menu of Visual studio2010,

With Great Expectation
Ulaga
Ricky
Telerik team
 answered on 01 Sep 2011
3 answers
120 views
I am trying to determine if a method exists and then test if that method has been called. The only interface that is available to the test project in the below example code is I1.

public interface I1 { }
public interface I2 : I1
{
    void Test();
}
My test code looks like this
[TestMethod()]
public void MyClassConstructorTest()
{
    this.Test<I2>();
}
 
public void Test<T>() where T : I1
{
    T t = Mock.Create<T>();
    bool called = false;
    Mock.NonPublic.Arrange(t, "Test").DoInstead(() => called = true);
}

This throws this error: "Could not resolve the target method; make sure that you have provided arguments correctly.". I have put this code into the function to make sure that Mock.Create creates the appropriate proxy.
MethodInfo method = t.GetType().GetMethod("Test");
MethodInfo is never null so that tells me that a valid proxy has been created.

My question is: Am I going about this the wrong way? How can I tell if a method that the test only knows by name and not by interface has actually been called?

Thank you for your help.
Ricky
Telerik team
 answered on 30 Aug 2011
6 answers
382 views
Here is a sample I am working with. My repository works with a LINQ data context against SQL Server 2008. I  would like to assert that my repository works without actually adding records to the database. I am not sure I am doing the correctly. I would like to write tests for my Add, Edit, Delete, and List functions. This is about as simple as it gets for repo's. Can you give me a hand figuring this out?

I have interfaces and classes for my problem domain; and interfaces and classes for my repositories. What must I do to mock my repositories for testing?

    [TestFixture] 
    class TextHTMLRepositoryTests 
    { 
        TextHTMLRepository _repo; 
 
        [TestFixtureSetUp] 
        public void TestSetup() 
        { 
            _repo = Mock.Create<TextHTMLRepository>(); 
        } 
 
        [Test] 
        public void CreateMockRepo() 
        { 
            Assert.IsNotNull(_repo); 
        } 
 
        [Test] 
        public void NullListTest() 
        { 
            var _texts = _repo.List(); 
            Assert.IsNull(_texts); 
        } 
 
        [Test] 
        public void PostTest() // This test fails 
        { 
            TextHTML _text = Mock.Create<TextHTML>(); 
            _text.TextID = 1; 
            Mock.Assert(() => _repo.Post(_text)); 
        } 
 
        [TestFixtureTearDown] 
        public void TestTearDown() 
        { 
            // TODO: Tear down loose objects 
        } 
    } 

Thanks,

John


Ricky
Telerik team
 answered on 26 Aug 2011
5 answers
109 views
Hi,

When trying to run tests with TestDriven.Net i get the following exception:

 An error occured executing PopulateHolidays method. ---> Telerik.JustMock.MockException: Exception has been thrown by the target of an invocation.
at .ƒ.( expecation, Object[] userArgs)
at .ƒ.–( invocation)
at ..( invocation)
at ..( invocation)
at ..Intercept(MockInvocation invocation)
at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.€(IInvocation invocation)
at PersistenceManager_Interceptor_63dc8f881d054338ad4e199360304e8a.Intercept(PersistenceManager , Boolean& )
 at PersistenceManager.GetCalendarData()

Though when running it with MSTest runner the breakpoint stops correctly on my function.

The code of the test is something like this:
Mock.Arrange(() => PersistenceManager.GetCalendarData()).Returns(() => myDataSet());

Where GetCalendarData is the static method being mocked.

Any idea why this is happening?

Ricky
Telerik team
 answered on 18 Aug 2011
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?