Telerik Forums
JustMock Forum
1 answer
73 views

 Mock.NonPublic.Arrange<int>(mockedClass, "_prop").Returns(5);

Works as long as my private variable is setup like so:

private int _prop {get; set;}

However these:

private int _prop; 

or 

private int _prop = 5;

get an error attempting to read it. 

 

 

Thanks in advance, 

Mark 

 

Mark
Top achievements
Rank 1
 answered on 30 Apr 2015
4 answers
293 views
As mentioned, i wanted to download older version justmock, and i couldn't found it ..... 
Shane
Top achievements
Rank 1
 answered on 27 Apr 2015
8 answers
113 views
Suppose I have a class MyClass, with a method MyMethod(), and I have a method under test which looks something like:
MethodUnderTest(MyClass myClass)
{
    myClass.MyMethod();
    // Do some other stuff
    myClass.MyMethod();
}


I would like to be able to write the test for this looking something like:
[TestMethod]
public void MyTest()
{
    MyClass mockMyClass = Mock.Create<MyClass>(Behaviour.Strict);
    mockMyClass.Arrange(x=>x.MyMethod());
    // Arrange the other stuff
    mockMyClass.Arrange(x=>x.MyMethod());
 
    MethodUnderTest(mockMyClass);
     mockMyClass.AssertAll();
}


Of course I cannot do this, as the second Arrange simply replaces the first. I have to do:
[TestMethod]
public void MyTest()
{
    MyClass mockMyClass = Mock.Create<MyClass>(Behaviour.Strict);
    mockMyClass.Arrange(x=>x.MyMethod(), 2);
    // Arrange the other stuff
 
    MethodUnderTest(mockMyClass);
     mockMyClass.AssertAll();
}


which is OK, but the first pattern is a better reflection of the structure of the test and the method being tested, and is thus more readable.

Is there a syntax which allows me to say "arrange another call to this method" and so looks more like the first test and less like the second?

Dave
Stefan
Telerik team
 answered on 01 Apr 2015
5 answers
159 views
I am trying to setup a continuous integration process on our TFS server using the gated check-in method.  We have a number of existing tests which are using JustMock, so when we first tried to do this we received errors on the build that the profiler could not be started.  To remedy this I have been trying to follow the instructions at this link: http://www.telerik.com/help/justmock/integration-code-activity-workflow.html.  I have gotten to Step 2 and run into errors.  First when I tried to add the JustMock build workflow DLL to the custom toolbox I received an error stating that a dependant DLL could not be found.  One of our IT people found the missing DLL (Microsoft.TeamFoundation.Build.Client.dll) and by placing that in the same folder as the workflow DLL I was able to add the workflow DLL to the toolbox; however, when I attempted to drag the JustMock TestRunner tool into the workflow I received an error similar to the one I had gotten prior to adding the MS DLL to the folder, so I assumed I needed to add that DLL to the toolbox as well.  Adding the MS build client DLL threw an error stating that a reference could not be resolved and indicating that the reference was to a MS source control DLL.  I tried dragging the JustMock TestRunner onto the template again, and now I just have a red bar in the workflow stating "Could not generate view for JustMockTestRunner".

Does anyone have any suggestions for how to solve this issue?

TIA
Ron L.
Ron
Top achievements
Rank 1
 answered on 31 Mar 2015
4 answers
184 views
I've lately started receiving errors from my test runs stating (I think) that I need to upgrade the version of the profiler running on my build server. This is following an update I make to the JustMock version I use in my test projects (version details are in the below error message).

1) Test Error : CustomerExperience.Domain.Test.Integration.MailMergeTest.DateFormattingIsSuccessful
Telerik.JustMock.Core.MockException : Telerik.JustMock.dll version: 2015.1.224.3
Telerik.CodeWeaver.Profiler.dll version: 2014.3.1021.2
Register the updated Telerik.CodeWeaver.Profiler.dll.
at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
at Telerik.JustMock.Core.Context.MockingContext.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
at Telerik.JustMock.Mock.<Create>b__92[T]()
at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
at CustomerExperience.Domain.Test.Integration.MailMergeTest.DateFormattingIsSuccessful() in d:\Program Files (x86)\Jenkins\jobs\Customer Experience\workspace\source\CustomerExperience.Domain.Test\Integration\MailMergeTest.cs:line 50

I could just go ahead and update the profiler on the build server. The issue is that the same server runs tests for several other projects which haven't been updated in the same way that mine has.

Can anyone suggest a fix?
Stefan
Telerik team
 answered on 13 Mar 2015
2 answers
174 views
Hi,
  I am facing trouble, while Arranging value of a variable inside a Private Method. Below is a sample code snippet for the scenario that i am working on, which has a Private static method. In method "SomeMethod", i want to arrange the call "someObject.MethodReturnsTrueOrFalse(someValue)".
  Can anybody give me resolution on the same?

public class SomeClass
{
   
 private static void SomeMethod()
 {
int someValue = 10;
Foo someObject = new Foo();
        var result = someObject.MethodReturnsTrueOrFalse(someValue);
        if(result)
{
//do some operation
}
 }
}
Thanks In advance :)

Sagar





Sagar
Top achievements
Rank 1
 answered on 05 Mar 2015
5 answers
959 views
Dear sir,
I am a big fan of telerik control. Recently I have convinced my boss to use use JustMock for my current project. Everything was running smooth and our company was totally impressed with it until I stuck in a problem. I have tried my level best to solve it but can't find a suitable solution. My colleague, Google, Stackoverflow everything failed to satisfy me, so finding no way I came to you with the hope that you would rescue me from this unsolvable problem. I have included my code here, please have a look on it.

Problem : Unable to Mock DbSet 

we are test this Repository but don`t understand How to do it. 

 public class BaseRepository<T> : IRepositoryBase<T> where T : class, IEntity, new()
    {
        protected readonly DbContext DbContext;
        protected DbSet<T> DbSet;

        public BaseRepository(DbContext dbContext)
        {
            DbContext = dbContext;
            DbSet = DbContext.Set<T>();
        }

        public void Add(T entity)
        {
            DbSet.Add(entity);
        }
}

we are tried following code but we are failed.
 
 public class BaseRepositoryTest
    {
        readonly TimeSketchContext _mockDataContext = Mock.Create<TimeSketchContext>();
        private readonly BaseRepository<EmployeeSkill> _repository;
        public BaseRepositoryTest()
        {
            Mock.Arrange(() => _mockDataContext.EmployeeSkill).ReturnsCollection(GetEmployeeSkills());
            _repository = new BaseRepository<EmployeeSkill>(_mockDataContext);
        }

        [Fact]
        public void Add()
        {
            var employeeSkill = GetEmployeeSkill();
            _repository.Add(employeeSkill);
            _mockDataContext.SaveChanges();
            var allSkill = _repository.All();
            Assert.Equal(2, allSkill.Count()); //we are get 0 item here and out test is failed.
        }

        [Fact]
        public void Get_All_Test()
        {
            var allSkill = _repository.All();
            Assert.Equal(1, allSkill.Count()); //we are get 0 item here and out test is failed.

        }


        #region Private Methods
        private EmployeeSkill GetEmployeeSkill()
        {
            return new EmployeeSkill
            {
                SkillDescription = "aa",
                SkillName = "bbbb",
                Id = 1
            };
        }

        private IEnumerable<EmployeeSkill> GetEmployeeSkills()
        {
            return new List<EmployeeSkill>
            {
                GetEmployeeSkill()
            };
        }

        #endregion
    }
if any books on it please refer.
Zdravko
Telerik team
 answered on 05 Mar 2015
2 answers
88 views
My Company has just bought DevCraft licences for 6 Devs.

We all have machines that are set up in slightly different ways.

I want to ensure that the Project we are working on will work for any dev, regardless of the location of the installed files on his/her machine.

For a number of other products this has simply meant copying the appropriate DLLs to a shared /bin folder created as a Solution Folder and ensuring that the references in any appropriate product points there.

Can someone tell me how much of the ~JustMock/Libraries/ folder I have to copy to my /Bin folder please?
Stuart Hemming
Top achievements
Rank 2
 answered on 05 Mar 2015
2 answers
91 views
Hello, I grabbed this example from docs and added virtual modifier to ReturnFive function because free version can't mock not virtual members.
As far as I understand this modification shouldn't influence test results, though this test fails with  "Expected: 7  But was:  5"
I can't find any explicit statement in docs about future mock feature support in free version, so I'm not sure if it's my fault or this feature is just not available.
Any help would be appreciated.
       
public class UserData
        {
            public virtual int ReturnFive()
            {
                return 5;
            }
        }
        [Test]
        public void ShouldArrangeReturnForFutureUserDataInstances()
        {
            // Arrange
            var fakeUsed = Mock.Create<UserData>();
            Mock.Arrange(() => fakeUsed.ReturnFive()).IgnoreInstance().Returns(7);

            // Assert
            Assert.AreEqual(7, fakeUsed.ReturnFive());
            Assert.AreEqual(7, new UserData().ReturnFive());
        }
vsevolod
Top achievements
Rank 1
 answered on 04 Mar 2015
13 answers
6.4K+ views

It's quite common that we will try to customise a Framework class but still reuse most of the logic from the base class. For example, we want to provide our own Navigation Provider inheriting from Microsoft.SharePoint.Navigation.SPNavigationProvider. And we want to override GetChildNodes class to add some addition site map node on top of the collection that base class return. So we will be calling base.GetChildNodes() from our GetChildNodes method.

Here is a simple example. The problem is I dont know how to reference the base class method in the Mock.Arrange method?

public class ParentClass
{
    public virtual int Sum()
    {
        return 0;
    }
}
public class ChildClass : ParentClass
{
    public override int Sum()
    {
        return 1 + base.Sum();
    }
}
[TestMethod]
public void RunChildClass()
{
    var childClass = new ChildClass();
    Mock.Arrange(() => childClass.Sum()).Returns(2); // want to override ParentClass.Sum(), not ChildClass.Sum().
    var result = childClass.Sum();
    Assert.IsTrue(result == 3); // instead I will get 2 here.
}
Stefan
Telerik team
 answered on 04 Mar 2015
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?