How can i do this?

I need to develop a fairly simple algorithm, but I'm confused about how best to write a test for it.

General description: The user should be able to delete the plan. The plan has tasks associated with it, they must also be deleted (while they have not yet been completed).

Pseudo-code how the algorithm should behave:

   PlanController.DeletePlan(plan)
     =>
     PlanDbRepository.DeletePlan()
      ForEach Task t in plan.Tasks
          If t.Status = Status.Open Then
            TaskDbRepository.DeleteTask(t)
          End If
      End ForEach

Now, as I understand it, unit tests should not concern the database or generally require access to any external systems, so I assume that I have two options:

1) Retrieve the repository calls and check if they have been called the appropriate number of times, like “Claims”

2) Create stubs for both repository classes by manually setting the delete flag, and then make sure the corresponding objects are marked for deletion.

: ? EXTRA, ?

. - , RhinoMocks. , .

+5
7

, unit test, , . , , , DeleteTask ( = ). , , , , . (, unit test), , , , DeletePlan , .

+4

, , . -, .

unit test , ? , , , , .

+2

, , , . , - , , , . - , . // .

, , . DB mock delete, , .

+2

, , - , ( , , , , ).

, (.. , delete), , , , .

, :
DeletePlan?
DeleteTask ?
DeleteTask?
DeleteTask ?

: , .

+2

, , . ...

:

Plan1 {
 Task1: completed
 Task2: todo
 Task3: todo
}

delete , ?

Plan1 : ?
Task1: not deleted
Task2: deleted
Task3: deleted

plan1 , task1? ?.

, ( 1 4 : 1) Spec 2) 3) 4)

, . 2

public void DeletePlan(Plan p)
{ 
  var objectsToDelete = GetDeletedPlanObjects(p);
  DeleteObjects(objectsToDelete);
} 

. GetDeletedPlanObjects, , , .... www.approvaltests.com, : )

, Llewellyn

+1

, , . - , , "" "", - . , .

- "TaskRemovalStrategy", - .

0

IMO PlanRepository, .

, -

void DeletePlanTest()
{
    PlanRepository repo = new PlanDbRepository("connection string");
    repo.CreateNewPlan(); // create plan and populate with tasks
    AssertIsTrue(repo.Plan.OpenTasks.Count == 2); // check tasks are in open state
    repo.DeletePlan();
    AssertIsTrue(repo.Plan.OpenTasks.Count == 0);
}

, , .

, PlanDbRepository MockRepository, . , - , , , .

, , , , .

.

0
source

All Articles