0

I have a webtest where I am making POST request request1 for adding an item and then request2 to remove same item. Upon running I am getting following error.

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.

Maybe remove request hitting before even add is completed under DB. How can i resolve that? code below.

public override IEnumerator<WebTestRequest> GetRequestEnumerator()
    {
        WebTestRequest request1 = new WebTestRequest("https://XXXXX/XX");
        request1.ThinkTime = 1;
        request1.ReportingName = "Add Item";
        request1.ExpectedHttpStatusCode = 200;
        request1.Headers.Add(new WebTestRequestHeader("Authorization", token));
        request1.Method = "POST";


        FormPostHttpBody request1Body = new FormPostHttpBody();
        request1Body.FormPostParameters.Add("AId", "1");
        request1Body.FormPostParameters.Add("groupId", "1");

        request1.Body = request1Body;

        yield return request1;
        request1 = null;



        WebTestRequest request2 = new WebTestRequest("https://XXXXX/XX");
        request2.ThinkTime = 1;
        request2.ReportingName = "Remove Item";
        request2.ExpectedHttpStatusCode = 200;
        request2.Headers.Add(new WebTestRequestHeader("Authorization", token));
        request1.Method = "POST";

        FormPostHttpBody request2Body = new FormPostHttpBody();
        request2Body.FormPostParameters.Add("AId", "1");
        request2Body.FormPostParameters.Add("groupId", "1");

        request2.Body = request2Body;

        yield return request2;
        request2 = null;
    }
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • The test worked perfectly. You actually found an application bug - it can't handle concurrent updates and the error message contains the link to the docs that explain what happened and how to fix this. It's the *data access code* that needs changing, not the test – Panagiotis Kanavos Feb 07 '20 at 16:39
  • Unless you posted the `DELETE` operation before the web page had a chance to store the new record. How is `GetRequestEnumerator` used? You should put a small delay between iterations, so the page has a chance to process the request. Even so, the page *shouldn't* have thrown an exception. It should have handled the `DbUpdateConcurrencyException` and returned a warning to the user or at least a custom error page – Panagiotis Kanavos Feb 07 '20 at 16:42
  • @PanagiotisKanavos : Thats right! I tried same fucntion from UI and it's a bug in application. thanks for your response. You can post your comment as answer and i will mark it if you want. – Zaheer Khan Feb 12 '20 at 16:05

0 Answers0