2011-08-02 86 views
0

考慮到以下代碼是「保存」測試用例 - 我將如何編寫「刪除」測試用例?如何編寫測試用例以執行刪除操作

[Test] 
     public void Testsavesassignment() 
     { 
      var sAssignment = new SAssignment() 
      { 
       DateCreated = DateTime.Now, 
       DateUpdated = DateTime.Now, 
       Department = 9000.ToString(), 
       EmployeeId = 4342342 

      }; 
      Status status = null; 
      var assignment = this.m_personnelService.SaveSAssignment(sAssignment, out status); 
      Assert.IsTrue(status.Success); 
      Assert.AreEqual(sAssignment.EmployeeId, assignment.EmployeeId); 
      Assert.AreEqual(sAssignment.EmployeeId, assignment.DateCreated); 
      Assert.AreEqual(sAssignment.DateUpdated, assignment.DateUpdated); 
      Assert.AreEqual(sAssignment.Department, assignment.Department); 
      Assert.AreNotEqual(sAssignment.Id, assignment.Id); 

     } 
+0

一些詳細信息將是不錯的,在這一點上,我們都在猜測你的意思,寫一個刪除測試用例? – Andrew

+0

是的安德魯。刪除測試用例。 – nitinrakeysh

+0

請分享一下Delete方法的代碼 – sll

回答

0

你將不得不瞭解一下的m_personnelService底層實現,如果你希望能夠測試出刪除。

下面介紹如何使用實體框架實現單元測試(包括刪除):http://msdn.microsoft.com/en-us/library/ff714955.aspx(跳轉到標題爲「以EF爲中心的實現」的部分 - 除此之外,測試還有幾個部分) 。

+0

謝謝先生。我會那樣做 – nitinrakeysh

0

這可能有助於...

[Test] 
    public void TestDeleteAssignment() 
    { 
     //add assignment 
     var myAssignment = new SAssignment() 
     { 
      DateCreated = DateTime.Now, 
      DateUpdated = DateTime.Now, 
      Department = 9000.ToString(), 
      EmployeeId = 4342342 
     }; 

     Status addStatus = null; 
     var assignment = this.m_personnelService.SaveSAssignment(myAssignment, out addStatus); 
     Assert.IsTrue(addStatus.Success); 

     var targetAssignmentId = assignment.Id; 

     //possibility 1 
     Status deleteStatus = null; 
     var assignment2 = this.m_personnelService.DeleteSAssignment(targetAssignmentId, out deleteStatus); 
     Assert.IsTrue(deleteStatus.Success); //or Assert.AreEqual(assignment2.Id, targetAssignmentId); 


     //possibility 2 
     Status deleteStatus = null; 
     var assignment3 = this.m_personnelService.DeleteSAssignment(targetAssignmentId); 
     var result = this.m_personnelService.GetSAssignment(targetAssignmentId); 
     Assert.IsNull(result); 
    } 
相關問題