I'm working on a generic repository and I would like to test it using a NUnit.Mocks . According to Mike Hadlow in his article you can do it using Rhino mocks like this:
User[] users = new User[] { };
...
Expect.Call(userRepository.GetAll()).Return(users);
So I thought maybe I could write the same thing in NUnit.Mocks like this :
data...
Here is my situation:
I want to test on the "HasSomething()" function, which is in the following class:
public class Something
{
private object _thing;
public virtual bool HasSomething()
{
if (HasSomething(_thing))
return true;
return false;
}
public virtual bool HasSom...
Hi!
I've a problem setting up a test for an Equals method on an object.
The object in question is defined by this interface:
public interface IHours {
ITimeOfDay OpenAt { get; set; }
ITimeOfDay CloseAt { get; set; }
DateTime ValidFrom { get; set; }
DateTime ValidTo { get; set; }
bool isCovered(DateTime time);
}
a...
I'm trying to write a test for an ASP.NET MVC controller method. I've got RhinoMocks (since it seems to be the most popular and best supported), and MvcMockHelpers (since it seems like I need that).
My test method looks like:
var controller = new MyController();
MvcMockHelpers.SetFakeControllerContext(mocks, controller);
mocks.ReplayA...
I'm pretty new to testing and mocking and i am trying to write a test that will ensure that my validation logic is setting ModelState errors correctly.
What I'm seeing is that the controller.ControllerContext.HttpContext.Request is set the first time I check it but every time after that the Request is null.
This is causing a null r...
Again at the Rhino Mocks Noob Wall
mockUI.Expect( x => x.Update( new Frame[] {Frame.MakeIncompleteFrame(1, 5)} ) );
This is the exact argument that I need to match. Via trace statements, I have verified that is the actual output as well i.e. the code behaves as intended but the test disagrees. RhinoMocks responds with
TestBowlingSc...
I am trying to test how my class reacts on to what happens when the BackgroundWorker fires the RunWorkerCompleted event.
I am using RhinoMocks (if there is another approach I am willing to try it as well) and the code is as follows:
//arrange
var bw1 = MockRepository.GenerateStub<BackgroundWorker>();
Action work1 = () => T...
Hi,
I have the following code(simplified).
public class OrderProcessor
{
public virtual string PlaceOrder(string test)
{
OrderParser orderParser = new OrderParser();
string tester = orderParser.ParseOrder(test);
return tester + " here" ;
}
}
public class OrderParser
{
public virtual string P...
If I want to mock a class that returns a string that is used to determine whether while loop should continue (imagine read while string != null), how can I set the expectation. I have tried the following:
provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20");
provider.Reader.Expect(r => r.ReadLine()).Return(null);
but wh...
Hi
I'm trying to unittest several MVP implementations and can't quite figure out the best way to mock the view. I'll try to boil it down. The view IView consists e.g. of a property of type IControl.
interface IView
{
IControl Control1 { get; }
IControl Control2 { get; }
}
interface IControl
{
bool Enabled { get; set; }
...
Given this class:
public class OrderService
{
public OrderService(IOrderLogger log)
{
this.log = log;
}
private readonly IOrderLogger log;
public void PurgeOrder(Order order)
{
...
var action = new LogAction("foo","bar");
log.Action(action);
}
}
And this test:
[Fact]
public void Purg...
This is a test suite that is green using Rhino Mocks.
[SetUp]
public void BeforeEachTest()
{
_mocksRepo = new MockRepository();
_mockBank = _mocksRepo.StrictMock<IBank>();
//_mockPrinter = _mocksRepo.StrictMock<IPrinter>();
_mockPrinter = _mocksRepo.DynamicMock<IPrinter>();
_mockLogger = _mocksRepo.Str...
Hi,
i have a class e.g. DerivedClass that inherits from a base class e.g. BaseClass. BaseClass implements an interface called IBaseClass. IBaseClass has 1 property called TestProperty which is an integer auto property.
I PartialMultiMock DerivedClass like so:
derivedClassMock = repository.PartialMultiMock<DerivedClass>(typeof(IBaseIn...
I have the following class:
public class Script
{
IPrinter _printer;
public Script(IPrinter printer)
{
_printer = printer;
}
public void Print(TextWriter writer)
{
_printer.PrintComment(writer, "lolz");
writer.WriteLine("omg this complicates things";
_printer.PrintSpecial(writer)...
Hi,
I am struggling a bit to understand how the new AAA syntax works in Rhino Mocks. Most of my tests look like this:
[Test]
public void Test()
{
//Setup
ISth sth= mocks.DynamicMock<ISth>();
//Expectations
Expect.Call(sth.A()).Return("sth");
mocks.ReplayAll();
//Execution
...
I just watched this funny YouTube Video about unit testing (it's Hitler with fake subtitles chewing out his team for not doing good unit tests--skip it if you're humor impaired) where stubs get roundly criticized. But I don't understand what wrong with stubs.
I haven't started using a mocking framework and I haven't started feeling the...
We have a VB.net function with the following signature in class InitializerFactory:
Public Shared Function Create(ByRef ui As Object) As IModeInitializer
I'm attempting to test this function by passing in a mock of ui (using Rhino Mocks):
MainForm ui = mocks.StrictMock<MainForm>();
IModeInitializer item = InitializerFactory.Create(re...
TypeMock is too expensive for a hobbist like me :)
Moq or the next version of RhinoMocks have no plans on listening to the profiling API, why is that?
EDIT: This enables features such as:
Mocking non-virtual methods and
properties (!).
Mocking browser
environments.
simpler syntax which
is less fragile (and not having to go
trough...
We are Silverlight Unit Test Framework for testing.
Which one will be better for my team? Rhino Mocks or Moq. No one has any experience with using a framework like this.
What are the pros and cons of using each framework in this environment?
...
Hi,
Is it possible to create a "strict" mock using the new AAA syntax of Rhino Mocks? The issue I am seeing is that the library I am mocking often returns null as a valid return value (which I handle in my function), so using the default mock I can never be sure if I tested all paths or I forgot to set some expectations.
...