コード例 #1
0
        public void BTA375_REST_PostMemberToTargetedPromotion_POSITIVE()
        {
            testCase        = new TestCase(TestContext.TestName);
            listOfTestSteps = new List <TestStep>();
            testStep        = new TestStep();
            String stepName = "";
            Common common   = new Common(this.DriverContext);
            REST_Service_Methods rest_Service_Method = new REST_Service_Methods(common);
            JObject response;

            try
            {
                Logger.Info("Test Method Started");
                testStep = TestStepHelper.StartTestStep(testStep);
                stepName = "Adding member through rest service";
                JObject member = (JObject)rest_Service_Method.PostMembergeneral();
                var     k      = member.Value <string>("isError");
                Logger.Info(k.GetType());
                Logger.Info(member.Value <string>("isError"));
                if (member.Value <string>("isError") == "False")
                {
                    testStep.SetOutput("Member is added through PostMember service and following are the details, IPCODE:= " + member["data"].Value <int>("id") + "; Name= " + member["data"].Value <string>("firstName"));;
                    testStep = TestStepHelper.EndTestStep(testCase, testStep, stepName, true, DriverContext.SendScreenshotImageContent("API"));
                    listOfTestSteps.Add(testStep);
                }
                else
                {
                    testStep.SetOutput("PostMember service call failed with following developer message: \"" + member.Value <string>("developerMessage") + "\"");
                    testStep = TestStepHelper.EndTestStep(testCase, testStep, stepName, false, DriverContext.SendScreenshotImageContent("API"));
                    listOfTestSteps.Add(testStep);
                    Logger.Info("test  failed");
                    throw new Exception(member.Value <string>("developerMessage"));
                }

                testStep = TestStepHelper.StartTestStep(testStep);
                stepName = "Adding targeted promotion through rest service by providing the member.firstName and options.promotionCode as parameter";
                response = (JObject)rest_Service_Method.PostMemberToTargetedPromotion(member["data"].Value <string>("firstName"), DatabaseUtility.GETRecentPromotionfromDBREST());
                if (response.Value <string>("isError") == "False")
                {
                    testStep.SetOutput("The following promotion with ; memberpromotionID: " + response["data"].Value <int>("id") +
                                       "; Promotion ID : " + response.SelectToken("data.promotion").Value <string>("id") +
                                       "; Promotion name: " + response.SelectToken("data.promotion").Value <string>("name") +
                                       "; has been added to the member : " + member["data"].Value <string>("firstName"));
                    testStep = TestStepHelper.EndTestStep(testCase, testStep, stepName, true, DriverContext.SendScreenshotImageContent("API"));
                    listOfTestSteps.Add(testStep);

                    testStep = TestStepHelper.StartTestStep(testStep);
                    stepName = "Validating data with data from database";
                    string dbresponse = DatabaseUtility.GetMemberPromotionsUsingIpcodefromDBREST(member["data"].Value <int>("id") + "");
                    testStep.SetOutput("Response from DB  memberpromotionID  " + dbresponse);
                    Assert.AreEqual(response["data"].Value <int>("id") + "", dbresponse, "Expected value is " + response["data"].Value <int>("id") + " and actual value is " + dbresponse);
                    testStep = TestStepHelper.EndTestStep(testCase, testStep, stepName, true, DriverContext.SendScreenshotImageContent("API"));
                    listOfTestSteps.Add(testStep);
                    testCase.SetStatus(true);
                }
                else
                {
                    Logger.Info("test failed");
                    testStep.SetOutput(response.Value <string>("developerMessage"));
                    testStep = TestStepHelper.EndTestStep(testCase, testStep, stepName, false, DriverContext.SendScreenshotImageContent("API"));
                    listOfTestSteps.Add(testStep);
                    throw new Exception(response.Value <string>("developerMessage"));
                }
            }
            catch (Exception e)
            {
                testStep = TestStepHelper.EndTestStep(testCase, testStep, stepName, true, DriverContext.SendScreenshotImageContent("API"));
                listOfTestSteps.Add(testStep);
                testCase.SetStatus(false);
                testCase.SetErrorMessage(e.Message);
                Assert.Fail(e.Message);
            }
            finally
            {
                testCase.SetTestCaseSteps(listOfTestSteps);
                testCase.SetEndTime(new StringHelper().GetFormattedDateTimeNow());
                listOfTestCases.Add(testCase);
            }
        }