A short answer and a longer one :)
As pointed out by @Lilshieste, you're working with two different repository objects. Your customer object is deleted from one of them and then attempted to be retrieved from the other, possibly without ever being added to the other in the first place.
You may want to take another look at what you're testing here. Assuming CustomerService
is a fairly thin wrapper around CustomerRepository
, all this test would really do once it was complete is run code through CustomerService.Delete
and check it calls CustomerRepository.Delete
. The problem with this is two-fold:
You're testing how a class does it's job, not what the class does. This couples the test to the class and requires the test to know things about
CustomerService
which are really none of its business.When this code runs without a mock, I assume you're using an ORM or ADO.NET to actually delete an item from your data store - that's the behaviour you want to be sure works, but you're mocking it out. Having a test which says "Deleting Customers works!" but which doesn't actually test the real customer deletion code could be deceptive.
With this in mind, I wouldn't say the test you're writing actually buys you very much. I'd recommend changing it to an integration test which actually hits your data store and exercises the real delete code.
Jimmy Bogard's written about unit testing repositories here.