public void SuperStudentDiscountAmountOneDriver() { #region Define Inputs InputDefinition age = new InputDefinition(inputName: "DriverAge", defaultValue: 29, exerciseValues: new object[] { 29, 30, 31 }); InputDefinition gpa = new InputDefinition(inputName: "GPA", defaultValue: 3.50, exerciseValues: new object[] { 3.50, 3.49, 3.51, 3.79, 3.80, 3.81, 4.0 }); InputDefinition studentStatus = new InputDefinition(inputName: "StudentStatus", defaultValue: "College", exerciseValues: new object[] { "College", "HighSchool", "None" }); InputDefinition maritialStatus = new InputDefinition(inputName: "MaritialStatus", defaultValue: "Single", exerciseValues: new object[] { "Single", "Married", "Divorced", "Separated" }); InputDefinition violation = new InputDefinition(inputName: "ViolationStatus", defaultValue: "None", exerciseValues: new object[] { "None", "Speeding", "AtFaultAccident", "WrongWay" }); InputDefinition relationship = new InputDefinition(inputName: "Relationship", defaultValue: "Child", exerciseValues: 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 <SuperStudentGPADiscountOneDriverTestCase>(1); #endregion #region Setup Oracle and Results Logging //Instantiate oracle class SuperStudentGPADiscountOracle myOracle = new SuperStudentGPADiscountOracle(); bool testCaseHasFailure = false; //Used to log results StringBuilder resultMessageSb = new StringBuilder(); StringResultsWriter.AddHeaders <SuperStudentGPADiscountOneDriverTestCase>(resultMessageSb); #endregion #region Execute Test Cases and Log Results foreach (SuperStudentGPADiscountOneDriverTestCase tc in testCases) { #region Get Expected Results From Oracle and Get Actual Results From SUT double discountAmountActual = GetDiscountAmountValueFromSUT(tc); double discountAmountExpected = myOracle.DiscountAmount(tc); #endregion #region Compare Expected VS Actual and Log Result Differences if (!discountAmountExpected.Equals(discountAmountActual)) { StringResultsWriter.AddRow <SuperStudentGPADiscountOneDriverTestCase>(tc, resultMessageSb); //log failures only\ resultMessageSb.Append($"OUTPUT: Expected <{discountAmountExpected}> but was <{discountAmountActual}>"); testCaseHasFailure = true; } #endregion } #endregion Assert.IsFalse(testCaseHasFailure, resultMessageSb.ToString()); }
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()); }
public void SuperStudentDiscountAmountMultipleDrivers() { #region Define Inputs InputDefinition gpa1 = new InputDefinition(inputName: "Driver1GPA", defaultValue: 3.50, exerciseValues: new object[] { 3.50, 3.49, 3.51, 3.79, 3.80, 3.81, 4.0 }); InputDefinition gpa2 = new InputDefinition(inputName: "Driver2GPA", defaultValue: 3.50, exerciseValues: new object[] { 3.50, 3.49, 3.51, 3.79, 3.80, 3.81, 4.0 }); InputDefinition gpa3 = new InputDefinition(inputName: "Driver3GPA", defaultValue: 3.50, exerciseValues: new object[] { 3.50, 3.49, 3.51, 3.79, 3.80, 3.81, 4.0 }); List <InputDefinition> inputs = new List <InputDefinition> { gpa1, gpa2, gpa3 }; #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 <SuperStudentGPADiscountMultiDriverTestCase>(1); #endregion #region Setup Oracle and Results Logging //Instantiate oracle class SuperStudentGPADiscountOracle myOracle = new SuperStudentGPADiscountOracle(); bool testCaseHasFailure = false; //Used to log results StringBuilder resultMessageSb = new StringBuilder(); StringResultsWriter.AddHeaders <SuperStudentGPADiscountMultiDriverTestCase>(resultMessageSb); #endregion #region Execute Test Cases and Log Results foreach (SuperStudentGPADiscountMultiDriverTestCase tc in testCases) { #region Get Expected Results From Oracle and Get Actual Results From SUT double discountAmountActual = GetDiscountAmountValueFromSUT(tc); double discountAmountExpected = myOracle.DiscountAmountWithMultipleDrivers(GetMultiDriverSUTData(tc)); #endregion #region Compare Expected VS Actual and Log Result Differences if (!discountAmountExpected.Equals(discountAmountActual)) { StringResultsWriter.AddRow <SuperStudentGPADiscountMultiDriverTestCase>(tc, resultMessageSb); //log failures only resultMessageSb.Append($"OUTPUT: Expected <{discountAmountExpected}> but was <{discountAmountActual}>"); testCaseHasFailure = true; } #endregion } #endregion Assert.IsFalse(testCaseHasFailure, resultMessageSb.ToString()); }
public void TwoFatOneInputTest() { InputDefinition intDef = new InputDefinition("Int", 1, new object[] { 1, 2, 3 }); TestComboGen gen = new TestComboGen(new List <InputDefinition>() { intDef }); string exceptionMessage = string.Empty; try { var testCases = gen.GenerateNfatTestCases <ComboGenOneInputTestCase>(2); } catch (ApplicationException e) { exceptionMessage = e.Message; } Assert.AreEqual("2-FAT was selected which exceeds the number of inputs provided: 1. Please select 1-FAT or lower.", exceptionMessage); }
public void ThreeFatTwoInputsTest() { InputDefinition intDef = new InputDefinition("Int", 1, new object[] { 1, 2, 3 }); InputDefinition doubleDef = new InputDefinition("Double", 1.0, new object[] { 1.0, 2.0, 3.0 }); TestComboGen gen = new TestComboGen(new List <InputDefinition>() { intDef, doubleDef }); string exceptionMessage = string.Empty; try { var testCases = gen.GenerateNfatTestCases <ComboGenTwoInputTestCase>(3); } catch (ApplicationException e) { exceptionMessage = e.Message; } Assert.AreEqual("3-FAT was selected which exceeds the number of inputs provided: 2. Please select 2-FAT or lower.", exceptionMessage); }
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()); }