mocking

DotNetOpenAuth: Mock ClaimsResponse

Hello, I was wondering how I can mock the ClaimseReponse class in DotNetOpenAuth? This is the class(remove a few properties): [Serializable] public sealed class ClaimsResponse : ExtensionBase, IClientScriptExtensionResponse, IExtensionMessage, ...

How to properly match varargs in Mockito

I've been trying to get to mock a method with vararg parameters using Mockito: interface A { B b(int x, int y, C... c); } A a = mock(A.class); B b = mock(B.class); when(a.b(anyInt(), anyInt(), any(C[].class))).thenReturn(b); assertEquals(b, a.b(1, 2)); This doesn't work, however if I do this instead: when(a.b(anyInt(), anyInt()))...

Testing a method used from an abstract class

I have to Unit Test a method (runMethod()) that uses a method from an inhereted abstract class to create a boolean. The method in the abstract class uses XmlDocuments and nodes to retrieve information. The code looks somewhat like this (and this is extremely simplified, but it states my problem) namespace AbstractTestExample { public ab...

How to mock an SqlDataReader using Moq - Update

Hi, I'm new to moq and setting up mocks so i could do with a little help. Title says it all really - how do I mock up an SqlDataReader using Moq? Thanks Update After further testing this is what I have so far: private IDataReader MockIDataReader() { var moq = new Mock<IDataReader>(); moq.Setup( x => x.Read() ).Returns( true...

How to create tests for poco objects

Hi, I'm new to mocking/testing and wanting to know what level should you go to when testing. For example in my code I have the following object: public class RuleViolation { public string ErrorMessage { get; private set; } public string PropertyName { get; private set; } public RuleViolation( string errorMessage ) { ...

Mock dll methods for unit tests

I am trying to write a unit test for a method, which has a call to method from dll. Is there anyway i can mock the dll methods so that i can unit test? public string GetName(dllobject, int id) { var eligibileEmp = dllobject.GetEligibleEmp(id); <---------trying to mock ...

Passing System classes as constructor parameters

This is probably crazy. I want to take the idea of Dependency Injection to extremes. I have isolated all System.IO-related behavior into a single class so that I can mock that class in my other classes and thereby relieve my larger suite of unit tests of the burden of worrying about the actual file system. But the File IO class I end u...

Mocking a concrete class : templates and avoiding conditional compilation

I'm trying to testing a concrete object with this sort of structure. class Database { public: Database(Server server) : server_(server) {} int Query(const char* expression) { server_.Connect(); return server_.ExecuteQuery(); } private: Server server_; }; i.e. it has no virtual functions, let alone a well-defined int...

What is Mocking?

What is Mocking? ...

Mock a void method which change the input value

Hi, How could I mock a void method with parameters and change the value parameters? I want to test a class (SomeClassA) which has a dependency on another class (SomeClassB). I would like to mock SomeClassB. public class SomeClassA { private SomeClassB objectB; private bool GetValue(int x, object y) { objectB.GetVa...

How can I mock a method in easymock that shall return one of its parameters?

Hi, I have a method public Object doSomething(Object o); which I want to mock. It shall just return its parameter. I tried: Capture<Object> copyCaptcher = new Capture<Object>(); expect(mock.doSomething(capture(copyCaptcher))).andReturn(copyCatcher.getValue()); wihtout success, I get just an AssertionError "Nothing captured, yet". Any i...

Method for unit testing an extension method for SqlCommand

Hi, I've created an extension method for SqlCommand that allows some additional work before executing the command: public static SqlDataReader ExecuteMyReader( this SqlCommand sqlCommand ) { // Some calculations here return sqlCommand.ExecuteReader(); } My question is what is the best way to unit test this extension method? ...

Trouble with RSpec's with method

Hi there, I've coded the following spec: it "should call user.invite_friend" do user = mock_model(User, :id => 1) other_user = mock_model(User, :id => 2) User.stub!(:find).with(user.id).and_return(user) User.stub!(:find).with(other_user.id).and_return(other_user) user.should_receive(:invite_friend).with(other_us...

Is there a tool I can use to generate interfaces and wrappers for object mocking in c#

Given a class like System.Timers.Timer, or ANY managed class (whether user defined, from the .net framework, or some 3rd party library) is there some program I can use to (a) generate an interface based on this class and (b) generate a wrapper for the given class? for example if I have a public class Foo { public object MyProperty ...

Code generation tool, to create C# adapter classes for unit testing?

I know I wouldn't need this with Typemock, however, with something like MoQ , I need to use the adapter pattern to enable the creation of mocks via interfaces for code I don't control. For example, TcpClient is a .NET class, so I use adapter pattern to enable mocking of this object, b/c I need an interface of that class. I then produce...

how to avoid returning mocks from a mocked object list

I'm trying out mock/responsibility driven design. I seem to have problems to avoid returning mocks from mocks in the case of objects that need a service to retrieve other objects. An example could be an object that checks whether the bills from last month are paid. It needs a service that retrieves a list of bills. So I need to mock tha...

C# Visual Studio Unit Test, Mocking up a client IP address

Hey guys, I am writing some unit tests and I'm getting an exception thrown from my real code when trying to do the following: string IPaddress = HttpContext.Current.Request.UserHostName.ToString(); Is there a way to mock up an IP address without rewriting my code to accept IP address as a parameter? Thanks! ...

Automatically creating DynaActionForms in Mockrunner via struts-config.xml

I'm switching from MockStrutsTestCase to Mockrunner and I'm finding that having to manually re-create all of my DynaActionForms in Mockrunner is a pain...there has to be an easier way?! Can somebody offer a tip to simplify this process? For instance, this form bean definition in struts-config.xml: <form-bean name="myForm" type="org.ap...

How to mock a file with EasyMock?

Hello, I have recently been introduced to EasyMock and have been asked to develop some unit tests for a FileMonitor class using it. The FileMonitor class is based on a timed event that wakes up and checks for file modification(s) in a defined list of files and directories. I get how to do this using the actual file system, write a tes...

Should methods containing LINQ expressions be tested / mocked?

Assuming I have a class with a method that takes a System.Linq.Expressions.Expression as a parameter, how much value is there in unit testing it? public void IList<T> Find(Expression expression) { return someCollection.Where(expression).ToList(); } Unit testing or mocking these sorts of methods has been a mind-frying experience fo...