public void TestSpecInitialize(TestResources resources) { TestSpec = resources.GetSpecForContext(TestContext); }
private static string GetMessage(TestModel spec) { return($"Input: \"{spec.Input}\""); }
public void TestNumberWithUnit(TestModel testSpec) { TestPreValidation(testSpec); ValidateResults(testSpec, new[] { ResolutionKey.Unit, ResolutionKey.SubType }); }
public void TestCurrency(TestModel testSpec) { TestPreValidation(testSpec); ValidateResults(testSpec, new[] { ResolutionKey.Unit, ResolutionKey.IsoCurrency }); }
public void TestChoice(TestModel testSpec) { TestPreValidation(testSpec); ValidateResults(testSpec, new string[] { ResolutionKey.Value, ResolutionKey.Score }); }
private void ValidateResults(TestModel testSpec, IEnumerable <string> testResolutionKeys = null) { var actualResults = TestContext.GetModelParseResults(testSpec); var expectedResults = testSpec.CastResults <ModelResult>(); Assert.AreEqual(expectedResults.Count(), actualResults.Count, GetMessage(testSpec)); foreach (var(expected, actual) in Enumerable.Zip(expectedResults, actualResults, Tuple.Create)) { Assert.AreEqual(expected.TypeName, actual.TypeName, GetMessage(testSpec)); Assert.AreEqual(expected.Text, actual.Text, GetMessage(testSpec)); // Number and NumberWithUnit are supported currently. if (expected.Start != Constants.InvalidIndex) { Assert.AreEqual(expected.Start, actual.Start, GetMessage(testSpec)); } // Number and NumberWithUnit are supported currently. if (expected.End != Constants.InvalidIndex) { Assert.AreEqual(expected.End, actual.End, GetMessage(testSpec)); } if (testSpec.IgnoreResolution) { Assert.Inconclusive(GetMessage(testSpec) + ". Resolution not validated."); } else { if (expected.TypeName.Contains(Number.Constants.MODEL_ORDINAL)) { if (!expected.TypeName.Equals(Number.Constants.MODEL_ORDINAL_RELATIVE)) { Assert.AreEqual(expected.Resolution[ResolutionKey.Value], actual.Resolution[ResolutionKey.Value], GetMessage(testSpec)); } Assert.AreEqual(expected.Resolution[ResolutionKey.Offset], actual.Resolution[ResolutionKey.Offset], GetMessage(testSpec)); Assert.AreEqual(expected.Resolution[ResolutionKey.RelativeTo], actual.Resolution[ResolutionKey.RelativeTo], GetMessage(testSpec)); } else { Assert.AreEqual(expected.Resolution[ResolutionKey.Value], actual.Resolution[ResolutionKey.Value], GetMessage(testSpec)); } foreach (var key in testResolutionKeys ?? Enumerable.Empty <string>()) { if (!actual.Resolution.ContainsKey(key) && !expected.Resolution.ContainsKey(key)) { continue; } Assert.AreEqual(expected.Resolution[key].ToString(), actual.Resolution[key].ToString(), GetMessage(testSpec)); } } } }
public void TestURL(TestModel testSpec) { TestPreValidation(testSpec); ValidateResults(testSpec); }
public static bool IsNotSupportedByDesign(this TestModel testSpec) { return(testSpec.NotSupportedByDesign.HasFlag(Platform.dotNet)); }
public void TestDateTime(TestModel testSpec) { TestPreValidation(testSpec); var actualResults = TestContext.GetModelParseResults(testSpec); var expectedResults = testSpec.CastResults <ModelResult>(); Assert.AreEqual(expectedResults.Count(), actualResults.Count, GetMessage(testSpec)); try { foreach (var tuple in Enumerable.Zip(expectedResults, actualResults, Tuple.Create)) { var expected = tuple.Item1; var actual = tuple.Item2; Assert.AreEqual(expected.Text, actual.Text, GetMessage(testSpec)); Assert.AreEqual(expected.TypeName, actual.TypeName, GetMessage(testSpec)); Assert.AreEqual(expected.Start, actual.Start, GetMessage(testSpec)); Assert.AreEqual(expected.End, actual.End, GetMessage(testSpec)); if (testSpec.IgnoreResolution) { Assert.Inconclusive(GetMessage(testSpec) + ". Resolution not validated."); } else { var values = actual.Resolution as IDictionary <string, object>; // Actual ValueSet types should not be modified as that's considered a breaking API change var actualValues = ((List <Dictionary <string, string> >)values[ResolutionKey.ValueSet]).ToList(); var expectedValues = JsonConvert.DeserializeObject <IList <Dictionary <string, string> > >(expected.Resolution[ResolutionKey.ValueSet].ToString()); Assert.AreEqual(expectedValues.Count, actualValues.Count, GetMessage(testSpec)); foreach (var resolutionValues in expectedValues.Zip(actualValues, Tuple.Create)) { Assert.AreEqual(resolutionValues.Item1.Count, resolutionValues.Item2.Count, GetMessage(testSpec)); var expectedResolution = resolutionValues.Item1.OrderBy(o => o.Key).ToImmutableDictionary(); var actualResolution = resolutionValues.Item2.OrderBy(o => o.Key).ToImmutableDictionary(); for (int i = 0; i < expectedResolution.Count; i++) { var expectedKey = expectedResolution.ElementAt(i).Key; Assert.AreEqual(expectedKey, actualResolution.ElementAt(i).Key, GetMessage(testSpec)); var expectedValue = expectedResolution[expectedKey]; var actualValue = actualResolution[expectedKey]; Assert.AreEqual(expectedValue, actualValue, GetMessage(testSpec)); } } } } } catch (NullReferenceException nre) { throw new ApplicationException(GetMessage(testSpec), nre); } }
public void TestQuotedText(TestModel testSpec) { TestPreValidation(testSpec); ValidateResults(testSpec); }
public static IList <ModelResult> GetModelParseResults(this TestContext context, TestModel test) { var culture = TestUtils.GetCulture(context.FullyQualifiedTestClassName); var modelName = TestUtils.GetModel(context.TestName); var modelFunction = modelFunctions[modelName]; return(modelFunction(test, culture)); }