I think part of your problem may be in the design of your order object. Trying to write a free test, only to find that it relies on other functions, usually indicates that they are not sufficiently untied. A few rules of thumb that may be relevant here:
If Order.DeliveryAddress is just a simple getter / setter, don't worry about testing it. This is similar to trying to prove that C # behaves as it should. There are few advantages for this. Conversely, if your dispatch test relies on this property, which is in working condition, is not really a dependency.
However, if Order.DeliveryAddress follows the logic, for example, ensuring that the address can only be changed for unmanaged orders, then this is more complicated. You probably do not want to try to submit the entire order to verify that Order.DeliveryAddress is no longer subject to change.
Invoking the principle of single responsibility (see 1 and 2 ) here will say that the Order class now does too much. This is both sending orders and enforcing the integrity of order data. In this case, you probably want to split the dispatching functionality into a DispatcherService, which simply takes the order and sends it, setting the IsDispatched flag in order in this process.
You can then test the DeliveryAddress behavior by simply setting the IsDispatched property accordingly.
The third approach (which is a kind of trick, but works well in situations where you are trying to get some testing on obsolete objects) is to subclass Order to create the TestableOrder class, which gives the test fixture the opportunity to tinker with the internal state of the class. In other words, it can produce a MarkAsDispatched () method that sets the internal flags of the IsDispatched classes and thus allows you to verify that DeliveryAddress is configured only before it is marked as sent.
Hope this helps.
Kenneth Baltrinic
source share