moq

How to i unit test this method?

I need to unit test this method. I'm using moq as my mocking framework, if that helps. [AcceptVerbs(HttpVerbs.Get)] public RedirectToRouteResult LogOff() { FormsAuthentication.SignOut(); return RedirectToAction("Index", "Post"); } cheers :) EDIT: It was mainly the FormsAuthentication i was wondering. Should I even be testing ...

Unit Testing with Moq, Silverlight & Nunit

I am attempting to unit test a silverlight 3 project. I am using: Moq.Silverlight (3.0.308.2) NUnitSilverlight (http://www.jeff.wilcox.name/2009/01/nunit-and-silverlight/) When I write a test that does not use moq, it works as it should. When I use moq outside of a test, moq works as it should. (I mocked a interface and did a verify ...

How to mock Controller.User using moq

Hi there, I have a couple of ActionMethods that queries the Controller.User for its role like this Boolean isAdmin = User.IsInRole("admin"); acting conveniently on that condition. I'm starting to make tests for these methods with code like this [TestMethod] public void HomeController_Index_Should_Return_Non_Null_ViewP...

Moq - How to unit test changes on a reference in a method

Another day , another question. My service layer has the following method public MatchViewData CreateMatch(string user) { var matchViewData = !HasReachedMaxNumberOfMatchesLimit(user) ? CreateMatchAndAddToRepository(user) : MatchViewData.NewInstance(new Match(user)); matchViewData.LimitReached = HasReachedMaxNum...

Unit Testing a clone method with Moq in C#

I have some basic classes with cloning methods: public class SimpleClass { public int ValueA { get; set; } public string ValueB { get; set; } public ulong ValueC { get; set; } public SimpleClass TypedClone() { var item = new SimpleClass { ValueA = this.ValueA, ValueB = this....

What OSS software should I use for enterprise software?

Summary: OSS Technologies that fit with MS C#, Dot Net, and VS enterprise development. I am not trying to be subjective. I need a finite list of MS C# specific enterprise practices with matching OSS software titles that work with MS MVC (outlined below). From there I can review and setup a "hobbie kit" installer for my dev team. I wa...

Mocking non-virtual Events (In COM interop classes)

Edit: Language/Platform is C# / .Net I'm currently trying to fill a vast unit-test void in my current project, and being admittedly new to TDD, find myself quite stumped as to how to go about testing some of the more business-critical features. I picked up Moq and had an easy enough time doing simple mocks, however at the core of my ap...

How do i moq this DotNetOpenAuth Response object?

Hi folks, i have a method which takes in a DotNetOpenAuth (formally known as DotNetOpenId) Response object. My method extracts any claimed data, checks to see if this user exists in our system, yadda yadda yadda... and when finished returns the auth'd user instance. Now .. how can i use moq to mock up this response object, to test my a...

Why does getting the mocked instance created with Moq throw a System.BadImageFormatException?

This question may be related to another question and it certainly results with a System.BadImageFormatException. Maybe it's the same thing but exposed differently? I have the following the code: public interface IFoo<T> where T : class, new() { T FooMethod(object o); } public interface IFooRepo { F GetFoo<T, F>() where T : class, ...

Moq with Action argument

I'm trying to use Moq 3.x, it works superbly. However, I have a problem I can't figure out how to solve. Given public interface ITestSpec { bool Run(Action<string, string> onIncorrectResponse); } I am trying the following: var passingTestSpec = new Mock<ITestSpec>(); passingTestSpec .Setup(m => m.Run(null)) .Returns(true); Act...

How do I moq a ISingleResult? Should I? or there is a better method?

I have an action method like this in my controller public ActionResult Index() { using (NorthwindDataContext db = new NorthwindDatacontext()) { var results = db.GetRecordSets(arg1, ....).ToList(); // use results as list } return View(); } and I wanted to start making tests for it (yes, after it was bui...

Mocking a connection to a data source inside a function with Moq?

Hi! I'm starting to use Moq and I cannot figure out how to test the method Execute in the code below: I have the following class: public class MyObject { private IDataReaderPlugin m_source; private IDataWriterPlugin m_dest; private string[] m_dummyTags = new string[] { "tag1", "tag2", "tag3"}; public void Execute(DateT...

How to unit test a controller that calls Url.Action using AutoMockContainer?

This question is very similar to 674458 but I really want to use the AutoMockContainer in my unit tests. I cannot figure out how to setup up my context. Has anyone been able to unit test a controller that calls Url.Action using the AutoMockContainer? ...

How Do I Use the MoqAutoMocker that comes with StructureMap 2.5.3?

I'm trying to use the MoqAutoMocker class that comes with StructureMap and I can't find any examples of how it should be used. All I have to go on is the example at the StructureMap site that uses RhinoMocks. What I'm trying to do is get reference to one of my auto-mocked/injected dependencies using the Get method. According to that l...

Mocking the is operator in Moq

Is there a way to get my mocks to impersonate a type? I am trying to do something like this: var myMock = new Mock<IMyType>(); myMock.Setup(x => x.GetType()).Returns(typeof(MyTypeImpl)); however, GetType is not overrideable. Any suggestions? ...

How to mock the Request on Controller in ASP.Net MVC ?

I have a controller in C# using the ASP.Net MVC framework public class HomeController:Controller{ public ActionResult Index() { if (Request.IsAjaxRequest()) { //do some ajaxy stuff } return View("Index"); } } I got some tips on mocking and was hoping to test the code with the following ...

How do I unit test an ASP.NET MVC controller that uses DotNetOpenId?

I have an AccountController whose constructor takes an object derived from my custom IOpenIdAuthentication interface. By default, this is an OpenIdAuthenticationService object that wraps an OpenIdRelyingParty. The interface looks like this: public interface IOpenIdAuthentication { IAuthenticationResponse Response { get; } IAuthe...

What is the purpose of Verifiable() in Moq?

What is the purpose of Verifiable()? If I verify a mock and leave this out it still verifies the SetUp. Edit: I was using VerifyAll() thus the reason for everything being verified. After changing to Verify() only my verifiable setups were being check. ...

Can I get a series of good results and a thrown exception from Moq.

I am mocking a wrapper to an MSMQ. The wrapper simply allows an object instance to be created that directly calls static methods of the MessageQueue class. I want to test reading the queue to exhaustion. To do this I would like the mocked wrapper to return some good results and throw an exception on the fourth call to the same method. ...

Mocking The RouteData Class in System.Web.Routing for MVC applications

Hi, I'm trying to test some application logic that is dependent on the Values property in ControllerContext.RouteData. So far I have // Arrange var httpContextMock = new Mock<HttpContextBase>(MockBehavior.Loose); var controllerMock = new Mock<ControllerBase>(MockBehavior.Loose); var routeDataMock = new Mock<RouteData>(); var want...