Exemplo n.º 1
0
        public async Task SuperStudentDiscountAmountAsync()
        {
            #region Define Inputs
            InputDefinition        gpa    = new InputDefinition("DriverGPA", 3.50, new object[] { 3.49, 3.50, 3.51, 3.79, 3.80, 3.81, 4.0 });
            List <InputDefinition> inputs = new List <InputDefinition> {
                gpa
            };
            #endregion

            #region Setup Combination Generator and Generate Test Cases
            //Pass inputs to combination generator and select technique
            TestComboGen testComboGen = new TestComboGen(inputs);
            var          testCases    = testComboGen.GenerateNfatTestCases <SuperStudentDiscountApiTestCase>(1);
            #endregion

            #region Setup Oracle and Results Logging
            //Instantiate oracle class
            SuperStudentDiscountOracle myOracle = new SuperStudentDiscountOracle();
            bool hasFailures = false;

            //Used to log results
            StringBuilder results = new StringBuilder();
            StringResultsWriter.AddHeaders <SuperStudentDiscountApiTestCase>(results);
            #endregion

            #region Execute Test Cases and Log Results
            foreach (SuperStudentDiscountApiTestCase tc in testCases)
            {
                #region Get Expected Results From Oracle and Get Actual Results From SUT
                var responseMessage = await TestCaseToHttpConverter.ConvertTestCaseToHttpPOST <SuperStudentDiscountApiTestCase>("http://54.210.38.124/service/superstudentdiscount", tc);

                SuperStudentDiscountResult discountResult = JsonConvert.DeserializeObject <SuperStudentDiscountResult>(await responseMessage.Content.ReadAsStringAsync());
                double discountAmountActual   = discountResult.DiscountAmount;
                double discountAmountExpected = myOracle.DiscountAmount(tc);
                #endregion

                #region Compare Expected VS Actual and Log Result Differences
                if (!discountAmountExpected.Equals(discountAmountActual))
                {
                    StringResultsWriter.AddRow <SuperStudentDiscountApiTestCase>(tc, results); //log failures only
                    results.Append($"OUTPUT: Expected <{discountAmountExpected}> but was <{discountAmountActual}>");
                    hasFailures = true;
                }
                #endregion
            }
            #endregion

            Assert.True(!hasFailures, results.ToString());
        }
Exemplo n.º 2
0
        public async Task SuperStudentQualifiesForDiscountAsync()
        {
            #region Define Inputs
            InputDefinition state          = new InputDefinition("State", "OH", new object[] { "OH", "AZ", "CO" });
            InputDefinition age            = new InputDefinition("DriverAge", 29, new object[] { 29, 30, 31 });
            InputDefinition gpa            = new InputDefinition("DriverGPA", 3.50, new object[] { 3.50, 3.49, 3.51, 3.79, 3.80, 3.81, 4.0 });
            InputDefinition studentStatus  = new InputDefinition("StudentStatus", "College-enrolled", new object[] { "College-enrolled", "HighSchool-graduated", "None" });
            InputDefinition maritialStatus = new InputDefinition("MaritalStatus", "Single", new object[] { "Single", "Married", "Divorced", "Separated" });
            InputDefinition violation      = new InputDefinition("Violations", new List <string> {
            }, new List <List <string> > {
                new List <string> {
                }, new List <string> {
                    "Speeding", "AtFault"
                }, new List <string> {
                    "Comp"
                }
            });
            InputDefinition        relationship = new InputDefinition("Relationship", "Child", new object[] { "Child", "NamedInsured", "Spouse", "Other" });
            List <InputDefinition> inputs       = new List <InputDefinition> {
                age, gpa, studentStatus, maritialStatus, violation, relationship
            };
            #endregion

            #region Setup Combination Generator and Generate Test Cases
            //Pass inputs to combination generator and select technique
            TestComboGen testComboGen = new TestComboGen(inputs);
            var          testCases    = testComboGen.GenerateNfatTestCases <SuperStudentDiscountApiTestCase>(1);
            #endregion

            #region Setup Oracle and Results Logging
            //Instantiate oracle class
            SuperStudentDiscountOracle myOracle = new SuperStudentDiscountOracle();
            bool hasFailures = false;

            //Used to log results
            StringBuilder results = new StringBuilder();
            StringResultsWriter.AddHeaders <SuperStudentDiscountApiTestCase>(results);
            #endregion

            #region Execute Test Cases and Log Results
            foreach (SuperStudentDiscountApiTestCase tc in testCases)
            {
                #region Get Expected Results From Oracle and Get Actual Results From SUT
                var responseMessage = await TestCaseToHttpConverter.ConvertTestCaseToHttpPOST <SuperStudentDiscountApiTestCase>("http://54.210.38.124/service/superstudentdiscount", tc);

                SuperStudentDiscountResult discountResult = JsonConvert.DeserializeObject <SuperStudentDiscountResult>(await responseMessage.Content.ReadAsStringAsync());
                bool qualifiesForDiscountActual           = discountResult.DiscountGranted;
                bool qualifiesForDiscountExpected         = myOracle.QualifiesForDiscount(tc);
                #endregion

                #region Compare Expected VS Actual and Log Result Differences
                if (!qualifiesForDiscountExpected.Equals(qualifiesForDiscountActual))
                {
                    StringResultsWriter.AddRow <SuperStudentDiscountApiTestCase>(tc, results); //log failures only
                    results.Append($"OUTPUT: Expected <{qualifiesForDiscountExpected}> but was <{qualifiesForDiscountActual}>");
                    hasFailures = true;
                }
                #endregion
            }
            #endregion

            Assert.True(!hasFailures, results.ToString());
        }