Пример #1
0
        public void AllowAddingNewVerifiables()
        {
            var verifiable1 = new MockVerifiable();

            verifiable1.Verify.Return(new[] { new VerificationResult("My Verification", false) });

            var verifiable2 = new MockVerifiable();

            verifiable2.Verify.Return(new[] { new VerificationResult("My other verification", true) });

            IVerifiable group = new VerificationGroup("My Group")
            {
                verifiable1,
                verifiable2
            };

            var groupResult = group.Verify();
            var result      = Assert.Single(groupResult);

            var expectedResult = new VerificationResult("Verification Group 'My Group':", new[]
            {
                new VerificationResult("My Verification", false),
                new VerificationResult("My other verification", true)
            });

            result.AssertEquals(expectedResult);
        }
Пример #2
0
        public void ReturnSingleSuccessfulResultIfEmpty()
        {
            IVerifiable group       = new VerificationGroup();
            var         groupResult = group.Verify();
            var         result      = Assert.Single(groupResult);

            Assert.True(result.Success);
            Assert.Equal("Verification Group:", result.Description);
        }
Пример #3
0
        public void AcceptName()
        {
            IVerifiable group       = new VerificationGroup("Group Name");
            var         groupResult = group.Verify();
            var         result      = Assert.Single(groupResult);

            Assert.True(result.Success);
            Assert.Equal("Verification Group 'Group Name':", result.Description);
        }
Пример #4
0
        public void NotThrowWhenAssertingSuccessfulGroup()
        {
            var verifiable = new MockVerifiable();

            verifiable.Verify
            .Return(new[] { new VerificationResult("a passing test", true) });

            var group = new VerificationGroup("My Group")
            {
                verifiable
            };

            group.Assert();
        }
Пример #5
0
        /// <summary>
        ///     Step that checks the number of times the method has been called. Adds the check to the verification group
        ///     provided.
        /// </summary>
        /// <typeparam name="TParam">The method parameter type.</typeparam>
        /// <typeparam name="TResult">The method return type.</typeparam>
        /// <param name="caller">The mock or step to which this 'verification' step is added.</param>
        /// <param name="verificationGroup">The verification group to which this check is added.</param>
        /// <param name="name">A name that can be used to identify the check in its group.</param>
        /// <param name="expectedNumberOfCalls">The expected number of times the method has been called.</param>
        /// <returns>An <see cref="ICanHaveNextMethodStep{TParam, TResult}" /> that can be used to add further steps.</returns>
        public static ICanHaveNextMethodStep <TParam, TResult> ExpectedUsage <TParam, TResult>(
            this ICanHaveNextMethodStep <TParam, TResult> caller,
            VerificationGroup verificationGroup,
            string?name,
            int?expectedNumberOfCalls = null)
        {
            if (verificationGroup == null)
            {
                throw new ArgumentNullException(nameof(verificationGroup));
            }

            var step = new ExpectedUsageMethodStep <TParam, TResult>(name, expectedNumberOfCalls);

            verificationGroup.Add(step);
            return(caller.SetNextStep(step));
        }
Пример #6
0
        /// <summary>
        ///     Step that checks the number of times values have been read from or written to the indexer. Adds the check
        ///     to the verification group provided.
        /// </summary>
        /// <typeparam name="TKey">The type of the indexer key.</typeparam>
        /// <typeparam name="TValue">The type of the indexer value.</typeparam>
        /// <param name="caller">The mock or step to which this 'verification' step is added.</param>
        /// <param name="verificationGroup">The verification group to which this check is added.</param>
        /// <param name="name">A name that can be used to identify the check in its group.</param>
        /// <param name="expectedNumberOfGets">The expected number of times values have been read from the indexer.</param>
        /// <param name="expectedNumberOfSets">The expected number of times values have been written to the indexer.</param>
        /// <returns>An <see cref="ICanHaveNextIndexerStep{TKey, TValue}" /> that can be used to add further steps.</returns>
        public static ICanHaveNextIndexerStep <TKey, TValue> ExpectedUsage <TKey, TValue>(
            this ICanHaveNextIndexerStep <TKey, TValue> caller,
            VerificationGroup verificationGroup,
            string?name,
            int?expectedNumberOfGets = null,
            int?expectedNumberOfSets = null)
        {
            if (verificationGroup == null)
            {
                throw new ArgumentNullException(nameof(verificationGroup));
            }

            var step = new ExpectedUsageIndexerStep <TKey, TValue>(name, expectedNumberOfGets, expectedNumberOfSets);

            verificationGroup.Add(step);
            return(caller.SetNextStep(step));
        }
Пример #7
0
        /// <summary>
        ///     Step that checks the number of times event handlers have been added or removed. Adds the check to the verification
        ///     group provided.
        /// </summary>
        /// <typeparam name="THandler">The event handler type for the event.</typeparam>
        /// <param name="caller">The mock or step to which this 'verification' step is added.</param>
        /// <param name="verificationGroup">The verification group to which this check is added.</param>
        /// <param name="name">A name that can be used to identify the check in its group.</param>
        /// <param name="expectedNumberOfAdds">The expected number of times event handlers have been added.</param>
        /// <param name="expectedNumberOfRemoves">The expected number of times event handlers have been removed.</param>
        /// <returns>An <see cref="ICanHaveNextEventStep{THandler}" /> that can be used to add further steps.</returns>
        public static ICanHaveNextEventStep <THandler> ExpectedUsage <THandler>(
            this ICanHaveNextEventStep <THandler> caller,
            VerificationGroup verificationGroup,
            string?name,
            int?expectedNumberOfAdds    = null,
            int?expectedNumberOfRemoves = null) where THandler : Delegate
        {
            if (verificationGroup == null)
            {
                throw new ArgumentNullException(nameof(verificationGroup));
            }

            var step = new ExpectedUsageEventStep <THandler>(name, expectedNumberOfAdds, expectedNumberOfRemoves);

            verificationGroup.Add(step);
            return(caller.SetNextStep(step));
        }
Пример #8
0
        public void ExposesVerifiablesThroughIEnumerable()
        {
            var verifiable1 = new MockVerifiable();

            verifiable1.Verify.Return(new[] { new VerificationResult("My Verification", false) });

            var verifiable2 = new MockVerifiable();

            verifiable2.Verify.Return(new[] { new VerificationResult("My other verification", true) });

            var group = new VerificationGroup("My Group")
            {
                verifiable1,
                verifiable2
            };

            Assert.Equal(new IVerifiable[] { verifiable1, verifiable2 }, group);
            Assert.Equal(new IVerifiable[] { verifiable1, verifiable2 }, group.ToArray());
        }
Пример #9
0
        public void PassFormatProviderToGroupMembers()
        {
            var verifiable = new MockVerifiable();

            verifiable.Verify
            .RecordBeforeCall(out var ledger)
            .Return(new[] { new VerificationResult("aha", true) });

            IVerifiable group = new VerificationGroup("My Group")
            {
                verifiable
            };

            var french   = new CultureInfo("fr-FR");
            var japanese = new CultureInfo("ja-JP");

            group.Verify(french);
            group.Verify(japanese);

            Assert.Equal(new IFormatProvider[] { french, japanese }, ledger);
            Assert.Equal(new IFormatProvider[] { french, japanese }, ledger.ToArray());
        }
Пример #10
0
        public void ThrowWhenAssertingFailedGroup()
        {
            var verifiable = new MockVerifiable();

            verifiable.Verify
            .Return(new[] { new VerificationResult("a failing test", false) });

            var group = new VerificationGroup("My Group")
            {
                verifiable
            };

            var ex = Assert.Throws <VerificationFailedException>(() => group.Assert());

            ex.VerificationResult.AssertEquals(new VerificationResult("Verification Group 'My Group':", new[]
            {
                new VerificationResult("a failing test", false)
            }));

            Assert.Equal(@"Verification failed.

FAILED: Verification Group 'My Group':
FAILED:   a failing test", ex.Message);
        }
Пример #11
0
 /// <summary>
 ///     Checks the current values in the indexer store. Adds the check to the verification group provided.
 /// </summary>
 /// <typeparam name="TKey">The type of the indexer key.</typeparam>
 /// <typeparam name="TValue">The type of the indexer value.</typeparam>
 /// <param name="indexer">The <see cref="IStoredIndexer{TKey,TValue}" /> whose values to check.</param>
 /// <param name="collector">The verification group to which this check is added.</param>
 /// <param name="name">A name that can be used to identify the check in its verification group.</param>
 /// <param name="expectedValues">
 ///     A list of key-value pairs to check. The check will retrieve the value for each key
 ///     in the list and compare it to the value in the list.
 /// </param>
 /// <param name="comparer">Optional parameter with a comparer used to verify that the values are equal.</param>
 /// <returns>The <see cref="IStoredIndexer{TKey,TValue}" /> instance that can be used to add further checks.</returns>
 public static IStoredIndexer <TKey, TValue> CurrentValuesCheck <TKey, TValue>(this IStoredIndexer <TKey, TValue> indexer,
                                                                               VerificationGroup collector,
                                                                               string?name, IEnumerable <KeyValuePair <TKey, TValue> >?expectedValues, IEqualityComparer <TValue>?comparer = null)
 {
     collector.Add(new CurrentValuesIndexerCheck <TKey, TValue>(indexer, name, expectedValues, comparer));
     return(indexer);
 }
Пример #12
0
 /// <summary>
 ///     Checks the current values in the property store. Adds the check to the verification group provided.
 /// </summary>
 /// <typeparam name="TValue">The type of the property.</typeparam>
 /// <param name="property">The <see cref="IStoredProperty{TValue}" /> whose value to check.</param>
 /// <param name="collector">The verification group to which this check is added.</param>
 /// <param name="name">A name that can be used to identify the check in its verification group.</param>
 /// <param name="expectedValue">The expected value. </param>
 /// <param name="comparer">Optional parameter with a comparer used to verify that the values are equal.</param>
 /// <returns>The <see cref="IStoredProperty{TValue}" /> instance that can be used to add further checks.</returns>
 public static IStoredProperty <TValue> CurrentValueCheck <TValue>(this IStoredProperty <TValue> property, VerificationGroup collector,
                                                                   string?name, TValue expectedValue, IEqualityComparer <TValue>?comparer = null)
 {
     collector.Add(new CurrentValuePropertyCheck <TValue>(property, name, expectedValue, comparer));
     return(property);
 }