private static async Task <Exception> InvokeWithInterceptionAsync(Func <Task> action)
        {
            try
            {
                // For the duration of this nested invocation, configure CallerIdentifier
                // to match the contents of the subject rather than our own call site.
                //
                //   Func<Task> action = async () => await subject.Should().BeSomething();
                //   await action.Should().ThrowAsync<Exception>();
                //
                // If an assertion failure occurs, we want the message to talk about "subject"
                // not "await action".
                using (CallerIdentifier.OnlyOneFluentAssertionScopeOnCallStack()
                        ? CallerIdentifier.OverrideStackSearchUsingCurrentScope()
                        : default)
                {
                    await action();
                }

                return(null);
            }
            catch (Exception exception)
            {
                return(exception);
            }
        }
        private Exception InvokeSubjectWithInterception()
        {
            Exception actualException = null;

            try
            {
                // For the duration of this nested invocation, configure CallerIdentifier
                // to match the contents of the subject rather than our own call site.
                //
                //   Action action = () => subject.Should().BeSomething();
                //   action.Should().Throw<Exception>();
                //
                // If an assertion failure occurs, we want the message to talk about "subject"
                // not "action".
                using (CallerIdentifier.OnlyOneFluentAssertionScopeOnCallStack()
                    ? CallerIdentifier.OverrideStackSearchUsingCurrentScope()
                    : default)
                {
                    InvokeSubject();
                }
            }
            catch (Exception exc)
            {
                actualException = exc;
            }

            return(actualException);
        }
示例#3
0
        public bool Equals(InvocationExpression compareNode)
        {
            return
                (compareNode != null &&
                 MethodName?.Equals(compareNode.MethodName) != false &&
                 Modifiers?.Equals(compareNode.Modifiers) != false &&
                 SemanticNamespace?.Equals(compareNode.SemanticNamespace) != false &&
                 CallerIdentifier?.Equals(compareNode.CallerIdentifier) != false &&
                 SemanticClassType?.Equals(compareNode.SemanticClassType) != false &&
                 SemanticMethodSignature?.Equals(compareNode.SemanticMethodSignature) != false &&
#pragma warning disable CS0618 // Type or member is obsolete
                 Parameters?.SequenceEqual(compareNode.Parameters) != false &&
#pragma warning restore CS0618 // Type or member is obsolete
                 Arguments?.SequenceEqual(compareNode.Arguments) != false &&
                 SemanticReturnType?.Equals(compareNode.SemanticReturnType) != false &&
                 SemanticOriginalDefinition?.Equals(compareNode.SemanticOriginalDefinition) != false &&
                 IsExtension == compareNode.IsExtension &&
                 base.Equals(compareNode));
        }
示例#4
0
 private static string GetName() => CallerIdentifier.DetermineCallerIdentity() ?? "completion list items";
示例#5
0
        public static void DetermineCallerIdentityInNamespace()
        {
            Func <string> actualCaller = () => CallerIdentifier.DetermineCallerIdentity();

            actualCaller.Should().BeNull("we want this check to fail for the test");
        }