I'm a little confused by your test since you are not really testing anything except that RhinoMocks works. You create two mocks and then do some assertions on them. You haven't even tested your real classes You need to do some dependency injection if you really want to get a good unit test.
You can quickly refactor your code to use interfaces and dependency injection to make your test valid Start by extracting an interface from your OrderParser class: public interface IOrderParser { String ParseOrder(String value); } Now make sure your OrderParser class implements that interface: public class OrderParser: IOrderParser{ ... } You can now refactor your OrderProcessor class to take in an instance of an IOrderParser object through its constructor. In this way you "inject" the dependency into the class public class OrderProcessor { IOrderParser _orderParser; public OrderProcessor(IOrderParser orderParser) { _orderParser = orderParser; } public virtual string PlaceOrder(string val) { string tester = _orderParser. ParseOrder(val); return tester + " here" ; } } In your test you only want to mock out the dependency and not the SUT (Subject Under Test).
Your test would look something like this: public class OrderTest { public void TestParser() { // Arrange var spec = MockRepository.GenerateMock(); var client = new OrderProcessor(spec); spec. Stub(x => x. ParseOrder("test")).IgnoreArguments().
Return("Test1"); //Act var s = client. PlaceOrder("Blah"); //Assert Assert. AreEqual("Test1 Here", s); } } It is difficult for me to gauge what you are trying to do with your classes, but you should be able to get the idea from this.
A few axioms to follow: Use interfaces and composition over inheritance Use dependency injection for external dependencies (inversion of control) Test a single unit, and mock its dependencies Only mock one level of dependencies. If you are testing class X which depends on Y which depends on Z, you should only be mocking Y and never Z Always test behavior and never implementation details You seem to be on the right track, but need a little guidance. I would suggest reading material that Martin Fowler and Bob Martin have to get up to speed.
I'm a little confused by your test since you are not really testing anything except that RhinoMocks works. You create two mocks and then do some assertions on them. You haven't even tested your real classes.
You need to do some dependency injection if you really want to get a good unit test. You can quickly refactor your code to use interfaces and dependency injection to make your test valid. Start by extracting an interface from your OrderParser class: public interface IOrderParser { String ParseOrder(String value); } Now make sure your OrderParser class implements that interface: public class OrderParser: IOrderParser{ ... } You can now refactor your OrderProcessor class to take in an instance of an IOrderParser object through its constructor.In this way you "inject" the dependency into the class.
Public class OrderProcessor { IOrderParser _orderParser; public OrderProcessor(IOrderParser orderParser) { _orderParser = orderParser; } public virtual string PlaceOrder(string val) { string tester = _orderParser. ParseOrder(val); return tester + " here" ; } } In your test you only want to mock out the dependency and not the SUT (Subject Under Test). Your test would look something like this: public class OrderTest { public void TestParser() { // Arrange var spec = MockRepository.GenerateMock(); var client = new OrderProcessor(spec); spec.
Stub(x => x. ParseOrder("test")).IgnoreArguments(). Return("Test1"); //Act var s = client.
PlaceOrder("Blah"); //Assert Assert. AreEqual("Test1 Here", s); } } It is difficult for me to gauge what you are trying to do with your classes, but you should be able to get the idea from this. A few axioms to follow: Use interfaces and composition over inheritance Use dependency injection for external dependencies (inversion of control) Test a single unit, and mock its dependencies Only mock one level of dependencies.
If you are testing class X which depends on Y which depends on Z, you should only be mocking Y and never Z. Always test behavior and never implementation details You seem to be on the right track, but need a little guidance. I would suggest reading material that Martin Fowler, and Bob Martin have to get up to speed.
I'm a little confused by your test since you are not really testing anything except that RhinoMocks works. You create two mocks and then do some assertions on them. You haven't even tested your real classes.
You need to do some dependency injection if you really want to get a good unit test. You can quickly refactor your code to use interfaces and dependency injection to make your test valid. You can now refactor your OrderProcessor class to take in an instance of an IOrderParser object through its constructor.
In this way you "inject" the dependency into the class. In your test you only want to mock out the dependency and not the SUT (Subject Under Test). It is difficult for me to gauge what you are trying to do with your classes, but you should be able to get the idea from this.
Only mock one level of dependencies. If you are testing class X which depends on Y which depends on Z, you should only be mocking Y and never Z. You seem to be on the right track, but need a little guidance.
I would suggest reading material that Martin Fowler, and Bob Martin have to get up to speed.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.