Telerik Forums
JustMock Forum
9 answers
139 views
I think I have discovered a bug.
    internal class InternalClass
    {
        public int GetInt() { return 5; }
    }
 
    internal class InternalOwner
    {
        public int GetInt() { return 5; }
        public InternalClass InternalClassField = new InternalClass();
 
        public InternalClass InternalClassProp
        {
            get { return InternalClassField; }
        }
    }
 
...
 
    [Test]
    public void Test5()
    {
        InternalOwner io = Mock.Create<InternalOwner>();
//      Mock.Arrange(() => io.GetInt()).Returns(6);     // Test1, works.
//      Mock.Arrange(() => io.InternalClassField.GetInt()).Returns(6);      // Test2, works.
        Mock.Arrange(() => io.InternalClassProp.GetInt()).Returns(6);       // Test3, FAILS.
    }
If you uncomment each of the lines Test1, Test2 and Test3 in turn you'll see that recursively mocking the GetInt() method via InternalClassProp fails.

Adding the InternalsVisibleto assembly attribute has no effect.

Ricky
Telerik team
 answered on 16 May 2012
1 answer
90 views
Hi,

I'm using JustMock Q1 2012 SP1 (2012.1.508.6) and when I try to create a mock of the same type as the one under test most of the test for the type are failing.
 

A simplified example of what I'm doing follows.
var mock = Mock.Create<MyTypeUnderTest>(Constructor.Mocked);
var target = new MyTypeUnderTest ();
target.TestMethod();

The only temporary solution I've found is to create the Mock with Behavior.CallOriginal.

Any solution for this?

Kind Regards,
Edoardo
Ricky
Telerik team
 answered on 15 May 2012
1 answer
113 views
I'm using JustMock Q1 2012 SP1 (2012.1.508.6) and when I try to create a mock of the Thread class, I get an exception.

I tried the following methods:

- var mock = Mock.Create<Thread>.Create(any argument);
- var mock = Mock.Create<Thread>.Create(new Thread(delegate{}));

Both fails whether I use the MockClass attribute or not.

Any suggestion?
Thanks.
Ricky
Telerik team
 answered on 15 May 2012
1 answer
104 views
I'm trying to test a method that simply looks to see if a value exists in a property that contains a list of strings, but the test fails despite the fact that the value is in the list.  Here is some sample code:

Imports System.Text
Imports Telerik.JustMock
 
Public Class User
 
  Public Sub New()
    MyBase.New()
  End Sub
 
  Public Shared Function Create() As User
    Dim returnValue As New User
    returnValue.UID = "TestUser"
    returnValue.Roles.Add("Admin")
    Return returnValue
  End Function
 
  Public Property UID As String
  Public Property Roles As List(Of String)
 
  Public Function IsAdministrator() As Boolean
    Return _roles.Contains("Admin")
  End Function
 
End Class
 
 
<TestClass()>
Public Class Mocking
 
  <TestMethod()>
  Public Sub Works()
    Dim user As User = user.Create
    Assert.IsTrue(user.IsAdministrator)
  End Sub
 
  <TestMethod()>
  Public Sub DoesNotWork()
 
    Dim user As User = Mock.Create(Of User)()
    Dim roles As New List(Of String)
 
    Mock.Arrange(Function() user.UID).Returns("SomeUser")
    roles.Add("Admin")
    Mock.Arrange(Function() user.Roles).Returns(roles)
 
    Assert.AreEqual("SomeUser", user.UID)
    Assert.AreEqual(roles.Count, user.Roles.Count)
    Assert.AreEqual("Admin", user.Roles.Item(0))
    Assert.IsTrue(user.IsAdministrator)
 
  End Sub
 
End Class

 

I'm sure I'm just missing something obvious, so any help is greatly appreciated.
Ricky
Telerik team
 answered on 14 May 2012
1 answer
128 views
Hi..

I have this kind of test situation I need Guid list to be send with ReturnsCollection 


        [TestMethod]       
        public void GetCodedObjectsClients_WithServiceArea()
        {               
            // Arrange
            KAPRole role = CreateDataRole();


            //Create test worker
            OHPClientWorker clientWorker = new OHPClientWorker(Entities);
            Guid MyGuidi = new Guid("ccae2079-2ebc-4200-879d-866fc82e6afa");
            Guid MyGuidi2 = new Guid("ccae2079-3ebc-4200-879d-866fc82e6afa");            
            IEnumerable<Guid> guids = new List<Guid> { MyGuidi, MyGuidi2 };


            // Create mock data
            Mock.Arrange(() => clientWorker.ServiceAreaWorker.GetServiceAreaUserGuids(Arg.IsAny<long>())).ReturnsCollection(guids);



But in code to test the Guid list contains only guids 00000 0000 00000 00000 .... So guid was changed from ccae2079-2ebc-4200-879d-866fc82e6afa"  to 00000 0000 00000 0000  Why

 public ICollection<OHPClientWithCodedObject> GetCodedObjectsClients(ICollection<long> objectIDs, ICollection<KAPRole> roles, long serviceAreaID)
        {          
            //Users with rights granted through servicearea
            ICollection<Guid> userGuids = ServiceAreaWorker.GetServiceAreaUserGuids(serviceAreaID);
............
userGuids  does not contain anymore real Guids


Any Idea why ReturnsCollection  chages Guids


Ricky
Telerik team
 answered on 08 May 2012
1 answer
94 views
We recently had a need to start using Telerik JustMock to go along with the other telerik products we are using. Upon installation and running the sample Mock code we ran into exception setting up Mock classes "Unable to obtain public key for StrongNameKeyPair". We're running on Windows 7 x64. After hunting around in the forums and net for possible solutions, I noticed other Mocking software having similar type problems on Windows 7 x64. It turns out if we open up the security on the "C:\users\all users\microsoft\crypto\rsa" folder (Read &execute / List Folder/ Read/ Write) it resolves the issue.

Is there a better workaround that we could be using, or atleast a change in the installer so the security permissions get updated properly? or better yet, a different solution that I missed?
Ricky
Telerik team
 answered on 07 May 2012
2 answers
97 views
I have an odd case where I have multiple tests running on the same class. For most of these tests I am mocking a method on the class to return controlled results. One of the tests actually uses the normal version of the method. When the test that uses the concrete version of the method call runs first then I am unable to mock the method in the other tests.

Here is some example code depicting my issue:
var first = new MyClass();
var second = new MyClass();
second.DoSomething();
Mock.Arrange(() => first.DoSomething()).Returns(new List<IDataItem>);
first.DoSomething();

In the code above, first will actually call the method rather than using the mock. Is this a bug? It seems like a bug. Is there a work around?
Ricky
Telerik team
 answered on 02 May 2012
1 answer
213 views
I am simply trying to mock an extension method on an Enum and no matter how I set it up I always seem to get a "Object reference not set to an instance of an object." error. Here is my code:

var invalidType = new MyEnum();
Mock.Arrange(() => invalidType.ToType()).Returns((System.Type)
null);

The extension method (ToType) is just a switch statement that maps enum values to Types. I also tried using a mock for the invalidType.
Ricky
Telerik team
 answered on 01 May 2012
1 answer
1.4K+ views
Is it possible to mock out a method with optional parameters? I can't seem to figure out how to do it.
Ricky
Telerik team
 answered on 30 Apr 2012
1 answer
59 views
Hi

I have over 100 tests now but about 10 of them go to error when I run tests in test list editor
but if I run test separately test works fine.

Any idea what makes this.. is testlist editor so bad?

Ricky
Telerik team
 answered on 27 Apr 2012
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?