Example #1
0
        public void Snap(string snapshotName, object newSnapValue)
        {
            var path        = _pathResolver.ResolvePath(snapshotName);
            var oldSnapshot = _store.GetSnap(path);

            if (oldSnapshot != null)
            {
                AssertSnapshot(path, newSnapValue, oldSnapshot);
                return;
            }

            if (_snapUpdateDecider.ShouldUpdateSnap())
            {
                _store.StoreSnap(path, newSnapValue);
                _asserter.AssertEqual();
                return;
            }

            _asserter.AssertNotEqual("A snapshot for this does not exist yet.");
        }
        public bool ShouldUpdateSnap()
        {
            if (_envUpdateDecider.ShouldUpdateSnap())
            {
                return(true);
            }

            var(method, _) = XUnitTestHelper.GetCallingTestInfo();

            var methodHasAttribute = method?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false;
            var classHasAttribute  = method?.ReflectedType?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false;

            return(methodHasAttribute || classHasAttribute);
        }