Exemplo n.º 1
0
        private SpecInfo getRunInfo(SpecificationMethodInfo spec)
        {
            var formatter = getFormatter(spec.Specification);
            var specInfo = new SpecInfo(formatter);
            specInfo.Name = getSpecName(spec.MethodInfo.DeclaringType, spec.MethodInfo);

            spec.UpdateSkipInformation(specInfo);

            if (specInfo.Skipped.IsSkipped)
            {
                spec.Specification.EnrichDescription(specInfo, formatter);
                return specInfo;
            }

            specInfo.ReportSpecExecutionHasTriggered();

            try
            {
                spec.Specification.Run(specInfo, getFormatter(spec.Specification));
            }
            catch (Exception e)
            {
                specInfo.Exception = e;
            }

            return specInfo;
        }
Exemplo n.º 2
0
        public void Specification(MethodInfo testMethod)
        {
            var inconclusive = false;
            var testResult = new SpecInfo();

            var skip = testMethod.GetCustomAttributes().OfType<SkipAttributeContract>()
                    .FirstOrDefault();

            if (skip != null)
            {
                testResult.ReportSkipped(skip.Reason);
                inconclusive = true;
            }
            else
            {
                testResult.ReportSpecExecutionHasTriggered();
            }

            try
            {
                testResult.Name = getSpecName(testMethod.DeclaringType, testMethod);

                var spec = testMethod.Invoke(this, new object[0]) as Specification;
                var formatter = MessageFormatterRegistry.GetFormatter(spec.SpecificationCategory);

                testResult.UseFormatter(formatter);

                if (skip != null)
                    spec.EnrichDescription(testResult, formatter);
                else
                    testResult = spec.Run(testResult, formatter);
            }
            catch (Exception e)
            {
                testResult.Exception = e;
            }

            var sb = new StringBuilder();
            sb.AppendLine(getDescription(testResult));

            var description = sb.ToString();

            if(inconclusive)
                Assert.Inconclusive(testResult.Skipped.Reason);
            else if (!testResult.Passed)
                Assert.Fail(description);
            else
            {
                Console.WriteLine(description);
                Assert.Pass(description);
            }
        }