public void MultidimensionalPrimitiveArray()
        {
            var arrayDocId     = "M:System.Int32[0:,0:][0:,0:].#ctor(System.Int32,System.Int32)";
            var objectDocId    = "T:System.Object";
            var assemblyToTest = TestAssembly.Create("MultidimensionalPrimitiveArray.cs");

            var filter           = new DotNetFrameworkFilter();
            var dependencyFinder = new ReflectionMetadataDependencyFinder(filter, new SystemObjectFinder(filter));
            var progressReporter = Substitute.For <IProgressReporter>();
            var dependencies     = dependencyFinder.FindDependencies(new[] { assemblyToTest }, progressReporter);

            var primitiveArray = dependencies.Dependencies.FirstOrDefault(o => string.Equals(o.Key.MemberDocId, arrayDocId, StringComparison.Ordinal)).Key;

            Assert.NotNull(primitiveArray);
            var systemObject = dependencies.Dependencies.FirstOrDefault(o => string.Equals(o.Key.MemberDocId, objectDocId, StringComparison.Ordinal)).Key;

            Assert.NotNull(systemObject);

            //Test that the DefinedInAssemblyIdentity of the primitive array is not null/empty and it is the same as the one of System.Object
            var definedInAssemblyIdentity = primitiveArray.DefinedInAssemblyIdentity;

            var isNullOrWhiteSpace = string.IsNullOrWhiteSpace(definedInAssemblyIdentity);

            Assert.False(isNullOrWhiteSpace);
            Assert.Equal(systemObject.DefinedInAssemblyIdentity, definedInAssemblyIdentity);
        }
        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"
            }
            .Concat(FilterApisDocIds)
            .OrderBy(x => x, StringComparer.Ordinal);

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

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

            Assert.Equal(expected, foundDocIds);
        }
        public void EmptyProject()
        {
            var assemblyToTest = TestAssembly.Create("EmptyProject.cs");
            var expected       = EmptyProjectMemberDocId();

            var filter           = new AlwaysTrueDependencyFilter();
            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(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 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 actual.Zip(s_expectedResult, 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>());
        }
        public void VerifyDotNetFrameworkFilter()
        {
            var filter           = new DotNetFrameworkFilter();
            var dependencyFinder = new ReflectionMetadataDependencyFinder(filter, new SystemObjectFinder(filter));
            var assemblyToTest   = TestAssembly.Create("FilterApis.cs");

            var expected = FilterApisDocIds
                           .Concat(new[] {
                "M:System.Uri.TryCreate(System.String,System.UriKind,System.Uri@)",
                "T:System.Uri",
                "T:System.UriKind"
            })
                           .OrderBy(x => x, StringComparer.Ordinal);

            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);
        }
Example #6
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"
            };

            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 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 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);

            var found = dependencies.Dependencies
                        .Any(d => string.Equals(d.Key.MemberDocId, v, StringComparison.Ordinal));

            Assert.True(found, $"Could not find docid '{v}'");
        }
        public void ThrowsSystemObjectNotFoundException()
        {
            var dependencyFilter = Substitute.For <IDependencyFilter>();

            dependencyFilter.IsFrameworkAssembly(Arg.Any <AssemblyReferenceInformation>()).Returns(false);
            var dependencyFinder = new ReflectionMetadataDependencyFinder(dependencyFilter, new SystemObjectFinder(dependencyFilter));
            var assemblyToTest   = TestAssembly.Create("FilterApis.cs", false, new[] { typeof(Image).GetTypeInfo().Assembly.Location });
            var progressReporter = Substitute.For <IProgressReporter>();

            var exception = Assert.Throws <AggregateException>(() =>
            {
                var dependencies = dependencyFinder.FindDependencies(new[] { assemblyToTest }, progressReporter);
            });

            Assert.IsType <SystemObjectNotFoundException>(exception.InnerException);
        }
Example #10
0
        public void ThrowsSystemObjectNotFoundException()
        {
            var dependencyFilter = Substitute.For <IDependencyFilter>();

            dependencyFilter.IsFrameworkAssembly(Arg.Any <string>(), Arg.Any <PublicKeyToken>()).Returns(false);
            var dependencyFinder = new ReflectionMetadataDependencyFinder(dependencyFilter, new SystemObjectFinder(dependencyFilter));
            var assemblyToTest   = TestAssembly.Create("FilterApis.cs", _output);
            var progressReporter = Substitute.For <IProgressReporter>();

            var exception = Assert.Throws <AggregateException>(() =>
            {
                var dependencies = dependencyFinder.FindDependencies(new[] { assemblyToTest }, progressReporter);
            });

            Assert.IsType <SystemObjectNotFoundException>(exception.InnerException);
        }
        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);
        }
Example #12
0
        public void AssemblyWithNoReferencesIsSkipped()
        {
            var dependencyFilter = Substitute.For <IDependencyFilter>();

            dependencyFilter.IsFrameworkAssembly(Arg.Any <string>(), Arg.Any <PublicKeyToken>()).Returns(false);
            var dependencyFinder = new ReflectionMetadataDependencyFinder(dependencyFilter, new SystemObjectFinder(dependencyFilter));
            var file             = TestAssembly.Create("ResourceAssembliesGetSkipped_NoReferences.il", _output);
            var progressReporter = Substitute.For <IProgressReporter>();

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

            Assert.Empty(dependencies.AssembliesWithErrors);
            Assert.Empty(dependencies.UnresolvedAssemblies);
            var assembly = Assert.Single(dependencies.UserAssemblies);

            Assert.Equal("NoReferences, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", assembly.AssemblyIdentity);
        }
Example #13
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);
        }
        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();

            Assert.Equal(expectedOrdered, foundDocIds);
        }
Example #15
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));
        }
        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>());
        }