Hello, I'm using the Moq framework to do my unit testing. I'm following some really useful instructions outlined here to help me mock the httpcontext, specifically for the purposes of testing the url referrer:
http://my6solutions.com/post/2009/08/18/Mocking-HttpContext-in-ASP-NET-MVC.aspx
Everything seems to compile fine, however whe...
Hi all,
I have a method that i want to mock that takes an array as a argument. In a real call, the method would modify this array and the resultant array would be use further along in code.
What i tried to do was pass in array to the mocked method call, that had values that would be valid when the array is used again. However what i fin...
I have a preexisting Interface...
public interface ISomeInterface
{
void SomeMethod();
}
and I've extended this intreface using a mixin...
public static class SomeInterfaceExtensions
{
public static void AnotherMethod(this ISomeInterface someInterface)
{
// Implementation here
}
}
I have a class thats callin...
I am using Moq for unit testing and I would like to test for a view's attribute.
In this case the Authorize attribute.
Example View Code:
[Authorize(Roles = "UserAdmin")]
public virtual ActionResult AddUser()
{
// view logic here
return View();
}
So I would like to test the view attribute when I act on this view with a user t...
I have a method that calls a service to retrieve an instance of an object, updates the instance then saves the instance back to the service (the code for this is below).
What I want to know is if there is a nice way in Moq to check the following:-
That the instance that is being saved back to the service is a modified version of the o...
Hi folks,
i have the following code, which fails during runtime...
var mock = new Mock<ControllerContext>();
mock.SetupGet(x => x.HttpContext.Request
.ServerVariables["HTTP_HOST"]).Returns(domain);
** RunTime Error: Invalid setup on non-overridable
property
I've got some code in my controller, which needs to check the doma...
Whats the best way to setup a mock expection for the Map function in AutoMapper.
I extract the IMapper interface so I can setup expects for that interface. My mapper has dependencies, so I have to pass those in to the mapper.
What happens when I create 2 instances of my mapper class, with 2 different dependency implementations? I asume...
i have just started using Moq ver (3.1) and i have read blogs and what not.... anyway... i guess until you makes your hand dirty you will not learn :)
okay here is what i'm testing...
var newProduct = new Mock<IPartialPerson>();
newProduct.SetupGet(p => p.FirstName).Returns("FirstName");
newProduct.SetupGet(p => p.MiddleNam...
In a custom ActionFilter, I want check the attributes on the controller action that will be executed. Running through a small test application, the following works when launching the app in the asp.net development server-
public class CustomActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(Action...
I'm trying to use mock to verify that an index property has been set. Here's a moq-able object with an index:
public class Index
{
IDictionary<object ,object> _backingField
= new Dictionary<object, object>();
public virtual object this[object key]
{
get { return _backingField[key]; }
set { _backing...
Hopefully this is a simple. I just getting started with mocking frameworks and have decided to use MOQ. I'm having trouble with one of my test after setup of my mock object so i decided to step through the code. When i hit F10 after the following line:
Dim Mock = New Mock(Of IMyInterface) <----Error When on this line and hit F10
Wi...
I have an abstract class that has a virtual method. The method is virtual in the event that a later implementation needs to override that functionality.
However, Moq proxies all virtual methods so I don't seem to be able to test the actual code that's written, and instead uses the Mock setup for that method (which is currently to return...
Hi,
I hope this question is not 'controversial' - I'm just basically asking - has anyone here purchased TypeMock and been happy (or unhappy) with the results?
We are a small dev shop of only 12 developers including the 2 dev managers. We've been using NMock so far but there are limitations. I have done research and started playing with...
I've just been working on some tests using Moq but ran into trouble trying to test a method I wanted to call twice through a try catch block. The principle is that the first call throws an exception, then in the catch I correct the problem and call the method again.
I managed to do it with Rhino Mocks as below but being new to both fra...
I am trying to unit test the code I got from an DotNetOpenAuth example but I have a hard time getting the UrlHelper to work in my tests.
Somewhere on the LogOn ActionResult on my controller it calls the following UrlHelper. The following example is a simplified version of that ActionResult.
public ActionResult TestUrlHelper()
{
var...
When I try to mock a class using Moq the method attribute gets inherited to the mock class, but not the parameter attribute.
Basically the row "let a = (ArgumentsAttribute) p.GetCustomAttributes(typeof (ArgumentsAttribute), true).SingleOrDefault()" doesnt return the attribute.. Run the code to see where it fails.
How do I make this tes...
I am using Web Forms MVP to write an DotNetNuke user control. When the 'SubmitContactUs' event is raised in my unit test the presenter attempts to set the 'Message' property on the Modal. However the View.Modal is null in the presenter.
Shouldn't the Web Forms MVP framework automatically build a new View.Model object in the presente...
I've just started some MonoTouch development and I've tried, and failed, to get Moq working for my unit tests. The binary version fails because it's looking for System v2.0, which I assume is down to its Castle requirements, and building it from source crashes the compiler!
My question is has anyone gotten Moq to work on Mono (the touch...
This seems like an easy enough issue but I can't seem to find the keywords to effect my searches.
I'm trying to unit test by mocking out all objects within this method call. I am able to do so to all of my own creations except for this one:
public void MyFunc(MyVarClass myVar)
{
Image picture;
...
picture = Image.FromStrea...
I am pretty new to use moq. I am into creating some unit test case to HttpModule and everything works fine until I hit a static property as follows
this.applicationPath = (HttpRuntime.AppDomainAppVirtualPath.Length > 1) ? HttpRuntime.AppDomainAppVirtualPath : String.Empty;
I do not know how create mocks for static class and...