public void UnresolvedAssemblyTest()
        {
            var finder = new ReflectionMetadataDependencyFinder(new AlwaysTrueDependencyFilter());
            var progressReport = Substitute.For<IProgressReporter>();

            var path = this.GetType().GetTypeInfo().Assembly.Location;
            var testInfo = new FilePathAssemblyFile(path);

            var dependencies = finder.FindDependencies(new[] { testInfo }, progressReport);
            var actual = dependencies.UnresolvedAssemblies
                            .Select(u => u.Key)
                            .OrderBy(u => u);

            _log.WriteLine("Actual unresolved assemblies:");
            foreach (var assembly in actual)
            {
                _log.WriteLine(assembly);
            }

            Assert.Equal(s_expectedResult.Count(), actual.Count());

            // Use this instead of Assert.Equal so it will output the missing item
            foreach (var items in s_expectedResult.Zip(actual, Tuple.Create))
            {
                Assert.Equal(items.Item1, items.Item2);
            }

            Assert.True(dependencies.UnresolvedAssemblies.All(o => o.Value.Count == 1));
            Assert.True(dependencies.UnresolvedAssemblies.All(o => string.Equals(o.Value.First(), "Microsoft.Fx.Portability.MetadataReader.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4a286c3e845c3e69", StringComparison.Ordinal)));

            // Make sure no issues were found
            progressReport.Received(0).ReportIssue(Arg.Any<string>());
        }
Exemplo n.º 2
0
        public void MscorlibTest()
        {
            var mscorlib = typeof(object).Assembly.Location;

            var baseline = GetBaseline(mscorlib);
            var dependencyFinder = new ReflectionMetadataDependencyFinder();
            var path = new FileInfo(mscorlib);
            var progressReporter = Substitute.For<IProgressReporter>();

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

            var result = dependencies.Dependencies
                .Select(d => d.Key)
                .OrderBy(d => d);

            Assert.Equal(baseline, result);
        }
        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, $"Could not find docid '{docid}'");
        }
        private void CompareDependencies(string path, IEnumerable<Tuple<string, int>> expected)
        {
            var dependencyFinder = new ReflectionMetadataDependencyFinder();
            var assemblyToTestFileInfo = new FileInfo(path);
            var progressReporter = Substitute.For<IProgressReporter>();

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

            var foundDocIds = dependencies
                .Dependencies
                .Select(o => Tuple.Create(o.Key.MemberDocId, o.Value.Count))
                .OrderBy(o => o.Item1, StringComparer.Ordinal)
                .ToList();

            var expectedOrdered = expected
                .OrderBy(o => o.Item1, StringComparer.Ordinal)
                .ToList();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var item in foundDocIds)
            {
                sb.AppendLine(string.Format("yield return Tuple.Create(\"{0}\", 1);", item.Item1));
            }

            Assert.Equal(expectedOrdered.Count, foundDocIds.Count);

            foreach (var combined in expectedOrdered.Zip(foundDocIds, Tuple.Create))
            {
                var expectedItem = combined.Item1;
                var actualItem = combined.Item2;

                Assert.Equal(expectedItem.Item1, actualItem.Item1);
                Assert.Equal(expectedItem.Item2, actualItem.Item2);
            }
        }
        private void TestForDocId(string source, string docid, bool allowUnsafe)
        {
            var assembly = TestAssembly.Create(source, allowUnsafe);

            var dependencyFinder = new ReflectionMetadataDependencyFinder();
            var assemblyToTestFileInfo = new FileInfo(assembly.AssemblyPath);
            var progressReporter = Substitute.For<IProgressReporter>();

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

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

            Assert.True(false, $"Could not find docid '{docid}'");
        }
        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);
        }
        public void EmptyProject()
        {
            var assemblyToTest = TestAssembly.Create("EmptyProject.cs");
            var expected = EmptyProjectMemberDocId();

            var dependencyFinder = new ReflectionMetadataDependencyFinder(new AlwaysTrueDependencyFilter());
            var progressReporter = Substitute.For<IProgressReporter>();

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

            var foundDocIds = dependencies
                .Dependencies
                .Select(o => Tuple.Create(o.Key.MemberDocId, o.Value.Count))
                .OrderBy(o => o.Item1, StringComparer.Ordinal)
                .ToList();

            var expectedOrdered = expected
                .OrderBy(o => o.Item1, StringComparer.Ordinal)
                .ToList();

            Assert.Equal(expectedOrdered.Count, foundDocIds.Count);

            foreach (var combined in expectedOrdered.Zip(foundDocIds, Tuple.Create))
            {
                var expectedItem = combined.Item1;
                var actualItem = combined.Item2;

                Assert.Equal(expectedItem.Item1, actualItem.Item1);
                Assert.Equal(expectedItem.Item2, actualItem.Item2);
            }
        }
        public void VerifyFilter()
        {
            var expected = new[]
            {
                "M:Microsoft.Bar.Test`1.Get",
                "M:Other.Test`1.Get",
                "T:Microsoft.Bar.Test`1",
                "T:Other.Test`1"
            };

            var dependencyFinder = new ReflectionMetadataDependencyFinder(new AssemblyNameFilter("FilterApis"));
            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);
        }
        private void CompareSpecificDependency(string path, string v)
        {
            var dependencyFinder = new ReflectionMetadataDependencyFinder();
            var assemblyToTestFileInfo = new FileInfo(path);
            var progressReporter = Substitute.For<IProgressReporter>();

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

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

            Assert.True(false, $"Could not find docid '{v}'");
        }