mocking

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...

Is it legal to stub the #class method of a Mock object when using RSpec in a Ruby on Rails application?

I would like to stub the #class method of a mock object: describe Letter do before(:each) do @john = mock("John") @john.stub!(:id).and_return(5) @john.stub!(:class).and_return(Person) # is this ok? @john.stub!(:name).and_return("John F.") Person.stub!(:find).and_return(@john) end it.should "have a valid #to fi...

Unit testing in asp.net MVC, how do I mock a page request?

How do I mock a page request for a .net MVC page? ...

Testing an object's state at save

I'm looking to write unit tests for a method such as this one: public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { ISPMembershipUserDao userDao = GetISPMembershipUserDao(); if (ValidateUser(username, password)) { SPMembershipU...

Best tool to develop screen mocks

I'm starting a new project and would like to develop some screen mocks to show to users before I'm actually designing my screens. What (hopefully free) tool would you recommend to use for this? Thanks! ...

How do you mock the caching object in asp.net mvc?

How would I mock the caching object on the ControllerContext object for my unit tests? I have tried creating a wrapper class like the following (since the cache object is a sealed class) with no luck. var mockControllerContext = new Mock<ControllerContext>(); var mockhttpContext = new Mock<HttpContextBase>(); mockhttpConte...

How do I create a mock object for Spring's WebServiceTemplate?

I have a class which calls out to an existing web service. My class properly handles valid results as well as fault strings generated by the web service. The basic call to the web service looks something like this (although this is simplified). public String callWebService(final String inputXml) { String result = null; try { ...

Discrepancies between “Mock” Database and “Real” database behaviours.

We use C# and Linq2SQL with a MS SQL Server Database. We have a mockdatacontext to carry out some unit testing. When testing we have discovered two different behaviours depending on whether the "real" or "mock" database is used. Scenario 1: Real Database There are 5 records in the database: db = realDatabase db.InsertOnSubmit(new re...

Experiences using moq with VB.Net

I really like the moq mocking framework. I've used it on several projects. Unfortunately, one of my customers is demanding we use VB.Net. Not my preference, but hey, .Net is .Net, right? I've heard that moq has some trouble with VB. Is this true? Is so, what sorts of trouble? I would expect it to work fine given the language agnos...

Unit testing with generated DAL code

I use a code generator (CodeSmith with .NetTiers template) to generate all the DAL code. I write unit tests for my code (business layer), and these tests are becoming pretty slow to run. The problem is that for each test, I reset the database to have a clean state. Also, as I do a lot of tests, it seems that the latency of the database o...

XNA mock the Game object or decoupling your Game

I was wandering if it's possible to mock a Game object in order to test my DrawableGameComponent component? I know that mocking frameworks need an interface in order to function, but I need to mock the actual Game object. edit: Here is a link to respective discussion on XNA Community forums. Any help? ...

Strategies to mock a webservice

I'm implementing a client consuming a webservice. I want to reduce dependencies and decided to mock the webservice. I use mockito, it has the advantage vs. EasyMock to be able to mock classes, not just interfaces. But that's not the point. In my test, I've got this code: // Mock the required objects Document mDocument = mock(Document.c...

Why does my partial mock have all virtual methods mocked, even if no expectations are set?

I have a user control which does some validation in the ValidateChildren method which I would like to test. I have created a partial mock of the user control, but although I am not setting any expectations on the ValidateChildren method, I am simply calling it, it is simply skipped and the code inside the method never executes. To try ...

Looking for the best opensource Mocking framework for .net

I know this is fairly subjective, but I'm diving into testing and learning about mocking, and I'm trying to figure which framework I should use. If you could please tell me which ones you recommed and most importantly why it's better than others you've used I would aprpeciate. Or if anyone knows where I can get a side-by-side comparison ...

Unit testing with NSURLConnection

Hello! I want to test a piece of code that uses network (the NSURLConnection class, to be specific). The code (let’s call it NetworkManager) looks a bit like this: - (id) buildConnection { // some more code and then: return [NSURLConnection …]; } - (void) startNetworkSync { id connection = [self buildConnection]; //… }...

How to mock or stub a .netTiers generated DataRepository object

I am using Rhino mocks for unit test mocking of objects. Our DAL uses codesmith to generate code from .netTiers templates, which creates these DataRepository classes that contain all the methods for CRUD type transaction to the datasource. In unit testing, I am trying to mock this data repository object which has no interface class to us...

Is my Unit Test Sufficient?

I am looking at the Unit Tests I wrote for an email service (unsing SMTP) and I am wondering if one test inparticular is suffient. Here is a snippet of my email service: [PluginFamily("EmailService")] public interface IEmailService { Boolean SendEmail( string toAddress, string fromAddress, string bccAddress, string ccAddress, stri...

Creating a mock with Jmock to return a null value for itself

I have a method that looks similar to the following: public void myMethod(MyClass c) { if (c == null) { return; } try { c.someMethod(); } catch (SomeException e) { // log the exception, possibly re-throw } } I am trying to find a way to set up a mock instance of the MyClass parameter c such that it return...

relevance and benefit of a mocking framework to emulate various physical device

Hello Is a mocking framework a good idea for working with several physical devices, and mocking them ? The main goal of my compagnie is to interface our software with several brand of theater projector( barco, sony... ) , sound processor, IO controler ( barionet, wago ). Sometime the vendor give an API for the communication, sometime...

will a mocked interface still serialize to a file?

I'm trying to unit test saving of a file. I have an interface that defines a document, and I pass a concrete object that implements that interface to the Save method, and it works in practice, but I'm trying to unit test it to ensure that it will always work (and I'm desperately trying to catch up on the unit tests after a period of 'cru...