mocking

Using Mockito's generic "any()" method

I have an interface with a method that expects an array of Foo: public interface IBar { void DoStuff(Foo[] arr); } I am mocking this interface using Mockito, and I'd like to assert that DoStuff() is called, but I don't want to validate what argument are passed - "don't care". How do I write the following code using any(), the gener...

Mocking Entity Context in EF4

I am using VS2010 B2 and EF4 B2 and trying to use Rhino Mocks to mock the entity context generated by EEF. var context = MockRepository.GenerateMock<SomeDBEntities>(); IObjectSet<TxMode> objectSet = new List<TxMode> { mode }.AsObjectSet(); context.Expect(c => c.TxModes).Return(objectSet); The problem is that c.TxModes is a property of...

How to verify a certain javascript function has been called during unit testing

Hi all: I'm using JsTestDriver and a bit of Jack (only when needed). Does anyone know how to verify that a javascript function has been called during unit testing? E.g. function MainFunction() { var someElement = ''; // or = some other type anotherFunction(someElement); } And in the test code: Test.prototype.test_mainFunct...

SoapUI Groovy Scripts

Hi , I'm trying to read the incoming request & set the mock response depending on a value comming in the request in soapUI 3.0. I use the following groovy script for this. def typeElement = mockRequest.getContentElement().execQuery("//ProductType"); def records = new XmlParser().parseText(typeElement[0].xmlText()) if (records.text()==...

How to mock methods with lambda as parameter

Hi, I'm new to mocking, I have a method which takes a lambda as a parameter, how can I mock it using Rhino Mocks? Thanks. ...

Rhino.Mocks - Stub one method of class and let other real methods use this stubbed one

I have TimeMachine class which provides me current date/time values. The class looks like this: public class TimeMachine { public virtual DateTime GetCurrentDateTime(){ return DateTime.Now; }; public virtual DateTime GetCurrentDate(){ return GetCurrentDateTime().Date; }; public virtual TimeSpan GetCurrentTime(){ return GetCurrentDate...

How to find the value that has been passed to a method on my mocked (Moq or Rhino Mocks) interface?

I am using Moq - but could easily swap to another mock framework if needed. I have a interface defined: public interface IBaseEngineManagerImp { void SetClientCallbackSender(IClientCallbackSender clientCallbackSender); } I then mock IBaseEngineManagerImp with mockEngineManagerImp = new Mock<IEngineManagerImp>(); EngineManager eng...

Save object in debug and than use it as stub in tests.

My application connects to db and gets tree of categories from here. In debug regime I can see this big tree object and I just thought of ability to save this object somewhere on disk to use in test stubs. Like this: mockedDao = mock(MyDao.class); when(mockedDao.getCategoryTree()).thenReturn(mySavedObject); Assuming mySavedObject - is...

How to verify that method argument's property values are set when mocking methods with Moq?

Not sure if it has been asked before, here is the question. Code first: public class Customer { public string Password { get; set; } public string PasswordHash { get; set; } } public class CustomerService { private ICustomerRepository _repo; public CustomerService(ICustomerRepository repo) { _repo...

Integration test for instantiation of a type via DI container

I am running TDD on an ASP.NET MVC web app. Is it standard practice to create integration tests to demonstrate the correct instantiation of a type via the DI container (in my case Castle Windsor)? If so, would you mock out the container, or simply use it as is? Or... is this simply not done for some reason? Thanks. ...

Mocking a Static Class

I have a static class that wraps some native methods from winspool: public static class WinSpool { [DllImport("winspool.drv")] public static extern int OpenPrinter(string pPrinterName, out IntPtr phPrinter, IntPtr pDefault); ... //some more methods here } I would like to mock them for unit testing, but couldn't fin...

How to unit test the default case of an enum based switch statement

I have a switch statement in a factory that returns a command based on the value of the enum passed in. Something like: public ICommand Create(EnumType enumType) { switch (enumType) { case(enumType.Val1): return new SomeCommand(); case(enumType.Val2): return new SomeCommand(); case(enumType.Val3...

Rhino mocks - does this test look sensible?

I have just crafted the following test using Rhino mocks. Does my test look valid and make sense to those more experienced with mocking? I am a a little confused that I haven't had to use the DynamicMock() or StrictMock() methods to create a seemingly valid test. This test tests that the Add method was invoked on the supplied ICachingS...

Mocking Framework with C# 4.0 Support?

Anybody know of a mocking framework that supports C# 4.0? Doesn't matter which one ATM, just need something that will work. ...

Need ideas for a TDD Approach

We have just released a re-written(for the 3rd time) module for our proprietary system. This module, which we call the Load Manager, is by far the most complicated of all the modules in our system to date. We are trying to get a comprehensive test suite because every time we make any kind of significant change to this module there is h...

Testing internal/closed/sealed System.Data bits. TypeMock or Decorators or xxxxxx?

I'm writing some code that integrates pretty tightly with lots of internal and sealed classes inside of System.Data ( like DbDataRecord and ObjectStateEntry ) for an EntityFramework project I'm working on. Of course the mocking frameworks fall to pieces trying to mock these things. I still need to test these objects and AFAIK my only ...

Is Typemock the only framework that can mock a Linq To SQL Table class?

I am trying to setup unit tests for my Linq To SQL code. My code uses the System.Data.Linq.Table class (generated by the designer). Because this class is sealed and the constructor is internal it is completely impervious to unit testing frameworks like Rhino Mocks. (Unless you want to alter you code to use the repository pattern, whic...

Mock an out paramter with moq or rhino mock or something else

I tried with NMock2 but I get TypeLoadExceptions when trying to pass the mocks into the constructor, also I saw TypeMock can do that but it costs 80$ ...

Mocking Web Service Response | Bundle couple of them in a web app

I am working in an enterprise project and my team is responsible for creating front end of the application and there is another team developing webservices and has provided WSDL for all the services that will be available as part of this project. In development phase our local dev environment will point to one of the development box of t...

mocking LINQ to SQL

What is the best and easiest way to unit test a Class that uses LINQ to SQL and returns back a decimal, is it by Mocking? If so how do I go about this? ...