Example #1
0
        public static void MustConformTo(this TypeConformanceSpecimen specimen, IConventionSpecification conventionSpecification)
        {
            if (ConventionConfiguration.DefaultFailureAssertionCallback == null)
            {
                throw new Exception("You must configure a default failure assertion when using Doomsday tests");
            }

            if (ConventionConfiguration.DefaultWarningAssertionCallback == null)
            {
                throw new Exception("You must configure a default warning assertion when using Doomsday tests");
            }

            var evaluatedResults = specimen.Types.Select(conventionSpecification.IsSatisfiedBy).ToList();

            if (evaluatedResults.All(x => x.IsSatisfied))
            {
                return;
            }

            var currentDate      = ConventionConfiguration.DefaultCurrentDateResolver();
            var currentOffenders = evaluatedResults.Count(x => x.IsSatisfied == false);

            var result =
                evaluatedResults.Where(x => x.IsSatisfied == false).Aggregate(string.Empty, (s, x) =>
                                                                              s +
                                                                              x.TypeName +
                                                                              Environment.NewLine +
                                                                              StringConstants.Underline +
                                                                              Environment.NewLine +
                                                                              x.Failures.Aggregate(string.Empty, (s1, s2) => s1 + s2 + Environment.NewLine) +
                                                                              Environment.NewLine);

            if (specimen.Doomsday.HasValue && currentDate > specimen.Doomsday)
            {
                var message = "Doomsday is upon us! " + specimen.Message + Environment.NewLine + result;

                ConventionConfiguration.DefaultFailureAssertionCallback(message);
            }
            else if (currentOffenders > specimen.KnownOffenders)
            {
                var message = $"Expected {specimen.KnownOffenders} or less offenders but found {currentOffenders}: " + specimen.Message + Environment.NewLine + result;

                ConventionConfiguration.DefaultFailureAssertionCallback(message);
            }
            else if (specimen.WarnWithin.HasValue && currentDate.Add(specimen.WarnWithin.Value) > specimen.Doomsday)
            {
                var message = "Doomsday approaches! " + specimen.Message + Environment.NewLine + result;

                ConventionConfiguration.DefaultWarningAssertionCallback(message);
            }
        }
Example #2
0
        public static void MustConformTo(this TypeConformanceSpecimen specimen, IConventionSpecification conventionSpecification)
        {
            if (ConventionConfiguration.DefaultFailureAssertionCallback == null)
            {
                throw new Exception("You must configure a default failure assertion when using Doomsday tests");
            }

            if (ConventionConfiguration.DefaultWarningAssertionCallback == null)
            {
                throw new Exception("You must configure a default warning assertion when using Doomsday tests");
            }

            var evaluatedResults = specimen.Types.Select(conventionSpecification.IsSatisfiedBy).ToList();

            if (evaluatedResults.All(x => x.IsSatisfied))
            {
                return;
            }

            var currentDate = ConventionConfiguration.DefaultCurrentDateResolver();
            var currentOffenders = evaluatedResults.Count(x => x.IsSatisfied == false);

            var result =
                evaluatedResults.Where(x => x.IsSatisfied == false).Aggregate(string.Empty, (s, x) =>
                    s +
                    x.TypeName +
                    Environment.NewLine +
                    StringConstants.Underline +
                    Environment.NewLine +
                    x.Failures.Aggregate(string.Empty, (s1, s2) => s1 + s2 + Environment.NewLine) +
                    Environment.NewLine);

            if (specimen.Doomsday.HasValue && currentDate > specimen.Doomsday)
            {
                var message = "Doomsday is upon us! " + specimen.Message + Environment.NewLine + result;

                ConventionConfiguration.DefaultFailureAssertionCallback(message);
            }
            else if (currentOffenders > specimen.KnownOffenders)
            {
                var message = $"Expected {specimen.KnownOffenders} or less offenders but found {currentOffenders}: " + specimen.Message + Environment.NewLine + result;

                ConventionConfiguration.DefaultFailureAssertionCallback(message);
            }
            else if (specimen.WarnWithin.HasValue && currentDate.Add(specimen.WarnWithin.Value) > specimen.Doomsday)
            {
                var message = "Doomsday approaches! " + specimen.Message + Environment.NewLine + result;

                ConventionConfiguration.DefaultWarningAssertionCallback(message);
            }
        }
Example #3
0
 public NotConventionSpecification(IConventionSpecification x)
 {
     _wrapped = x;
 }
Example #4
0
 public static WrappedConventionResult MustConformTo(this IEnumerable<Type> types, IConventionSpecification conventionSpecification)
 {
     return new WrappedConventionResult(
         types,
         types.Select(conventionSpecification.IsSatisfiedBy));
 }
Example #5
0
 public static ConventionResult MustConformTo(this Type type, IConventionSpecification conventionSpecification)
 {
     return conventionSpecification.IsSatisfiedBy(type);
 }
Example #6
0
 public static WrappedConventionResult AndMustConformTo(this WrappedConventionResult results, IConventionSpecification conventionSpecification)
 {
     return new WrappedConventionResult(
         results.Types,
         results.Results.Union(results.Types.Select(conventionSpecification.IsSatisfiedBy)));
 }
 public AndConventionSpecification(IConventionSpecification x, IConventionSpecification y)
 {
     _left  = x;
     _right = y;
 }
 public IConventionSpecification And(IConventionSpecification conventionSpecification)
 {
     return new AndConventionSpecification(this, conventionSpecification);
 }
 public IConventionSpecification Or(IConventionSpecification conventionSpecification)
 {
     return new OrConventionSpecification(this, conventionSpecification);
 }
Example #10
0
 public static WrappedConventionResult MustConformTo(this IEnumerable <Type> types, IConventionSpecification conventionSpecification)
 {
     return(new WrappedConventionResult(
                types,
                types.Select(conventionSpecification.IsSatisfiedBy)));
 }
Example #11
0
 public static WrappedConventionResult AndMustConformTo(this WrappedConventionResult results, IConventionSpecification conventionSpecification)
 {
     return(new WrappedConventionResult(
                results.Types,
                results.Results.Union(results.Types.Select(conventionSpecification.IsSatisfiedBy))));
 }
Example #12
0
 public static ConventionResult MustConformTo(this Type type, IConventionSpecification conventionSpecification)
 {
     return(conventionSpecification.IsSatisfiedBy(type));
 }
 public IConventionSpecification Or(IConventionSpecification conventionSpecification)
 {
     return(new OrConventionSpecification(this, conventionSpecification));
 }
 public IConventionSpecification And(IConventionSpecification conventionSpecification)
 {
     return(new AndConventionSpecification(this, conventionSpecification));
 }
 public NotConventionSpecification(IConventionSpecification x)
 {
     _wrapped = x;
 }
 public OrConventionSpecification(IConventionSpecification x, IConventionSpecification y)
 {
     _left = x;
     _right = y;
 }