moq

OpenRasta unit testing

I’m about to start work on an OpenRasta project (an xml over http web service). OpenRasta looks great but unfortunately worked examples seem few and far between on the internet. Looking at the test side of the project, if my handlers are returning strongly typed objects (not OperationResult), i.e.: public class PersonHandler ... public...

How can I convert a Predicate<T> to an Expression<Predicate<T>> to use with Moq?

Please help this Linq newbie! I'm creating a list inside my class under test, and I would like to use Moq to check the results. I can easily put together a Predicate which checks the results of the list. How do I then make that Predicate into an Expression? var myList = new List<int> {1, 2, 3}; Predicate<List<int>> myPredicate = (lis...

MOQ 'TestMethod(Action<int> callback)' and be able to 'call' callback.

Oook, I'm wanting to mock a callback that I know my service will call. For example: public interface ITestMe { void TestMethod(Action<int> callback); } In the application, when calling 'TestMethod' I would pass the callback method to hit after it has run, which will do something based on the parameters. Typically, in this case it's us...

testing controller using MOQ calling repository

I'm very new to Mocking. In the below example i'm using Moq and trying to create a _companyRepository. However the second test has a null ref. ie Company is not instantiated. Assert.AreEqual(viewModel.Company.Name, "MyCompany"); Think i'm missing something silly here. [TestClass] public class ErrorControllerTest { ...

Moq: Setup a property without setter?

Hi, I have following class: public class PairOfDice { private Dice d1,d2; public int Value { get { return d1.Value + d2.Value; } } } Now I would like to use a PairOfDice in my test which returns the value 1, although I use random values in my real dice: [Test] public void DoOneStep () { var mock = new Moc...

Why the 'Moq.Proxy.CastleProxyFactory' type initializer exception when using NET40-NoCastle?

So I copied the sample code from the Moq home page pretty much verbatim, and am getting a castle proxy exception. Here's my code (as a console app for an easier sample) using System; using System.Collections.Generic; using System.Linq; using System.Text; using Moq; namespace MoqTestConsole { public interface ILoveThisFramework ...

Moq which Version to use

Hi all, I am starting a new project and I would like to know which version of Moq should I be using? I have noticed that there is a version 4? Is that RTM? In my place there are a bit funny about beta versions? any suggestions? ...

View returned from mvc action is blank using moq

The topic says it all. I'm guessing this is because of some missing setup related to MVC, but I'm very new to the world of http, asp.net and mvc, so I'm not quite sure what's wrong. public class MyController : Controller { public ActionResult MyAction(MyModel model) { return View(model); } } var controllerMock = new M...

Entity Framework 4, MOQ,

Hi, I am using EF4, Microsoft.Entity.CTP, and the latest MOQ. I am trying to create a generic repository class and moq the DBContext using MOQ. Whenever I run my moq test I get "object reference not set to an instance of an object" on this.context.Set().Add(entity); and I don't understand why. The code runs ok without a moq. public clas...