mocking

Where is the MOQ documentation?

Where can I find comprehensive documentation for MOQ? I'm just starting with mocking and am having difficulty getting my head around it. I've read through all the links at http://code.google.com/p/moq/wiki/QuickStart but can't seem to find a tutorial or gentle introduction. I have also looked briefly at Rhino Mocks but found it very con...

How to mock classes instantiated as local variables

I'm writing tests for a business method that invokes some DAO classes to perform operations over a database. This method, firstly retrieves a JDBC connection from a DataSource object, The same connection is passed to all DAO instances, so I can use it to control the transaction. So, if everything works properly, I must invoke commit() o...

rhino-mocks - good sample apps

Hi guys I know that there has been a couple questions about tutorials on rhino-mocks. But I am wondering if there are any sample apps out there that use rhino-mocks in the context of an n-tier business application using ado.net. I find the tutes good, but they don't seem to bring everything all together into the big picture. Thus, I ...

Mocking HttpContext doesn't work

I am trying to mock out HttpContext so that I can unit test my controller's Request.IsAuthenicated call. I am using the code that I found at Scott Hanselman's blog to simulate HttpContext using rhino.mocks. so i have this unit test piece: PostsController postsController = new PostsController(postDL); mocks.SetFakeControllerContext(post...

What is the best mock framework for VB.NET?

What's the best mocking framework syntax-wise and capability-wise ? My problem: Most mocking frameworks use lambda expressions now, which are really ugly to write in VB.NET, so is there any framework that has nice syntax without lambdas or has fluent syntax that doesn't need lambdas? ...

Forcing application to throw specific exceptions

Hi. We are replacing the exception handling system in our app in order to conform to Vista certification, but the problem is how to force certain exceptions to be thrown, so that we can check the response. Unfortunately the whole app was written without taking into consideration proper layering, abstraction or isolation principles, and...

moq - good sample apps

Hi guys I know that there has been a couple questions about tutorials on moq. But I am wondering if there are any sample apps out there that use moq in the context of an n-tier business application using ado.net. I find the tutes good, but they don't seem to bring everything all together into the big picture. Thus, I am looking for a s...

Data Driven Unit Tests

What is the best practice for testing an API that depends on data from the database? What are the issues I need to watch out for in a "Continuous Integration" environment that runs Unit Tests as part of the build process? I mean would you deploy your database as part of the build scripts (may be run your installer) or should I go for har...

How do I inject a WebRequest/Response dependency?

I'm struggling to separate the dependencies in the following code: public static SiteConnector ConnectToSite(String Logon, String Password) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_URI); ConfigureRequest(Logon, Password, webRequest); HttpWebResponse webResponse = (HttpWebResponse)...

Mock objects, nUnit, call log and log4net

A very often scenario of unit test is as follows: public void SetUp() { this.callLog = new StringBuilder(); } public void TestBuzzBar() { var bar = new Bar(new MockFoo(callLog)); bar.Buzz(17); Assert.AreEqual("MockFoo.Init(17) MockFoo.PrepareStuff MockFoo.DoTheJob ", callLog.ToString()); } ... with MockFoo implementing an IFo...

How do I mock objects without inheritance (in C)?

We use a simple object model for our low level networking code at work where struct pointers are passed around to functions which are pretending to be methods. I've inherited most of this code which was written by consultants with passable C/C++ experience at best and I've spent many late nights trying to refactor code into something tha...

Mocking WebService consumed by a Biztalk Request-Response port

I'm using BizUnit to unit-tests my Biztalk orchestrations, but some orchestrations consume a WebService,and testing these seems more like integration testing than unit testing. I'm familiar with using a mocking framework to mock the generated proxy objects, in order to test a web service from a Windows Forms application, but I would lik...

Mock File methods in .NET (like File.Copy("1.txt", "2.txt"))

We have some methods that call File.Copy, File.Delete, File.Exists, etc. How can we test these methods without actually hitting the file system? I consider myself a unit testing n00b, so any advice is appreciated. ...

Mocks... and Verifiers?

Hello, currently, I am looking deeper into testing techniques, even though I am not sure if I still reside in the unittest-land or left it into the land of integration tests already. Let me elaborate a bit, Given two components A and B and A uses B, then we have a certain "upwards-contract" for B and a certain "downwards-contract" for ...

How can I get PHPUnit MockObjects to return differernt values based on a parameter?

I've got a PHPUnit mock object that returns "return value" no matter what its arguments: // From inside a test... $mock = $this->getMock('myObject', 'methodToMock'); $mock->expects($this->any)) ->method('methodToMock') ->will($this->returnValue('return value')); What I want to be able to do is return a different value based ...

Can I use jmock to replace an implementation returned by a factory?

I have a factory that returns an interface FormatService: public class FormatServiceFactory { public FormatService getService() { ... } } Is it possible to mock out this factory so that it will always return a stub implementation of FormatService - FormatServiceStub in our unit tests? ...

ASP.NET - Separation of concerns

Imagine the following scenario - we have Page1 which contains controls Control A and Control B. Say Control A has a button, and on the click of this button we want Control B to react. But we want to do this in an abstract fashion, i.e. we can't have Control B knowing anything about Control A, and vice versa. That way we can develop the...

Rhino Mocks: Asserting that a method is called exactly one time

I want to assert that a method is called exactly one time. Update: I'm using RhinoMocks 3.5. Here's what I thought would work: [Test] public void just_once() { var key = "id_of_something"; var source = MockRepository.GenerateStub<ISomeDataSource>(); source.Expect(x => x.GetSomethingThatTakesALotOfResources(key)) ...

Mock filesystem in integration testing

I'm writing a ruby program that executes some external command-line utilities. How could I mock the filesystem from my rspec tests so that I could easily setup some file hierarchy and verify it after testing. It would also be best to be implemented in ram so that tests would run quickly. I realize that I may not find a portable solutio...

ASP.NET How to best create a test DB when doing TDD?

Hi folks, what's the best practice for creating test persistence layers when doing an ASP.NET site (eg. ASP.NET MVC site)? Many examples I've seen use Moq (or another mocking framework) in the unit test project, but I want to, like .. moq out my persistence layer so that my website shows data and stuff, but it's not coming from a datab...