mocking

How to Mock a printer in .NET?

I have an application that sends out many PDF's to a printer. Has anyone had any experience creating a Mock object that represents a local printer? ...

How can I mock Elmah's ErrorSignal routine?

We're using ELMAH for handling errors in our ASP.Net MVC c# application and in our caught exceptions, we're doing something like this: ErrorSignal.FromCurrentContext().Raise(exception); but when I try to unit test the caught exceptions, I get this message: System.ArgumentNullException: Value cannot be null. Parameter name: context H...

What would this Moq code look like in RhinoMocks

Hey people... trying to get my mocking sorted with asp.net MVC. I've found this example on the net using Moq, basically I'm understanding it to say: when ApplyAppPathModifier is called, return the value that was passed to it. I cant figure out how to do this in Rhino Mocks, any thoughts? var response = new Mock<HttpResponseBase>(); re...

Lua I/O dependency injection

I'm a Lua novice. I'm unit testing Lua 5.1 code using Lunity and LeMock. My class is StorageManager. I'm unit testing its load() method, which loads files from disk. I don't want my unit tests dependent on actual files on the actual disk to test that. So, I'm trying to inject the I/O dependency with a mock object and verify that obj...

JQuery Mocking

I am looking for a mature framework that can do Javascript mocking, especially on AJAX and JSON area. Is there any existing mocking framework for Javascript ( and/ or JQuery) that you are used and can recommend? Edit: I have evaluated jqmock and jqunit. It seems that it's the only framework that can do basic library mocking and stubbin...

How can I mock ActivityExecutionContext

This class is sealed but I need to mock it using Moq for use in a CRM workflow development for calling the method: protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) How can I do this or get around the problem by creating an instance of ActivityExecutionContext (which has no public constr...

FTP Mock for .NET framework

Is there a mock implementation for a ftp server that I can use in my UnitTests. I don't want my tests to depend on a real FTP server. For JAVA a ftpmock can be found here. ...

Mocking problem, public function calling private function

Hi! I’m having a mocking problem. I know only public methods should be mocked. But what do I do when a private method is called in a public method, and this private method is getting data from a file? I want to mock this private method so I could go on in with the test of the public method. I could make this public to make the test wor...

Rhino mocks - assert method was called with given parameter

My test method look like this: [Test] public void Generated_CaseNumber_should_be_set_as_LastCaseNumber_in_PropertiesManager() { String generatedCaseNumber = _sut.NextCaseNumber(); } _sut object has a dependency to mocked object of type IPropertiesManager. Method _sut.NextCaseNumber() should generate un...

Best way to mock java web service

I have to mock quite complicated java web service and I'm searching for the right solution. One way to do it would be to use Soap UI, but I need something that would be able to modify server state ie. one request would affect future requests. In this particular case it could be done quickly by saving serialized objects to disk and some...

Dependency injection - Place logic in the overloaded constructor?

Today I've got this class: public class SmtpEmailProvider : IMessageProvider { private readonly SmtpClientWrapper _smtpClientWrapper; public SmtpEmailProvider(SmtpClientWrapper smtpClientWrapper) { _smtpClientWrapper = smtpClientWrapper; } To be able to mock the SmtpClient, I've wrapped it like this: public c...

Getting arguments of a called Typemock mocked method

Hi all, I am a keen user of RhinoMocks developing from a TDD and AAA perspective with NUnit and ReSharper. I am changing jobs and the team I am moving to uses TypeMock so I want to hit the ground running... and I have run into a problem. How can I get the arguments for a called method on a mock object. When using RhinoMocks I use: mock...

What am I doing wrong this time with Moq?

Hi I am having problems with moq again and not sure what I did wrong this time. So I am going through the debugger step by step and I notice even though in my Mock I set ResetPassword to return "hey it does not seem to Here is part of my unit test: var membershipMock = new Mock<MembershipProvider>(); var user = new Mo...

unit test smell

I am trying to change my unit testing of ArcGIS, and start using mocks (I use rhino). When I started to get into writing the tests, I noticed I have to start mocking a lot of objects, and stub a lot of methods for even a single test to pass. For example - my controller first gets a RelationshipClass (so I need to stub the IWorkspace and ...

How do I make a mockup of System.Net.Mail MailMessage?

Hi So I have some SMTP stuff in my code and I am trying to unit test that method. So I been trying to Mockup MailMessage but it never seems to work. I think none of the methods are virtual or abstract so I can't use moq to mock it up :(. So I guess I have to do it by hand and that's where I am stuck. *by hand I mean witting the inter...

Test Cases: Mocking Database using Spring beans

Our application has a service layer and a DAO layer, written as Spring beans. While testing the Service Layer- I do not want to depend upon a real database so I am mocking that by creating a 'Mock' Impl for the DAO layer So when I am testing the Service layer- I chain the Service layer beans to the Mock DAO beans And in Production- wil...

Excluding code from test coverage

Wherever possible I use TDD: I mock out my interfaces I use IOC so my mocked ojbects can be injected I ensure my tests run and that the coverage increases and I am happy. then... I create derived classes that actually do stuff, like going to a database, or writing to a message queue etc. This is where code coverage decreases - an...

Recording interaction on an inflection point using mocking framework. Moq

Updated version of question Hi. My company has a few legacy code bases which I hope to get under test as soon as they migrate to .NET 3.5. I have selected Moq as my Mocking framework (I fell in love with the crisp syntax immediately). One common scenario, which I expect to see a lot of in the future, is where I see an object which i...

Mocking non-virtual methods in C#

I'm trying to test some classes I've made using mocks, but I've seen all free mocking frameworks in c# aren't able to mock non-virtual methods (if it is not in an interface). But, there's TypeMock who can do this, so it is possible. Can anyone show how to do it? I may even try to contribute to an open source framework if I can get this...

Need Help understand Moq better.

Hi I been looking at the Moq documentation and to me the comments are too short for me to understand each of things it can do. First thing I don't get is It.IsAny<string>(). //example using string Is there an advantage of using this over just putting some value in? Like I know people say use this if you don't care about the value but...