Telerik Forums
JustMock Forum
1 answer
101 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
91 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
119 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
89 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
90 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
203 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
56 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
10 answers
789 views
hi

Test CODE:
I have to make 3 different mock to same DeleteObject ()  method

1M       Mock.Arrange(() => CustomerEntities.DeleteObject(Arg.IsAny<DHP_History>())).DoInstead(......
2M.      Mock.Arrange(() => CustomerEntities.DeleteObject(Arg.IsAny<DHP_Document>())).DoInstead ......
3M.      Mock.Arrange(() => CustomerEntities.DeleteObject(Arg.IsAny<DHP_File>())).DoInstead((......

but  only last row comes mocked (3.)  . overriding not work in this case ... Why??  
AND how to mock this kind of situation?


Code to test: ( they are in same function )
so tests fail in row 1.. because it is mocked to  3M  .. WHY ?  it should be 1M
1.  ctx.DHP_Document.Where(d => childDocumentIDs.Contains(d.DocumentID)).ToList().ForEach(ch => ctx.DeleteObject(ch));
2.  ctx.DHP_Document.Where(d => unAttachmentDocumentIDs.Contains(d.DocumentID)).ToList().ForEach(ch => ctx.DeleteObject(ch));
3.  ctx.DHP_File.Where(f => unAttachmentFileIDs.Contains(f.FileID)).ToList().ForEach(ch => ctx.DeleteObject(ch));
Ricky
Telerik team
 answered on 27 Apr 2012
2 answers
183 views
Hello together

It seems that mocking the SPUser object out of the SharePoint 2010 assemblies is not working. I'm just calling the following line:

SPUser currentUser = Mock.Create<SPUser>();

Which leads to the following error in my test initialization method:

Initialization method XX.Presentation.Tests.LicensedPatents.AssociatedPatentsPresenterTests.InitalizeTest threw exception. System.MissingMethodException: System.MissingMethodException: Constructor on type 'System.Object[,]' not found..

Here is the call stack which refers to line 88 (the one posted above):

at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Telerik.JustMock.Utility.GetDefaultValue(Type target)
at Telerik.JustMock.Utility.ProcessArgument(Type target, BindingFlags flags, Object[] args)
at Telerik.JustMock.Utility.GetArgumentsWithDefaultValue(Type target)
at Telerik.JustMock.Utility.GetExtentedArguments(Type target, Object[] args)
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()
at XX.Presentation.Tests.LicensedPatents.AssociatedPatentsPresenterTests.InitalizeTest() in AssociatedPatentsPresenterTests.cs: line 88

It would be nice to be able to mock the SPUser object. Thanks for any help!

Regards
Andreas

Andreas
Top achievements
Rank 1
 answered on 24 Apr 2012
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?