예제 #1
0
 public void TestSpecInitialize(TestResources resources)
 {
     TestSpec = resources.GetSpecForContext(TestContext);
 }
예제 #2
0
 private static string GetMessage(TestModel spec)
 {
     return($"Input: \"{spec.Input}\"");
 }
예제 #3
0
 public void TestNumberWithUnit(TestModel testSpec)
 {
     TestPreValidation(testSpec);
     ValidateResults(testSpec, new[] { ResolutionKey.Unit, ResolutionKey.SubType });
 }
예제 #4
0
 public void TestCurrency(TestModel testSpec)
 {
     TestPreValidation(testSpec);
     ValidateResults(testSpec, new[] { ResolutionKey.Unit, ResolutionKey.IsoCurrency });
 }
예제 #5
0
 public void TestChoice(TestModel testSpec)
 {
     TestPreValidation(testSpec);
     ValidateResults(testSpec, new string[] { ResolutionKey.Value, ResolutionKey.Score });
 }
예제 #6
0
        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));
                    }
                }
            }
        }
예제 #7
0
 public void TestURL(TestModel testSpec)
 {
     TestPreValidation(testSpec);
     ValidateResults(testSpec);
 }
예제 #8
0
 public static bool IsNotSupportedByDesign(this TestModel testSpec)
 {
     return(testSpec.NotSupportedByDesign.HasFlag(Platform.dotNet));
 }
예제 #9
0
        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);
            }
        }
예제 #10
0
 public void TestQuotedText(TestModel testSpec)
 {
     TestPreValidation(testSpec);
     ValidateResults(testSpec);
 }
예제 #11
0
        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));
        }