开发者

How do I write a test case to exercise a Delete operation

开发者 https://www.devze.com 2023-03-24 09:13 出处:网络
Given the following code which is the \'save\' test case - how would I write a \'Delete\' test case? [Test]

Given the following code which is the 'save' test case - how would I write a 'Delete' test case?

[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.Depa开发者_JAVA技巧rtment);
            Assert.AreNotEqual(sAssignment.Id, assignment.Id);

        }


You are going to have to know something about the underlying implementation of m_personnelService if you want to be able to test out a Delete.

Here is a walk-through of how you can implement unit testing, including deletes, with Entity Framework: http://msdn.microsoft.com/en-us/library/ff714955.aspx (jump down to the section entitled "An EF Centric Implementation" - the tests are a couple more sections beyond that).


This might help...

    [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);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消