Beispiel #1
0
        public void XUnitFactTestMethod()
        {
            var testMethod = _testMethodResolver.ResolveTestMethod();

            var fileName = Path.Combine("Snapper.Internals.Tests", "Core",
                                        $"{nameof(TestMethodResolverTests)}.cs");

            testMethod.FileName.Should().EndWith(fileName);
            testMethod.MethodName.Should().Be(nameof(XUnitFactTestMethod));

            testMethod.BaseMethod.ReflectedType?.FullName.Should()
            .Be($"Snapper.Internals.Tests.Core.{nameof(TestMethodResolverTests)}");
            testMethod.BaseMethod.Name.Should().Be(nameof(XUnitFactTestMethod));
        }
Beispiel #2
0
        public SnapshotId ResolveSnapshotId(string childSnapshotName)
        {
            var testMethod     = _testMethodResolver.ResolveTestMethod();
            var testBaseMethod = testMethod.BaseMethod;

            var directory = Path.GetDirectoryName(testMethod.FileName);
            var className = testBaseMethod.DeclaringType?.Name;

            var snapshotDirectory      = Path.Combine(directory, SnapshotsDirectory);
            var storeSnapshotsPerClass = ShouldStoreSnapshotsPerClass(testBaseMethod);

            return(new SnapshotId(
                       snapshotDirectory,
                       className,
                       testMethod.MethodName,
                       childSnapshotName,
                       storeSnapshotsPerClass));
        }
        private bool ShouldUpdateSnapshotBasedOnAttribute()
        {
            var method = _testMethodResolver.ResolveTestMethod().BaseMethod;

            var customAttributeProviders = new List <ICustomAttributeProvider>
            {
                method,                         // check method
                method?.DeclaringType,          // check class
                method?.DeclaringType?.Assembly // check assembly
            };

            foreach (var customAttributeProvider in customAttributeProviders)
            {
                if (TryGetUpdateSnapshotsAttribute(customAttributeProvider, out var att))
                {
                    return(!(att.IgnoreIfCi && IsCiEnv()));
                }
            }

            return(false);
        }
Beispiel #4
0
        public SnapshotId ResolveSnapshotId(string partialSnapshotName)
        {
            var testMethod     = _testMethodResolver.ResolveTestMethod();
            var testBaseMethod = testMethod.BaseMethod;

            var directory = Path.GetDirectoryName(testMethod.FileName);
            var className = testBaseMethod.DeclaringType?.Name;

            var storeSnapshotsPerClass = ShouldStoreSnapshotsPerClass(testBaseMethod);

            if (storeSnapshotsPerClass)
            {
                var snapshotFilePath = Path.Combine(directory, SnapshotsDirectory, $"{className}.json");
                return(new SnapshotId(snapshotFilePath, testMethod.MethodName, partialSnapshotName));
            }
            else
            {
                var snapshotFileName = $"{className}{'_'}{testMethod.MethodName}";
                var snapshotFilePath = Path.Combine(directory, SnapshotsDirectory, $"{snapshotFileName}.json");
                return(new SnapshotId(snapshotFilePath, partialSnapshotName));
            }
        }