private TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) { var testMethod = new TestMethod(canonicalData, canonicalDataCase); UpdateTestMethod(testMethod); return(testMethod); }
protected override TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase, int index) { var testMethod = base.CreateTestMethod(canonicalDataCase, index); testMethod.Skip = false; return(testMethod); }
protected TestMethodBody(CanonicalDataCase canonicalDataCase, CanonicalData canonicalData) { CanonicalDataCase = canonicalDataCase; CanonicalData = canonicalData; Data = new TestMethodBodyData(this); InitializeTemplateParameters(); }
private string RenderTestMethodBody(CanonicalDataCase canonicalDataCase) { var testMethodBody = CreateTestMethodBody(canonicalDataCase); testMethodBody.Arrange = RenderTestMethodBodyArrange(testMethodBody); testMethodBody.Act = RenderTestMethodBodyAct(testMethodBody); testMethodBody.Assert = RenderTestMethodBodyAssert(testMethodBody); return(testMethodBody.Render()); }
protected virtual TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = CreateTestMethodData(canonicalData, canonicalDataCase, index); if (testMethodData.CanonicalDataCase.Expected is JObject jObject) { return(CreateExceptionTestMethod(testMethodData)); } return(CreateTestMethod(testMethodData)); }
public TestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) { Input = new Dictionary <string, dynamic>(canonicalDataCase.Input, StringComparer.OrdinalIgnoreCase); Expected = canonicalDataCase.Expected; Property = canonicalDataCase.Property; TestMethodName = canonicalDataCase.Description.ToTestMethodName(); TestMethodNameWithPath = string.Join(" - ", canonicalDataCase.DescriptionPath).ToTestMethodName(); TestedClass = canonicalData.Exercise.ToTestedClassName(); TestedMethod = canonicalDataCase.Property.ToTestedMethodName(); Skip = canonicalDataCase.Index > 0; InputParameters = canonicalDataCase.Input.Keys.ToArray(); }
private static void SetCreatePropertyData(CanonicalDataCase canonicalDataCase) { var validExpected = canonicalDataCase.Expected >= 0; canonicalDataCase.UseVariableForTested = validExpected; canonicalDataCase.ExceptionThrown = validExpected ? null : typeof(ArgumentOutOfRangeException); canonicalDataCase.Description = validExpected ? canonicalDataCase.Description + " does not throw exception" : canonicalDataCase.Description; var coordinates = GetCoordinatesFromPosition(canonicalDataCase.Input["queen"]); canonicalDataCase.Properties["X"] = coordinates.Item1; canonicalDataCase.Properties["Y"] = coordinates.Item2; canonicalDataCase.SetInputParameters("X", "Y"); }
protected virtual TestMethodBody CreateTestMethodBody(CanonicalDataCase canonicalDataCase) { if (canonicalDataCase.ExceptionThrown != null) { return(new TestMethodBodyWithExceptionCheck(canonicalDataCase, _canonicalData)); } if (canonicalDataCase.Expected is bool) { return(new TestMethodBodyWithBooleanCheck(canonicalDataCase, _canonicalData)); } if (canonicalDataCase.Expected is null) { return(new TestMethodBodyWithNullCheck(canonicalDataCase, _canonicalData)); } return(new TestMethodBodyWithEqualityCheck(canonicalDataCase, _canonicalData)); }
public TestMethodBodyWithBooleanCheck(CanonicalDataCase canonicalDataCase, CanonicalData canonicalData) : base(canonicalDataCase, canonicalData) { AssertTemplateName = "AssertBoolean"; AssertTemplateParameters = new { BooleanAssertMethod, Data.TestedValue }; }
public TestMethodBodyWithExceptionCheck(CanonicalDataCase canonicalDataCase, CanonicalData canonicalData) : base(canonicalDataCase, canonicalData) { AssertTemplateName = "AssertThrowsException"; AssertTemplateParameters = new { ExceptionType, Data.TestedValue }; }
private static string[] GetInputParameters(CanonicalDataCase canonicalDataCase, string constructorParamName) => canonicalDataCase.Input.Keys.Where(x => x != constructorParamName).ToArray();
public TestMethodBodyWithNullCheck(CanonicalDataCase canonicalDataCase, CanonicalData canonicalData) : base(canonicalDataCase, canonicalData) { AssertTemplateName = "AssertNull"; AssertTemplateParameters = new { Data.TestedValue }; }
protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); testMethodData.CanonicalDataCase.Property = "ToRoman"; testMethodData.CanonicalDataCase.Description = "Number_" + testMethodData.CanonicalDataCase.Description; return(testMethodData); }
private static dynamic ConvertExpected(CanonicalDataCase canonicalDataCase) => ((Dictionary <string, object>)canonicalDataCase.Expected).ToDictionary(kv => kv.Key[0], kv => int.Parse(kv.Value.ToString()));
private static string RenderSut(CanonicalDataCase canonicalDataCase) { var capacity = canonicalDataCase.Input["capacity"]; return($"var buffer = new CircularBuffer<int>(capacity: {capacity});"); }
protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); testMethodData.Options.UseVariableForExpected = true; testMethodData.Options.FormatExpected = true; testMethodData.CanonicalDataCase.Expected = CanonicalDataValue.ExpectedToMultiLineString(testMethodData.CanonicalDataCase.Expected); if (testMethodData.CanonicalDataCase.Property == "verse") { testMethodData.Options.InputProperty = "number"; } else { testMethodData.CanonicalDataCase.Input = new[] { testMethodData.CanonicalDataCase.Data["beginning"], testMethodData.CanonicalDataCase.Data["end"] } }; return(testMethodData); } }
private static string ToTestMethodName(CanonicalDataCase canonicalDataCase) => canonicalDataCase.UseFullDescriptionPath ? string.Join(" - ", canonicalDataCase.DescriptionPath).ToTestMethodName() : canonicalDataCase.Description.ToTestMethodName();
protected virtual TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase, int index) => new TestMethod { Skip = index > 0, Name = ToTestMethodName(canonicalDataCase), Body = RenderTestMethodBody(canonicalDataCase) };
private string RenderTestMethod(CanonicalDataCase canonicalDataCase, int index) => CreateTestMethod(canonicalDataCase, index).Render();
private static dynamic ConvertExpected(CanonicalDataCase canonicalDataCase) { Dictionary <string, object> expected = canonicalDataCase.Expected; return(expected.ToDictionary(kv => kv.Key[0], kv => int.Parse(kv.Value.ToString()))); }
protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodOptions = new TestMethodOptions(); testMethodOptions.InputProperty = "number"; testMethodOptions.TestedMethodType = TestedMethodType.Extension; return(testMethodOptions); }
protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) => new TestMethodData { CanonicalData = canonicalData, CanonicalDataCase = canonicalDataCase, Index = index, Options = CreateTestMethodOptions(canonicalData, canonicalDataCase, index) };
protected virtual TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) => new TestMethodOptions();
public TestMethodBodyWithEqualityCheck(CanonicalDataCase canonicalDataCase, CanonicalData canonicalData) : base(canonicalDataCase, canonicalData) { AssertTemplateName = ExpectedIsEmptyEnumerable ? "AssertEqual_Empty" : "AssertEqual"; AssertTemplateParameters = new { Data.ExpectedParameter, Data.TestedValue }; }
protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); testMethodData.Options.UseVariableForExpected = true; testMethodData.CanonicalDataCase.Expected = CanonicalDataValue.ExpectedToMultiLineString(testMethodData.CanonicalDataCase.Expected); if (testMethodData.CanonicalDataCase.Data.ContainsKey("end verse")) { testMethodData.CanonicalDataCase.Input = new[] { testMethodData.CanonicalDataCase.Data["start verse"], testMethodData.CanonicalDataCase.Data["end verse"] } } ; else { testMethodData.Options.InputProperty = "start verse"; } return(testMethodData); }
protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); testMethodOptions.ThrowExceptionWhenExpectedValueEquals = x => x is bool; return(testMethodOptions); }
protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); testMethodData.Options.ExceptionType = typeof(ArgumentOutOfRangeException); testMethodData.Options.FormatExpected = false; if (testMethodData.CanonicalDataCase.Expected is string classificationType) { testMethodData.CanonicalDataCase.Expected = GetClassification(classificationType); } return(testMethodData); }
protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); testMethodOptions.InputProperty = "phrase"; return(testMethodOptions); }