Thinking OO with TDD - where to start?

I try to improve my TDD / OO skills, and every time I try to use TDD to influence design, I come across a wall of where to start.

Here is my usage example / story:

Identify the subset of clients to be viewed. Start a review for them and send a couple of letters.

Now my muscle memory has already opened a request window, wrote a request, designed a user interface, and then I had to write code to glue the bits together.

I want the domain code to be the focus, and I want it to be under the test.

So what is the simplest in this case?

I think I need my list of Clients. I already have a client object (CSLA style), although it does have dependency dependencies that are hard to break. I assume that I can have a ClientReviewClients object and verify that I am getting the correct number of reviews. There are a number of factors that I need to consider, so this does not seem simple. And in general, how do I mock the fact that I have 10 reviews from 20 clients?

Can someone help me on my way?

+3
source share
3 answers

Here - I will start with two tests:

class IdentifyClientsDueForReview {
   public void CanStartSearch() {
      var s = new ClientSearcher();
   }

   public void CanSearchClients() {
      var s = new ClientSearcher();
      var r = s.Find(c => c.Id == 1);
      Assert.IsNotNull(r);
   }

   public void Finds10Clients() {
      var db = new MockDB();
      // Clients that need review
      for (int i = 0; i < 10; i++) {
         db.Add(new Client() { 
            NextReview = DateTime.Today.SubtractDays(i) 
         });
      }
      // Clients that don't need review
      for (int i = 0; i < 10; i++) {
         db.Add(new Client() { 
            NextReview = DateTime.Today.AddDays(i) 
         });
      }

      var s = new ClientSearcher(db);
      var r  = s.Find(c => c.NextReview <= DateTime.Today);
      Assert.AreEqual(10, r.Count);
   }
}

Linq To Sql ORM- - , , Find FindBy<Criteria>.

ClientSearcher, . MockDB RealDB .

+4

. , ( ), unit test.

, , , , 10 20, , , , -?

: "TDD/Using Mock objects with CSLA.Net":

, . , .

+1

#, , , .

TDD, - . , , - . , - : Client.initiate_reviews

, , ( , ). Client.initiate_reviews, , , , , , ?

, , .

, . , :

clients = Client.find_all_due_for_review
for_each client in clients {
    review = Review.start_new_for(client)
    Letter.send_for_review(review)
}

Then I wrote tests for the methods called in this method that I have to implement. Find_all_due_for_review has no side effects, but return something, so of course you check the return value here and maybe nothing has changed. Repeat until the first test is completed.

This way, every aspect is properly tested, and you can even use some methods that you can reuse.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1711256/


All Articles