Example #1
0
        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"
            }
            .OrderBy(x => x, StringComparer.Ordinal);

            var assemblyToTest   = TestAssembly.Create($"FilterApis.cs", _output);
            var filter           = new AssemblyFileFrameworkFilter(assemblyToTest);
            var dependencyFinder = new ReflectionMetadataDependencyFinder(filter, new SystemObjectFinder(filter));
            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);
            }

            var except  = expected.Except(foundDocIds).ToArray();
            var except2 = foundDocIds.Except(expected).ToArray();

            Assert.Equal(expected, foundDocIds);
        }
Example #2
0
        private void TestForDocIdHelper(string source, string docid, bool allowUnsafe)
        {
            var assemblyToTest   = TestAssembly.Create(source, _output, allowUnsafe);
            var filter           = new AssemblyFileFrameworkFilter(assemblyToTest);
            var dependencyFinder = new ReflectionMetadataDependencyFinder(filter, new SystemObjectFinder(filter));
            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));
        }
        public void UnresolvedAssemblyTest()
        {
            var path = this.GetType().GetTypeInfo().Assembly.Location;
            var referencedAssemblies = this.GetType().GetTypeInfo().Assembly.GetReferencedAssemblies()
                                       .Select(a => a.ToString())
                                       .OrderBy(a => a)
                                       .ToList();
            var testInfo = new FilePathAssemblyFile(path);

            var filter         = new AssemblyFileFrameworkFilter(testInfo);
            var finder         = new ReflectionMetadataDependencyFinder(filter, new SystemObjectFinder(filter));
            var progressReport = Substitute.For <IProgressReporter>();

            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(referencedAssemblies.Count(), actual.Count());

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

            Assert.True(dependencies.UnresolvedAssemblies.All(o => o.Value.Count == 1));

            // Make sure no issues were found
            progressReport.Received(0).ReportIssue(Arg.Any <string>());
        }