c# - how to unit test a delete method using JustMock lite and MSTest? -


I am just starting with unit testing and are now stuck in writing a test method for deletion. I'm using MStest and JuckMock follow my test method to use real store and do not use JustMock to duplicate one, but in code, I'm getting value for updated customer And the test method has failed. Hope someone can tell me the right direction.

  [TestMethod] Public invalid ShouldDeleteCustomerWithIdParam () {var repo = Mock.Create & lt; ICustomerRepository & gt; (); Var Customer Service = New Customer Service (Repo); Var customer = mock.com & lt; Customers & gt; (); CustomerService.Delete (customer.Id); Var updatedCustomer = _customerService.Get (customer.Id); Confirm. IsNull (Updated customer, "Customer has not been removed"); }    

a short answer and a long time :)

As told by @Lilisseste, you are working with two different repository objects, your customer object is removed from one of them and then tries to get it from the second place, possibly at the first place. Not being added

There is a fairly thin wrap around the Customer Service Assumption Customer Repository , after testing it all after testing it Actually it will be run through CustomerService.Delete and check this calls the customer repository. The problem is two times with

  1. You are testing how this is a class work, not < / Em> class

  2. When this code goes without it, about the customer service for testing this class and test Need to know things A fake, I believe that you are using an ORM or ADO.NET, actually deleting an item from your data store - that the behavior you want to make sure, but you It's joking about a test that "works to remove customers!" But that does not really test the real customer deletion code, it can be misleading. Keeping this in mind, I would not say that the test you are writing is actually buying you too much. I recommend changing it to an integration test that actually kills your data store and uses the actual delete code.

    The unique test has been written about the treasure.



Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -