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); } }
public NotConventionSpecification(IConventionSpecification x) { _wrapped = x; }
public static WrappedConventionResult MustConformTo(this IEnumerable<Type> types, IConventionSpecification conventionSpecification) { return new WrappedConventionResult( types, types.Select(conventionSpecification.IsSatisfiedBy)); }
public static ConventionResult MustConformTo(this Type type, IConventionSpecification conventionSpecification) { return conventionSpecification.IsSatisfiedBy(type); }
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); }
public static WrappedConventionResult MustConformTo(this IEnumerable <Type> types, IConventionSpecification conventionSpecification) { return(new WrappedConventionResult( types, types.Select(conventionSpecification.IsSatisfiedBy))); }
public static WrappedConventionResult AndMustConformTo(this WrappedConventionResult results, IConventionSpecification conventionSpecification) { return(new WrappedConventionResult( results.Types, results.Results.Union(results.Types.Select(conventionSpecification.IsSatisfiedBy)))); }
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 OrConventionSpecification(IConventionSpecification x, IConventionSpecification y) { _left = x; _right = y; }