I am trying to mock the Ajax.IsRequest() method of ASP.Net MVC. I found out how to do it in order for it to return true:
Expect.Call(_myController.Request.Headers["X-Requested-With"]).Return("XMLHttpRequest").Repeat.Any();
This works and returns true. Now I need to test the other branch of the code. How can I mock it to return false? ...
My dynamic mock behaves as Parial mock, meaning it executes the actual code when called. Here are the ways I tried it
var mockProposal = _mockRepository.DynamicMock<BidProposal>();
SetupResult.For(mockProposal.CreateMarketingPlan(null, null, null)).IgnoreArguments().Repeat.Once().Return(
copyPlan);
//Expec...
var mocks = new MockRepository();
var access = new Access();
access.ShowRepository = _mocks.Stub<IShowRepository>();
access.ShowRepository.Stub(x => x.GetShows()).Return(new List<Show>());
var kernel =_mocks.Stub<IKernel>();
kernel.Stub(x => x.Get<Access>()).Return(access);
This throws an ArgumentNullException:
Message: Value canno...
I am trying to use Rhino.Mocks to mock up a ControllerContext object to gain access to runtime objects like User, Request, Response, and Session in my controller unit tests. I've written the below method in an attempt to mock up a controller.
private TestController CreateTestControllerAs(string userName)
{
var mock = MockRepository....
I'm using Rhino.Mocks 3.6 for the first time. I'm trying to create a stub for an interface that returns an inherited type (B). When I try to do this, it will generate an InvalidCastException trying to convert some proxy object to the base class (A).
For example:
class A {}
class B : A {}
interface IMyInterface
{
A GetA();
}
// C...
I can't find out what's the problem. I haven't found any documentation on AssertWasCalled on Rhino.Mocks site, so I have to ask the question here.
What I do in my tests is I call _mocks.ReplayAll(), then one or more _mockedObject.AssertWasCalled() and then _mocks.VerifyAll(). But it tells me that "This action is invalid when the mock ob...
We use RhinoMocks. I have a type into whose constructor 9 types are injected. I'd like a way of automocking the type, but being able to detect a particular method invocation on one of the injected objects (i.e. I only care about a single method invocation on one of the injected objects).
Is this possible, or do I have to manually inject...
This is a test I am currently working on:
(Edited according to Lees answer)
[Test]
public void AddLockClassWithNullNameShouldCallInsertOnSessionWithEmptyString()
{
LockClass lockClass = new LockClass { Id = ValidId, Name = null };
using ( mockRepository.Record() ) {
sessionFactory.CreateSession();
LastCall.Retur...
Dear All,
Yesterday I re-factored the below method to return either a full view or a partial view.
public ActionResult List(int page)
{
var viewModel = GetListViewModel(page);
if(Request.IsAjaxRequest())
{
return PartialView("_list", viewModel);
}
return View("PartsList", viewModel);
}
But now my tests h...
Hi Is there a way to mock request params, what is the best approach when testing to create fake request values in order to run a test
would some thing like this work?
_context = MockRepository.GenerateStub<HttpContext>();
request = MockRepository.GenerateStub<HttpRequest>();
var collection = new NameValueColle...
Hello there Im trying to write a test can I mock a HttpRequestBase to return post values like this? please help as its quite urgent, how can I acheive this?
var collection = new NameValueCollection();
collection.Add("Id", "1");
collection.Add("UserName", "");
var mocks = new MockRepository();
using (mocks.Record())
{
Exp...
Hi I have a mock as below:
MockRepository mocks = new MockRepository();
ILoanRepository loanRepo = mocks.StrictMock<ILoanRepository>();
SetupResult.For(loanRepo.GetLoanExtended("sdfsdf")).Return(list.AsEnumerable<Loan>());
mocks.ReplayAll();
My question is I have seen the above being use in using statem...
I'm having problems figuring out the proper arguments of the Arg option in RhinoMocks.
I am trying to mock the MSIRecordGetString method which has a ref Int32 parameter. Currently I have:
_Api.RecordGetString(Arg<IntPtr>.Is.Anything,
Arg<Int32>.Is.Anything,
Arg<StringBuilder>.Is.Anything,
...
hey guys
I'm new to mocking, and I'm having a hard time solving an issue with UnitTesting.
Say I have this code:
public class myClass{
private IDoStuff _doer;
public myClass(IDoStuff doer){
_doer = doer;
}
public void Go(SomeClass object){
//do some crazy stuff to the object
_doer.DoStuff(o...
I got this really cool Moq method that fakes out my GetService, looks like this
private Mock<IGetService<TEntity>> FakeGetServiceFactory<TEntity>(List<TEntity> fakeList) where TEntity : class, IPrimaryKey, new()
{
var mockGet = new Mock<IGetService<TEntity>>();
mockGet.Setup(mock => mock.GetAll()).Returns(fakeList);
mockG...
I'm getting an exception that really makes no sense to me whatsoever.
I have an Expect call for a method that takes 3 arguments into it: The types are called CallContext, IDal, and List.
NUnit throws me 2 exceptions: One for not expecting a method call that happened where the types are CallContext, System.Object, and List, and one fo...
Hi,
I'm using MvcContrib's test helpers and Rhino Mocks 3.5 to test an ASP.NET MVC action method. I build my fake controller like so:
var _builder = new TestControllerBuilder();
_builder.InitializeController(_controller);
So I get a fake controller that contains fake HTTP Server etc.
I'm then trying to stub the Server.MapPath method...
So the MvcContrib TestHelpers create mock versions of the following
HttpContext
HttpRequest
HttpResponse
HttpSession
Form
TempData
QueryString
ApplicationPath
PathInfo
within a fake controller when using this kind of code
var _controller = new FooController();
var _builder = new TestControllerBuilder();
_builder.InitializeC...
I'm having another fun problem with Rhino Mocks. Can anyone answer this one:
Here's the call that I'm making in my code:
Expect.On(this.mockDal).Call(this.mockDal.SaveObject(entry)).IgnoreArguments();
mockDal is mocking something of type Dal, and it's SaveObject method's signature is this;
void SaveObject(object obj);
Visual Stud...
I've got a method that's mildly complicated and needs to be very well tested. Secret sauce stuff. Ok, maybe not that cool, but I'm not 100% sure how to go about getting these things setup. This sort of stems from my previous question here. I haven't used rhino mocks so I'm still bad/unaware of the syntax, so feel free to make a ton o...