moq

Why would I select Moles as my mocking framework?

I've been looking at several Mocking frameworks for ASP.NET and came across Microsoft Moles. This seems to be a part of Microsoft Research team and was wondering If anyone here has selected Moles over other matured Mocking frameworks such as Moq. ...

Moq Example using out and ref needed.

Hi, I am trying to build a test against some legacy method that implement out parameters. Could you give me an example how to do this? Very grateful ...

Mocking methods that call other methods Still hit database.Can I avoid it?

Hi, It has been decided to write some unit tests using moq etc..It's lots of legacy code c# (this is beyond my control so cannot answer the whys of this) Now how do you cope with a scenario when you dont want to hit the database but you indirectly still hit the database? This is something I put together it's not the real code but give...

mocking collection behavior with Moq

Hello, I've read through some of the discussions on the Moq user group and have failed to find an example and have been so far unable to find the scenario that I have. Here is my question and code: // 6 periods var schedule = new List<PaymentPlanPeriod>() { new PaymentPlanPeriod(1000m, args.MinDate.ToString()), new PaymentPla...

Integrate Pex with MoQ

Can anyone point me to a resource that shows an example of how Pex can be used in conjunction with MoQ? Thanks ...

Calling original method with Moq

I have a ProductRepository with 2 methods, GetAllProducts and GetProductByType, and I want to test the logic at GetProductByType. Internally, GetProductByType makes a call to GetAllProducts and then filters the correct ones. public virtual IEnumerable<Product> GetAllProducts() { //returns all products in memory, db etc } public vir...

Returning different results or throwing exceptions from successive calls to Moq Mock

I get a Moq object to return different values on successive calls to a method. This is done by this extension method: public static void ReturnsInOrder<T, TResult>(this ISetup<T, TResult> setup, params TResult[] results) where T : class { setup.Returns(new Queue<TResult>(results).Dequeue); } Now I want one of the calls to throw a...

Can someone help me Mock this ASP.NET MVC Controller with Moq, please?

Hi folks, I'm trying to mock an ASP.NET MVC2 Controller using Moq but I get an error because i'm trying to mock an non-overridable property. How should I be doing this, please? NOTE: the controller I'm trying to mock up is the (abstract) ASP.NET MVC2 Controller ... not a custom controller. Why? I'm trying to test some custom controller...

Mocking a property using SetupGet and SetupSet - this works, but why?

Using Moq I am mocking a property, Report TheReport { get; set; } on an interface ISessionData so that I can inspect the value that gets set on this property. To achieve this I'm using SetupGet and SetupSet as follows: // class-level fields protected Report _sessionReport; protected Mock<ISessionData> SessionData { get; private set; } ...

How to write Internal mockable method

We are using Moq as our mocking framework, the problem is that type that needs to be mock-able is done using an interface, the problem with that is anything in that interface will be public and therefore considered part our public API. is there a way to have to have a member that is mockable and not public? ...

How to setup a simple Unit Test with Moq?

I'm new to Moq and not quite sure why this won't run. Repository Interface using System.Collections.Generic; public interface IRepository { IEnumerable<string> list(); } Service Interface using System.Collections.Generic; public interface IService { IEnumerable<string> AllItems(); } Service Class using System.Collection...

Conditional logic on Generic Type Constraints

I'm trying to write an automocking extension of Unity. While it would be much easier to use a Windsor subdependency resolver and RhinoMocks I'm forced by the business to use Unity and Moq. I haven't found an existing solution that uses Moq and I've found out why. Moq can't generate mocks from just a Type parameter, which makes Unity ex...

Moq Exception: Verifying a method call that takes parameters

I want to test that the "Create" method on the _eventManager in my controller gets called. When I run my test, I get the following exception: Test method Baigent.TheDoNation.Application.Tests.EventControllerTest.Create_Post_IfModelIsValidRedirectToSuccessfullyCreatedViewOccurs threw exception: System.ArgumentException: Invalid setup on...

How do i Moq an Ideablade Entity 'IRepository'

I haven't been able to find anything on setting up an IRepository<> through moq for IdeaBlade, I was wondering if anyone has had the pleasure of setting one of these up before and is kind enough to shown some light for me. Thanks! ...

Moq: How to clear expectations on a mock object ?

An example - I want to test that the sniper notifies the view only for added items. [Test] public void NotifiesViewOfLoss_IfCloseEventReceivedForSnipedItems() { _sniper.AddItem(TestConstants.ItemNo54321); _sniper.AddItem(TestConstants.ItemNo65432); _sniper.AuctionClosedFor(TestConstants.ItemNo65432); ...

Using Moq with Windsor -- Object of Type Moq.Mock[IFoo] cannot be converted to IFoo

I'm trying to set up some Moq repositories to test my service with Castle Windsor as my IOC. Mu service depends on IFoo, so I'm creating a moq instance that implements IFoo and injecting it into the container like so: _container.AddComponent("AutoBill", typeof (AutoBillService), typeof (AutoBillService)); var mockUserRepository = n...

What are strict and non-strict mocks?

I have started using moq for mocking. Can someone explain me the concept of strict and non-strict mocks? How can they can be used in moq? edit: in which scenario do we use which type of mock? ...

Dependency injection and mock framework for .net

I am trying to set up expectations on methods of a mocked object in Moq. At the same time, using Ninject, I try to have the kernel return my set up mock whenever a caller wants the corresponding interface. For more clarity, here's some pseudocode Class Car { Void buildChassis() { Engine = ObjectBuilder.get<Iengine>() ...

Unit Test Throwing "System.NullReferenceException", using Moq and Nunit

Hi All, I am newbie to moq and unit testing. So, I don't understand it thoroughly. pardon me if question is stupid. please help me understand the following scenario. Following is my simple test [Test] public void TryMoq() { var mock = new Mock<IDummyInterface>(); var dummy = new DummyClass(mock.Object); mock.VerifySet(m =...

TDD System Under Test Creation Patterns (AutoFixture)

I'm trying to use SUT Factory 'pattern' to create my SUT. Given the SUT structure: namespace MySut { public class Dep1 { } public class Dep2 { } public class Sut { public Sut( Dep1 dep1, Dep2 dep2 ) { } } } I'm using AutoFixture, and am wondering what's the best way to col...