示例#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);
        }