Telerik Forums
JustMock Forum
2 answers
188 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
3 answers
204 views
How do you use this?
Ricky
Telerik team
 answered on 19 Apr 2012
3 answers
227 views
I have setup a Windows 7 x64 machine, with Visual Stuidio 11 Beta and JustMock. When running Unit Tests I get:

Unit Test Adapter threw exception: Could not load file or assembly 'Telerik.CodeWeaver.Hook, Version=1.0.0.0, Culture=neutral, PublicKeyToken=87210992829a189d' or one of its dependencies. The system cannot find the file speccified..

When I disable JustMock, it runs fine (ev. I have the following in Code. Mock.Create(Context)();)
I have started VS in normal Mode and in admin mode, same results...

Any Ideas? Thankx, Harry

Ricky
Telerik team
 answered on 18 Apr 2012
4 answers
142 views
I can get the JustMockRunner to execute the xUnit.net gui test runner (xunit.gui.clr4.exe) without a problem. When I try to get it run the xUnit.net console runner (xunit.console.clr4.exe) it just seems to hang up on the command line requiring Ctrl+C to cancel the run. 

This works:
C:\apps\JustMock\Libraries\JustMockRunner.exe ..\..\..\..\tools\xunit.net\xunit.gui.clr4.exe MyTests.dll

This locks up:
C:\apps\JustMock\Libraries\JustMockRunner.exe ..\..\..\..\tools\xunit.net\xunit.console.clr4.exe MyTests.dll

It also fails with NSpec console runner:
C:\apps\JustMock\Libraries\JustMockRunner.exe ..\..\..\..\tools\nspec\NSpecRunner.exe MyTests_nspec.dll

Any ideas would be appreciated. 
Ricky
Telerik team
 answered on 13 Apr 2012
9 answers
1.1K+ views
HttpContext currentContext = Mock.Create<HttpContext>(Constructor.Mocked);
Ambiguous match found.

 

 

HttpContext currentContext = Mock.Create<HttpContext>();

Object reference not set to an instance of an object.

These are the two errors I am getting. My Question is what is the current way to mock HttpContext constructor.

I am using JustMock Trial Version Q2 2011 (2011.2.713.2)

Thanks

Ricky
Telerik team
 answered on 13 Apr 2012
2 answers
117 views
Environment:
OS: Windows 7 Enterprise 64-bit
IDE: Visual Studio 2010 Premium
JustMocks: "Trial Version Q1 2012 Visual Studio 11 Refresh - Build (2012.1.229.0)"

I have a Enabled JustMock in Visual Studio 2010 and am attempting to run the following test against SharePoints SPWebApplication:
[TestMethod]
[TestCategory("JustMocked")]
public void ValidSPWebApp_SetsEmailAddresses_JustMocked()
{
    var fakeSPWebApp = Mock.Create<SPWebApplication>(Constructor.Mocked);
    Mock.Arrange(() => fakeSPWebApp.OutboundMailServiceInstance.Server.Address).Returns(SmtpHostName);
    Mock.Arrange(() => fakeSPWebApp.OutboundMailSenderAddress).Returns(EmailAddressForSender);
    Mock.Arrange(() => fakeSPWebApp.OutboundMailReplyToAddress).Returns(EmailAddressForReplyTo);
 
    var sut = new SimpleEmailHelper(fakeSPWebApp);
    Assert.AreEqual(EmailAddressForSender, sut.SenderMailAddress.Address);
    Assert.AreEqual(EmailAddressForReplyTo, sut.ReplyToAddress.Address);
}

I get the following exception message:
Telerik.JustMock.MockException: There were some problems intercepting the mock call. Optionally, please make sure that you have turned on JustMock's profiler while mocking concrete members.

When I run it via the xUnit GUI Runner it passes. I use the following command to run xUnit via an external tool in VS:

JustMockRunner.exe xunit.gui.clr4.exe $(BinDir)$(TargetName)$(TargetExt)

and here is the xUnit version of the test:
[Fact]
[Trait("Tag", "JustMocked")]
public void ValidSPWebApp_SetsEmailAddresses_JustMocked()
{
    var fakeSPWebApp = Mock.Create<SPWebApplication>();
    Mock.Arrange(() => fakeSPWebApp.OutboundMailServiceInstance.Server.Address).Returns(SmtpHostName);
    Mock.Arrange(() => fakeSPWebApp.OutboundMailSenderAddress).Returns(EmailAddressForSender);
    Mock.Arrange(() => fakeSPWebApp.OutboundMailReplyToAddress).Returns(EmailAddressForReplyTo);
 
    var sut = new SimpleEmailHelper(fakeSPWebApp);
    Assert.Equal(EmailAddressForSender, sut.SenderMailAddress.Address);
    Assert.Equal(EmailAddressForReplyTo, sut.ReplyToAddress.Address);
}

Any ideas would be appreciated.
Ricky
Telerik team
 answered on 10 Apr 2012
2 answers
97 views
Hi

my tests fail

code to test

 DHP_Document documentObject = ctx.DHP_Document.Single(d => d.DocumentID == document.DocumentID);

documentObject    = null


How I can  mock DHP_Document   which is entity table in database ?

i have mocked  ctx.DHP_Document 
Mock.Arrange(() => CustomerEntities.DHP_Document).ReturnsCollection(CreateDHP_DocumentList());

ari
Top achievements
Rank 1
 answered on 10 Apr 2012
6 answers
182 views
Hi,

We are trying to put together a script using MSBuild to run our unit tests. This uses NUnit as the unit testing engine and JustMock for the mocking framework. We have the 2012 Q1 full release of JustMock, Nunit 2.5.10 and MSBuild 4.0.

When we run the unit tests in Visual Studio 2010 (using Resharper) all the unit tests run without any problem. When we try to run the unit tests via MSBuild we get:
Test Error : Cecil.SharePoint.Foundation.UnitTests.Model.WorkspaceTests.ModelTestBase`1.SaveExisting
   Telerik.JustMock.MockException : There were some problems intercepting the mock call. Optionally, please make sure that you have turned on JustMock's profiler while mocking concrete members.
   at Telerik.JustMock.Expectations.Expectation.ThrowForInvalidCall(IInvocation invocation)
   at Telerik.JustMock.Mock.<>c__DisplayClass1`1.<Arrange>b__0(MockContext`1 x)
   at Telerik.JustMock.MockContext.Setup[TDelgate,TReturn](Instruction instruction, Func`2 function)

We are using the JustMockRunner and the MSBuild targets (JustMockStart & JustMockStop) but the tests are still failing.

What else do we need to do to get the testings running?


Craig
Ricky
Telerik team
 answered on 05 Apr 2012
9 answers
190 views
Hi 

I have some kind of tricky bug..

I have private method which I fake with Mock.NonPublic.Arrange   and it returns "TestValueFoo" string

I debug .. everything goes ok .. this "TestValueFoo "  was added to list in real code..and  which I check in test code later  .. In test code there is no "TestValueFoo "

if I change tested method to public and then I use  Mock.Arrange(...and it returns "TestValueFoo" 
 Then this same code works fine in test method

so there is some kind of problem with private mocking 
Debug show that  "TestValueFoo"  was added to list but when program goes back to test code then there is no "TestValueFoo"  in list anymore 

visual studio 2010  and visual studio unit test

Hopeful you got the idea.. which I was trying to explain


ari
Top achievements
Rank 1
 answered on 04 Apr 2012
1 answer
173 views
Is there a way to assert that a public constructor calls a private method?  As shown below, the PrivateMethod is internal so that the code will compile.  However, the assertion that PrivateMethod is called once fails because it's apparently called before the assertion is made.  Is there a way around this dilemma?  Secondly, I would like the PrivateMethod to be private (as the name suggests).  Is this possible?  THANKS!

[Fact]
void Test() {
    int p = 3;
    var m = Mock.Create<SUT>(p);
    Mock.Arrange(() => m.PrivateMethod(p)).OccursOnce();
    Mock.Assert(m);
}
 
public class SUT {
    public SUT(int p1) { PrivateMethod(p1); }
    internal void PrivateMethod(int p) { }
}
Ricky
Telerik team
 answered on 29 Mar 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?