mocking

RhinoMocks Types

Folks How to Exposte RhinoMock Objects as properties I am trying following code snippet internal class Mocks { private MockRepository.GenerateMock<IFormsAuthentication> formsAuthentication; } but its now working for me anyone know How to do this with rhinomocks ...

JUnit mocking with Mockito, EasyMock, etc

I'm trying to mock a method of an object inside the class I'm testing. For instance class ClassToTest { public doSomething () { SomeObject a = new SomeObject (); a.doSomethingElse (); } } Is there a way to mock the methods of the variable "a"? I'd like doSomethingElse to do nothing during testing. I'm currentl...

Moq - Need mocked function to return value passed in

I have a mock that i have setup like this. I need to return the same value that was passed in to .CreatePersonName mock.Setup(m => m.CreatePersonName(It.IsAny<PersonName>())) .Returns(// what do i put here?); ...

how to display custom error message using rhino mocks

I'm using RhinoMocks to test an Add() method on a viewModel. I've got one test called AddTest()) which tests everything inside the Add() method, including 1) an item was added the viewModel items list, 2) the item was validated 3) the itemsList pagedCollection view was moved to the correct page the problem is that this requires about 5...

RSpec mock_models don't appear to be working for request specs: Should they?

I'm building an app in rails 3 using rspec 2 for specs. All my specs are working fine, except my request spec (only have one at the moment, as I'm building specs as I work): def mock_account(stubs = {}) @mock_account ||= mock_model(Account, stubs).as_null_object end before (:each) do Account.stub(:find_by_id).with(1) { mock_account...

Mockito: Injecting Mocks Throughout Control Flow

I'm still learning mockito and right now I'm learning how to inject mocks. I have an object under test with a particular method that depends on other objects. Those objects, in turn, depend on other objects. I want to mock certain things and have those mocks be used everywhere during execution--throughout the control flow of the metho...

structuremap Property Injection

How to do Dependency Injection on Property of a class Using Structure Map public class ContactController : Controller { public IContactService Service { get; set; } public ContactController() : this(null,null) { } [SetterProperty] public MembershipProvider Provider { get; private set; } } Here when i ...

C# + Mock service layer?

Hello there, I have just started playing with unit testing / mocks using Moq, and ran into a problem.. I have a Service layer named "CustomerService" which have following code: public interface ICustomerService { Customer GetCustomerById(int id); } public class CustomerService : ICustomerService { private IRepository<Customer>...

Best mock framework for .Net 2.0?

Most of the sexy new .Net mock frameworks have heavy dependencies on 3.5 language features such as lambdas and extension methods. I'm looking for recommendations for the "best" mocking tool for a legacy-ish project developed in .Net 2.0. The criteria for "best" would be ease-of-use and readability first, followed by power and scope of f...

Mock or simulate Message Queue (JMS)

There is a message(text), which format and content i definitely know. For now,class in Java,that parses and reads this message from file,is implemented. In real world, this message will come from Message Queue. For now I should simulate, mock or generate Message Queue on my local PC for testing purposes. Java spec(java jms): JMS prov...

mocking in Ruby: mocks are sticking around between tests

I'm using RR as the mocking framework for a personal project of mine. I've been using it to mock the new method for some classes and when I run the tests they pass fine, but when I run ALL of the tests I run into a problem where it seems like the "new" methods are still returning the fake results, even when in a different test file. Is...

Mocks: How to avoid children talking to parents?

i'm trying to test an object by passing a mock owner. Originally PartD would be passed a PartB1 as its owner: PartD partD = new PartD(partB1); Now i want to test a feature of PartD by passing it a mock owner: PartD partD = new PartD(mockPartB1); This works okay, except there are things PartD does that depends on it knowing some sta...

How do you create a mock object without an interface class in AMOP?

I'm just getting into Test Driven Development with mock objects. I can do it the long way with UnitTest++, but now I want to try to minimize typing, and I'm trying to use AMOP mock framework to do the mocking. AMOP states: The main differences between AMOP and other mock object library is that, users DO NOT need to implement the ...

Are fakes better than Mocks?

I stumbled upon this open source project Fake It Easy, and I have to admit, it looks very interesting, however I have my doubts, what are the difference between FIE fakes and say Moq Mocks? Is any one better for particular uses? EDIT: What is it about this new framework that would make it better than say Moq? ...

list Mocking Books

Hi guys can anyone list if any books are available on mocking? for .NET Currently i am reading ASP.NET MVC 1.0 Test Driven Development: Problem - Design - Solution by Emad Ibrahim it's good book but you get lost with just code snippets. It would have been great if at the end of each chapter he had some artifacts ...

Rails mock_model returning TrueClass?!

Trying to test a controller in Rspec. (Rails 2.3.8, Ruby 1.8.7, Rspec 1.3.1, Rspec-Rails 1.3.3) I'm trying to post a create but I get this error message: ActiveRecord::AssociationTypeMismatch in 'ProjectsController with appropriate parameters while logged in: should create project' User(#2171994580) expected, got TrueClass(#214825...

Testing call order across mock objects with Mox and Python

Hi, I'm testing a function that obtains a skeleton object from one helper object, modifies it using a second helper, and passes the modified object back to the first helper. Something along the lines of: class ReadModifyUpdate(object): def __init__(self, store, modifier): self._store = store self._modifier = modifie...

Mock Verify/VerifyAll before or after Assertion

Hi All, I have been used to following code pattern while writing my test public void TestMethod_Condition_Output() { //Arrange---------------- Mock<x> temp = new Mock<x>(); temp.setup....... //Act-------------------- classinstance.TestMethod() //Assert------------------ temp.VerifyAll(); Assert.AreNot...

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

Making a DynamicMock MockInstance equal to itself

Trying to use NUnit to test a method that adds an object to a queue, and throws an exception if the object's already been queued, but it fails because Queue.Contains() can't detect that the mock object's already in the queue. The method under test is pretty simple: public void Enqueue(ISomeInterface obj) { if (myQueue.Contains(obj)...