I understand the basics of unit testing, although I often have to struggle to find meaningful things to do the test. is. I believe I have to make a fake implementation and put it in the consumer. I have a service class that is responsible for subscribing (using Exchange Web Services (EWS)) Exchange 2010 is requesting updates on new mail. To reduce the implementation of subscribing to the service, Decided to implement the implementation. Below I am currently in what I have exclusively left the code communicating with the exchange.
// There is no big fan for having two identical interfaces ... Public Interface Error Notification Service {Zero Subscription (); } Public Interface IExchangeService {Zero Subscribe (); } Public Class Streaming Notification Service: IT Streaming Notification Service {Private Readonly IEX Services Service _ Exchange Service; Public Streaming Notification Service (IExchangeService ExchangeService) {If (Exchange Service == Free) {New Logic (NullException) ("Exchange Service"); } _exchangeService = exchangeService; } Subscribe to Public Zero () {_exchangeService.Subscribe (); }} Public class ExchangeServiceImpl: IExchangeService {Private Redondly International Configuration _ Network Configuration; Private Exchange Service Exchange Service {Receive; Set; } Public ExchangeServiceImpl (Incoming Configuration Network Configuration) {If (Network Configuration == Empty) {New Logic (NullException) ("Network Configuration"); } _networkconfigured = network configuration; // set up EWS} subscribe to public zeros () {// subscribe to new mail notifications}} More specifically, to ensure the way to subscribe I How do I create a meaningful unit test?
Usually you will use a funny framework for fake exchange and on this object Check that membership was actually called. I generally use, and your test will look for example in this way (there are several ways to apply it):
[test] Public Zero SubscribesToExchange () {var exchange = MockRepository.GenerateMock & lt; IExchangeService & gt; (); // This is stub ware service = streaming notification service (exchange); // This is the object that we are testing the service. Subscribe (); Service.AssertWasCalled (x = & gt; x.Subscribe ();); }
Comments
Post a Comment