Exemplo n.º 1
0
        /// <summary>
        /// Compares the current snapshot with the expected snapshot and applies
        /// the compare rules of the compare actions.
        /// </summary>
        /// <param name="matchOptions">The compare actions, which will be used for special comparion.</param>
        /// <param name="expectedSnapshot">The original snapshot of the current result.</param>
        /// <param name="actualSnapshot">The actual (modifiable) snapshot of the current result.</param>
        public void CompareSnapshots(
            string expectedSnapshot,
            string actualSnapshot,
            Func <MatchOptions, MatchOptions> matchOptions)
        {
            JToken originalActualSnapshotToken = _snapshotSerializer.Deserialize(actualSnapshot);
            JToken actualSnapshotToken         = _snapshotSerializer.Deserialize(actualSnapshot);
            JToken expectedSnapshotToken       = _snapshotSerializer.Deserialize(expectedSnapshot);

            if (matchOptions != null)
            {
                ExecuteFieldMatchActions(originalActualSnapshotToken,
                                         actualSnapshotToken, expectedSnapshotToken, matchOptions);
            }

            string actualSnapshotToCompare = _snapshotSerializer
                                             .SerializeJsonToken(actualSnapshotToken);
            string expectedSnapshotToCompare = _snapshotSerializer
                                               .SerializeJsonToken(expectedSnapshotToken);

            _snapshotAssert.Assert(expectedSnapshotToCompare, actualSnapshotToCompare);
        }
Exemplo n.º 2
0
        public ValueAssertionResult AssertValue(IEnumerable <TElement> actual)
        {
            string expectation = ComposeLog.Expected("0 matches");

            if (actual == null)
            {
                return(new ValueAssertionResult(
                           true,
                           actual.ToValueString(),
                           expectation));
            }

            var actualList = actual.ToList();

            if (!actualList.Any())
            {
                return(new ValueAssertionResult(
                           true,
                           actualList.ToValueString(),
                           expectation));
            }

            IReadOnlyCollection <Result> results = actualList.Map(a => childAssertion.Assert(a));
            int numberOfSucceededResults         = results.Count(r => r.succeeded);

            return(new ValueAssertionResult(
                       numberOfSucceededResults == 0,
                       string.Join(
                           Environment.NewLine,
                           numberOfSucceededResults.Matches()
                           .Cons(results.Select(r => r.actual))),
                       string.Join(
                           Environment.NewLine,
                           expectation
                           .Cons(results.Select(r => r.expectation)))));
        }
 public static TResult Assert <TName, TArgFirst, TArgSecond, TResult>(this IAssert <TName, TArgFirst, TArgSecond, TResult> sender, TArgFirst argFirst, TArgSecond argSecond)
 {
     return(sender.Assert(argFirst, argSecond));
 }
Exemplo n.º 4
0
        public ValueAssertionResult AssertValue(T actual)
        {
            Result result = assert.Assert(actual);

            return(new ValueAssertionResult(result.succeeded, result.actual, result.expectation));
        }
Exemplo n.º 5
0
 public void Assert(T actualItem)
 {
     assertor?.Assert(actualItem);
 }
Exemplo n.º 6
0
 public static Result Evaluate <T>(T instance, IAssert <T> assertion)
 {
     return(assertion.Assert(instance));
 }