Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
            public void UpdateSkipInformation(SpecInfo specInfo)
            {
                var skipAttribute =
                    MethodInfo.DeclaringType.GetCustomAttributes().FirstOrDefault(x => x is SkipAttributeContract) ??
                    MethodInfo.GetCustomAttributes().FirstOrDefault(x => x is SkipAttributeContract);

                if (skipAttribute == null)
                    return;

                var typed = (SkipAttributeContract)skipAttribute;
                string reason = typed.Reason;

                specInfo.ReportSkipped(reason);
            }