I've been using RhinoMocks lately but I keep running into an issue. If I break into the debugger and step over code while a mock is in Record mode, I end up getting an exception along the lines of:
System.InvalidOperationException: Previous method 'SuchAndSuch.ToString();'
requires a return value or an exception to throw.
But if I ...
Hi,
I'm trying to create a mock HttpContextBase for unit test.
var fakePrinciple = new GenericPrincipal(
new GenericIdentity(userId),
rolesList.ToArray());
var mockHttpContext = new Mock<HttpContextBase>();
mockHttpContext.Setup(t => t.User).Returns(fakePrinciple);
HttpContextBase mockedContext = mock...
Hello,
We are looking to make a final decision on our Mocking framework. After trying several, I have fallen in love with Moq. I also love TypeMock - but because we are in the early stages of implementing TDD across the team, we do not want to make such a large investment quite yet. We are using VS 2008 now and are going to move to 2010...
I have a constructor which has a non-interface dependency:
public MainWindowViewModel(IWorkItemProvider workItemProvider, WeekNavigatorViewModel weekNavigator)
I am using the Moq.Contrib automockcontainer. If I try to automock the MainWindowViewModel class, I get an error due to the WeekNavigatorViewModel dependency.
Are there any a...
Hello,
How can I do this in Moq?
Foo bar = new Foo();
Fake(bar.PrivateGetter).Return('whatever value')
It seems I can only find how to mock an object that was created via the framework. I want to mock just a single method/property on a concrete object I've created...
In TypeMock, I would just do Isolate.WhenCalled(bar.PrivateGetter...
I'm brand new to Moq (using v 4) and am struggling a little with the documentation.
What I'm trying to do is to Moq a method that takes a byte array and returns an object. Something like:
decoderMock.Setup(d => d.Decode(????).Returns(() => tagMock.Object);
The ???? is where the byte[] should be, but I can't work out how to make it so...
Can somebody please suggest how I could write a Unit Test with Moq for following HtmlHelper method?
public static HtmlTagBase GenerateTag<T>(this HtmlHelper htmlHelper
, object elementData
, object attributes)
where T : HtmlTagBase
{
return (T)Activator.Creat...
I think I may be a bit confused on the syntax of the Moq Callback methods. When I try to do something like this:
IFilter filter = new Filter();
List<IFoo> objects = new List<IFoo> { new Foo(), new Foo() };
IQueryable myFilteredFoos = null;
mockObject.Setup(m => m.GetByFilter(It.IsAny<IFilter>())).Callback( (IFilter filter) => myFilte...
Could somebody show me how you would go about creating a mock HTML Helper with Moq?
This article has a link to an article claiming to describe this, but following the link only returns an ASP.NET Runtime Error
[edit]
I asked a more specific question related to the same subject here, but it hasn't gotten any responses. I figured it was ...
I'm doing some maintenance on an older web application written in Monorail v1.0.3. I want to unit test an action that uses RenderText(). How do I extract the content in my test? Reading from controller.Response.OutputStream doesn't work, since the response stream is either not setup properly in PrepareController(), or is closed in Ren...
I have a problem with VB9 and Moq.
I need to call a verify on a Sub. Like so:
logger.Verify(Function(x) x.Log, Times.AtLeastOnce)
And my logger looks like this:
Public Interface ILogger
Sub Log()
End Interface
But with VB this is not possible, because the Log method is a Sub, and thereby does not produce a value.
I don't want...
I have a class that roughly looks like this:
public class ViewModel
{
public ViewModel(IWebService service)
{
this.WebService = service;
}
private IWebService WebService{get;set;}
private IEnumerable<SomeData> MyData{get;set;}
private void GetReferenceData()
{
this.WebService.BeginGetStaticReferenceData(GetRefe...
I have a function I want to Moq. The problem is that it takes 5 parameters. The framework only contains Action<T1,T2,T3,T4> and Moq's generic CallBack() only overloads Action and the four generic versions. Is there an elegant workaround for this?
This is what I want to do:
public class Filter : IFilter
{
public int Filter(...
Moq allows developers to mock protected members. I was looking for the same functionality in Rhino.Mocks but fail to find it.
Here's an example from Moq Quick Start page how to mock protected method.
// at the top of the test fixture
using Moq.Protected()
// in the test
var mock = new Mock<CommandBase>();
mock.Protected()
.Setup...
Following is the code. create a class lib add the ref to NUnit framework 2.5.3.9345 and Moq.dll 4.0.0.0 and paste the following code. Try running it on my machine it throws
TestCase
'MoqTest.TryClassTest.IsMessageNotNull'
failed: Moq.MockException : Expected
invocation on the mock at least once,
but was never performed: v =...
I'm only new to Unit Testing and ASP.NET MVC. I've been trying to get my head into both using Steve Sanderson's "Pro ASP.NET MVC Framework". In the book there is this piece of code:
public class AdminController : Controller
{
...
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Product product, HttpPostedFileBase image)
...
I am trying to test that a property has been set but when I write this as a unit test:
moqFeed.VerifySet(Function(m) m.RowAdded = "Row Added")
moq complains that "Expression is not a property setter invocation"
My complete code is
Imports Gallio.Framework
Imports MbUnit.Framework
Imports Moq
<TestFixture()> Public Class GUI_FeedPre...
Given the following interface
public interface ISomething {
void DoMany(string[] strs);
void DoManyRef(ref string[] strs);
}
I would like to verify that the DoManyRef method is called, and passed any string array as the strs parameter. The following test fails:
public void CanVerifyMethodsWithArrayRefParameter() {
var a = new M...
Using Moq for generation of Stubs and Mocks in my unit tests, I have a case where I want to Verify that a method that takes a Delegate parameter is called. I don't care about the particular Delegate parameter supplied I just want to make sure that the method is in fact called. The method looks like this:
public interface IInvokerProxy{
...
I want to use Ninject to use in a non MVC ASP.NET 3.5 web application.
Can someone write please what do I need to download from ninject home site and what steps I need to take (what ddls I need to reference etc.)? I also want to use Moq objects.
...