Exemple #1
0
    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());
        }
    }
Exemple #2
0
    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}");
        }
    }
Exemple #3
0
    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}`.");
    }
Exemple #4
0
    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.");
    }
Exemple #5
0
    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.");
    }
Exemple #6
0
    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}");
    }
Exemple #7
0
    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}");
    }
Exemple #8
0
    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}");
    }
Exemple #9
0
    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());
    }