public async Task ThrowIfRequired(string?message = null) { ProcessEquals(); if (missings.Count == 0 && notEquals.Count == 0 && danglingVerified.Count == 0) { return; } var builder = new StringBuilder("Results do not match."); builder.AppendLine(); if (message != null) { builder.AppendLine(message); } if (settings.clipboardEnabled && !settings.autoVerify) { builder.AppendLine("Verify command placed in clipboard."); } await ProcessDangling(builder); await ProcessMissing(builder); await ProcessNotEquals(builder); if (!settings.autoVerify) { throw InnerVerifier.exceptionBuilder(builder.ToString()); } }
static void AssertProcess(bool isRunning, params FilePair[] pairs) { foreach (var pair in pairs) { var command = BuildCommand(pair); if (isRunning == ProcessCleanup.IsRunning(command)) { continue; } var commands = string.Join(Environment.NewLine, ProcessCleanup.Commands.Select(x => x.Command)); string message; if (isRunning) { message = "Expected command running"; } else { message = "Expected command not running"; } throw InnerVerifier.exceptionBuilder($@"{message} {command} Commands: {commands}"); } }
public static MethodInfo GetPublicMethod(this Type type, string method) { var methodInfo = type.GetMethod(method, flags); if (methodInfo != null) { return(methodInfo); } throw InnerVerifier.exceptionBuilder($"Method `{method}` not found on type `{type.Name}`."); }
public static string GetAttributeConfiguration(this Assembly assembly) { var attribute = assembly.GetCustomAttribute <AssemblyConfigurationAttribute>(); if (attribute != null) { return(attribute.Configuration); } throw InnerVerifier.exceptionBuilder("UniqueForAssemblyConfiguration used but no `AssemblyConfigurationAttribute` found."); }
static TupleElementNamesAttribute ReadTupleElementNamesAttribute(MethodInfo method) { var attribute = (TupleElementNamesAttribute?)method.ReturnTypeCustomAttributes .GetCustomAttributes(typeof(TupleElementNamesAttribute), false) .SingleOrDefault(); if (attribute != null) { return(attribute); } throw InnerVerifier.exceptionBuilder("Verify is only to be used on methods that return a tuple."); }
public static bool ParseEnvironmentVariable(string?disabledText) { if (disabledText == null) { return(false); } if (bool.TryParse(disabledText, out var disabled)) { return(disabled); } throw InnerVerifier.exceptionBuilder($"Could not convert `Verify.DisableClipboard` environment variable to a bool. Value: {disabledText}"); }
public static T GetValue <T>(this MemberInfo member, object instance) { // this value could be in a public field or public property if (member is PropertyInfo propertyInfo) { return((T)propertyInfo.GetValue(instance, null) !); } if (member is FieldInfo fieldInfo) { return((T)fieldInfo.GetValue(instance) !); } throw InnerVerifier.exceptionBuilder($"No supported MemberType: {member.MemberType}"); }
public int IntOrNext <T>(T input) { if (input is Guid guidInput) { return(GuidCounter.IntOrNext(guidInput)); } if (input is DateTime dateTimeInput) { return(DateTimeCounter.IntOrNext(dateTimeInput)); } if (input is DateTimeOffset dateTimeOffsetInput) { return(DateTimeOffsetCounter.IntOrNext(dateTimeOffsetInput)); } throw InnerVerifier.exceptionBuilder($"Unknown type {typeof(T).FullName}"); }
static string AppendFileParts(Namer namer, StringBuilder builder, Assembly assembly) { if (namer.UniqueForRuntimeAndVersion || VerifierSettings.SharedNamer.UniqueForRuntimeAndVersion) { builder.Append($".{Namer.RuntimeAndVersion}"); } else if (namer.UniqueForRuntime || VerifierSettings.SharedNamer.UniqueForRuntime) { builder.Append($".{Namer.Runtime}"); } if (namer.UniqueForAssemblyConfiguration || VerifierSettings.SharedNamer.UniqueForAssemblyConfiguration) { if (assembly == null) { throw InnerVerifier.exceptionBuilder("`UniqueForAssemblyConfiguration` requires `SharedVerifySettings.SetTestAssembly(Assembly.GetExecutingAssembly());` to be called at assembly startup."); } builder.Append($".{assembly.GetAttributeConfiguration()}"); } return(builder.ToString()); }