Esempio n. 1
0
        /// <summary>
        /// Verifies the answer of the given question using a NUnit constraint
        /// </summary>
        /// <typeparam name="T">The answer type</typeparam>
        /// /// <param name="verifies">The <see cref="IVerifies"/> instance</param>
        /// <param name="question">The question to verify the answer from</param>
        /// <param name="constraint">A NUnit constraint that encapsulate the expected result</param>
        /// <param name="getExceptionMessage">A function that returns the message to return when the assertion fails</param>
        /// <returns>The answer, when the verification succeeds</returns>
        public static T Then <T>(
            this IVerifies verifies,
            IQuestion <T> question,
            IResolveConstraint constraint,
            Func <string> getExceptionMessage)
        {
            if (verifies == null)
            {
                throw new ArgumentNullException(nameof(verifies));
            }
            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }
            if (constraint == null)
            {
                throw new ArgumentNullException(nameof(constraint));
            }
            if (getExceptionMessage == null)
            {
                throw new ArgumentNullException(nameof(getExceptionMessage));
            }

            return(verifies.Then(question, answer => Assert.That(answer, constraint, getExceptionMessage)));
        }
Esempio n. 2
0
        /// <summary>
        /// Verifies the answer of the given question using a NUnit constraint
        /// </summary>
        /// <typeparam name="T">The answer type</typeparam>
        /// /// <param name="verifies">The <see cref="IVerifies"/> instance</param>
        /// <param name="question">The question to verify the answer from</param>
        /// <param name="constraint">A NUnit constraint that encapsulate the expected result</param>
        /// <param name="message">The message to return when the assertion fails</param>
        /// <param name="args">Arguments to add to the message</param>
        /// <returns>The answer, when the verification succeeds</returns>
        public static T Then <T>(
            this IVerifies verifies,
            IQuestion <T> question,
            IResolveConstraint constraint,
            string message,
            params object[] args)
        {
            if (verifies == null)
            {
                throw new ArgumentNullException(nameof(verifies));
            }
            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }
            if (constraint == null)
            {
                throw new ArgumentNullException(nameof(constraint));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            return(verifies.Then(question, answer => Assert.That(answer, constraint, message, args)));
        }
Esempio n. 3
0
        public static IVerifies DontEnforceSetupVerification(this IVerifies verifies)
        {
            var testeroidsSetup = (Mocking.IVerifiesInternals)verifies;
            var expression      = testeroidsSetup.Expression;
            var testeroidsMock  = testeroidsSetup.TesteroidsMock;

            testeroidsMock.UnregisterSetupForVerification(expression);
            return(verifies);
        }
Esempio n. 4
0
        /// <summary>
        /// Verifies the answer of the given question using a NUnit constraint
        /// </summary>
        /// <typeparam name="T">The answer type</typeparam>
        /// /// <param name="verifies">The <see cref="IVerifies"/> instance</param>
        /// <param name="question">The question to verify the answer from</param>
        /// <param name="constraint">A NUnit constraint that encapsulate the expected result</param>
        /// <param name="message">The message to return when the assertion fails</param>
        /// <param name="args">Arguments to add to the message</param>
        /// <returns>The answer, when the verification succeeds</returns>
        public static T Then <T>(
            this IVerifies verifies,
            IQuestion <T> question,
            IResolveConstraint constraint,
            string message,
            params object[] args)
        {
            ValidateArguments(verifies, question, constraint, message, args);

            return(verifies.Then(question, answer => Assert.That(answer, constraint, message, args)));
        }
Esempio n. 5
0
        /// <summary>
        /// Verifies the answer of the given question using a NUnit constraint
        /// </summary>
        /// <typeparam name="T">The answer type</typeparam>
        /// /// <param name="verifies">The <see cref="IVerifies"/> instance</param>
        /// <param name="question">The question to verify the answer from</param>
        /// <param name="constraint">A NUnit constraint that encapsulate the expected result</param>
        /// <returns>The answer, when the verification succeeds</returns>
        public static Task <T> Then <T>(this IVerifies verifies, IQuestion <Task <T> > question, IResolveConstraint constraint)
        {
            if (verifies == null)
            {
                throw new ArgumentNullException(nameof(verifies));
            }
            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }
            if (constraint == null)
            {
                throw new ArgumentNullException(nameof(constraint));
            }

            return(verifies.Then <T>(question, answer => Assert.That(answer, constraint)));
        }
Esempio n. 6
0
        public void Then_ShouldCallAction(
            IVerifies verifies,
            IActor actor,
            object expected)
        {
            // arrange
            var verification = new Mock <Action <object> >();
            var question     = Questions.FromResult(expected);

            Mock.Get(verifies).Setup(a => a.Then(It.IsAny <IQuestion <object> >(), It.IsAny <Func <object, object> >()))
            .Returns((IQuestion <object> q, Func <object, object> f) =>
            {
                return(f(q.AnsweredBy(actor)));
            });
            // act
            var actual = verifies.Then(question, verification.Object);

            // assert
            Assert.Equal(expected, actual);
            verification.Verify(v => v(expected));
        }
Esempio n. 7
0
        /// <summary>
        /// Verifies the answer of the given question
        /// </summary>
        /// <typeparam name="TAnswer">The answer type</typeparam>
        /// <param name="actor">The actor</param>
        /// <param name="question">The question to verify the answer from</param>
        /// <param name="verifyAction">The action that verifies the answer. This action can throw assertion exceptions (using the Assert of a unit test framework) to indicates that the verification fails.</param>
        /// <returns>The answer, when the verification succeeds</returns>
        public static TAnswer Then <TAnswer>(this IVerifies actor, IQuestion <TAnswer> question, Action <TAnswer> verifyAction)
        {
            if (actor is null)
            {
                throw new ArgumentNullException(nameof(actor));
            }
            if (question is null)
            {
                throw new ArgumentNullException(nameof(question));
            }
            if (verifyAction is null)
            {
                throw new ArgumentNullException(nameof(verifyAction));
            }

            return(actor.Then(question, result =>
            {
                verifyAction(result);
                return result;
            }));
        }
Esempio n. 8
0
        public async Task Then_Async_ShouldExecuteAction(
            IVerifies verifies,
            IActor actor,
            object expected)
        {
            // arrange
            var mockAction = new Mock <Action <object> >();
            var task       = Task.FromResult(expected);
            var question   = Questions.FromResult(task);

            Mock.Get(verifies).Setup(a => a.Then(It.IsAny <IQuestion <Task <object> > >(), It.IsAny <Func <Task <object>, Task <object> > >()))
            .Returns((IQuestion <Task <object> > q, Func <Task <object>, Task <object> > f) =>
            {
                return(f(q.AnsweredBy(actor)));
            });
            // act
            var actual = await verifies.Then(question, mockAction.Object);

            // assert
            Assert.Equal(expected, actual);
            mockAction.Verify(a => a(expected));
        }
Esempio n. 9
0
        /// <summary>
        /// Verifies the answer of the given asynchronous question
        /// </summary>
        /// <typeparam name="TAnswer">The answer type</typeparam>
        /// <param name="actor">The actor</param>
        /// <param name="question">The question to verify the answer from</param>
        /// <param name="verifyAction">The action that verifies the answer. This action can throw assertion exceptions (using the Assert of a unit test framework) to indicates that the verification fails.</param>
        /// <returns>The answer, when the verification succeeds</returns>
        public static Task <TAnswer> Then <TAnswer>(this IVerifies actor, IQuestion <Task <TAnswer> > question, Action <TAnswer> verifyAction)
        {
            if (actor is null)
            {
                throw new ArgumentNullException(nameof(actor));
            }
            if (question is null)
            {
                throw new ArgumentNullException(nameof(question));
            }
            if (verifyAction is null)
            {
                throw new ArgumentNullException(nameof(verifyAction));
            }

            return(actor.Then(question, async resultTask =>
            {
                var result = await resultTask;
                verifyAction(result);
                return result;
            }));
        }
Esempio n. 10
0
 private static void ValidateArguments <T>(IVerifies verifies, IQuestion <T> question, IResolveConstraint constraint, string message, object[] args)
 {
     if (verifies == null)
     {
         throw new ArgumentNullException(nameof(verifies));
     }
     if (question == null)
     {
         throw new ArgumentNullException(nameof(question));
     }
     if (constraint == null)
     {
         throw new ArgumentNullException(nameof(constraint));
     }
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     if (args == null)
     {
         throw new ArgumentNullException(nameof(args));
     }
 }
 protected override void SetupVerifiableWrapper(IVerifies wrappedReturn, IVerifies verifiableWrapperReturn)
 {
     mockVerifiableWrapper.Setup(m => m.WrapVerifiesForVerification(wrappedReturn)).Returns(verifiableWrapperReturn);
 }
Esempio n. 12
0
 public IVerifies WrapVerifiesForVerification(IVerifies wrap)
 {
     return(new VerifiableVerifies(wrap, this));
 }
Esempio n. 13
0
 public static IVerifies EnforceUsage(this IVerifies verifies)
 {
     verifies.Verifiable();
     return(verifies);
 }