コード例 #1
0
        public static void MultipleMscorlibReferencesFound()
        {
            var objectFinder = new SystemObjectFinder(new DotNetFrameworkFilter());
            var file         = TestAssembly.Create("multiple-mscorlib.exe");

            using (var stream = file.OpenRead())
                using (var peFile = new PEReader(stream))
                {
                    var metadataReader = peFile.GetMetadataReader();

                    var assemblyInfo = objectFinder.GetSystemRuntimeAssemblyInformation(metadataReader);

                    Assert.Equal("mscorlib", assemblyInfo.Name);
                    Assert.Equal("4.0.0.0", assemblyInfo.Version.ToString());
                    Assert.Equal("neutral", assemblyInfo.Culture);
                    Assert.Equal("b77a5c561934e089", assemblyInfo.PublicKeyToken);
                }
        }
コード例 #2
0
        public void NetstandardReferencesOnly()
        {
            var objectFinder = new SystemObjectFinder(new DotNetFrameworkFilter());
            var file         = TestAssembly.Create("OnlyNetStandardReference.il", _output);

            using (var stream = file.OpenRead())
            {
                using (var peFile = new PEReader(stream))
                {
                    var metadataReader = peFile.GetMetadataReader();

                    Assert.True(objectFinder.TryGetSystemRuntimeAssemblyInformation(metadataReader, out var assemblyInfo));
                    Assert.Equal("netstandard", assemblyInfo.Name);
                    Assert.Equal("2.0.0.0", assemblyInfo.Version.ToString());
                    Assert.Equal("neutral", assemblyInfo.Culture);
                    Assert.Equal("cc7b13ffcd2ddd51", assemblyInfo.PublicKeyToken);
                }
            }
        }
コード例 #3
0
        public void VerifyDotNetFrameworkFilter()
        {
            var expected = new[]
            {
                "M:System.Console.WriteLine(System.String)",
                "M:System.Diagnostics.DebuggableAttribute.#ctor(System.Diagnostics.DebuggableAttribute.DebuggingModes)",
                "M:System.Object.#ctor",
                "M:System.Object.ToString",
                "M:System.Runtime.CompilerServices.CompilationRelaxationsAttribute.#ctor(System.Int32)",
                "M:System.Runtime.CompilerServices.RuntimeCompatibilityAttribute.#ctor",
                "M:System.Runtime.Versioning.TargetFrameworkAttribute.#ctor(System.String)",
                "M:System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)",
                "M:System.Uri.TryCreate(System.String,System.UriKind,System.Uri@)",
                "T:System.Console",
                "T:System.Diagnostics.DebuggableAttribute",
                "T:System.Diagnostics.DebuggableAttribute.DebuggingModes",
                "T:System.Object",
                "T:System.Runtime.CompilerServices.CompilationRelaxationsAttribute",
                "T:System.Runtime.CompilerServices.RuntimeCompatibilityAttribute",
                "T:System.Runtime.Versioning.TargetFrameworkAttribute",
                "T:System.RuntimeTypeHandle",
                "T:System.Type",
                "T:System.Uri",
                "T:System.UriKind"
            };

            var dependencyFinder = new ReflectionMetadataDependencyFinder(new DotNetFrameworkFilter());
            var assemblyToTest   = TestAssembly.Create("FilterApis.cs");
            var progressReporter = Substitute.For <IProgressReporter>();

            var dependencies = dependencyFinder.FindDependencies(new[] { assemblyToTest }, progressReporter);
            var foundDocIds  = dependencies.Dependencies
                               .Select(m => m.Key.MemberDocId)
                               .OrderBy(o => o, StringComparer.Ordinal);

            foreach (var docId in foundDocIds)
            {
                _output.WriteLine(docId);
            }

            Assert.Equal(expected, foundDocIds);
        }
コード例 #4
0
        public void LookInFilePassedInAssembly(string name)
        {
            var source       = @"
.assembly " + name + @"
{
  .ver 1:0:0:0
} ";
            var objectFinder = new SystemObjectFinder(new DotNetFrameworkFilter());
            var file         = TestAssembly.CreateFromIL(source, name, _output);

            using (var stream = file.OpenRead())
            {
                using (var peFile = new PEReader(stream))
                {
                    var metadataReader = peFile.GetMetadataReader();

                    Assert.True(objectFinder.TryGetSystemRuntimeAssemblyInformation(metadataReader, out var assemblyInfo));
                    Assert.Equal(name, assemblyInfo.Name);
                }
            }
        }
コード例 #5
0
        private void TestForDocId(string source, string docid, bool allowUnsafe)
        {
            var dependencyFinder = new ReflectionMetadataDependencyFinder(new AlwaysTrueDependencyFilter());
            var assemblyToTest   = TestAssembly.Create(source, allowUnsafe);
            var progressReporter = Substitute.For <IProgressReporter>();

            var dependencies = dependencyFinder.FindDependencies(new[] { assemblyToTest }, progressReporter);

            foreach (var dependency in dependencies.Dependencies)
            {
                if (string.Equals(dependency.Key.MemberDocId, docid, StringComparison.Ordinal))
                {
                    return;
                }
            }

            _output.WriteLine("Found docids:");
            _output.WriteLine(string.Join(Environment.NewLine, dependencies.Dependencies.Select(o => o.Key.MemberDocId).OrderBy(o => o)));

            Assert.True(false, ((FormattableString)$"Could not find docid '{docid}'").ToString(CultureInfo.CurrentCulture));
        }
コード例 #6
0
        public void EmptyProject()
        {
            var test = TestAssembly.Create("EmptyProject.cs");

            CompareDependencies(test.AssemblyPath, EmptyProjectMemberDocId());
        }