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 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.º 3
0
 /// <summary>
 /// This will search the input given and find all paths
 /// </summary>
 /// <param name="path">A file and directory path</param>
 /// <param name="isExplicitlySpecified">Whether the assembly was explicitly specified</param>
 private void UpdateInputAssemblies(string path, bool isExplicitlySpecified)
 {
     if (Directory.Exists(path))
     {
         foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
         {
             // If the user passes in a whole directory, any assembly we find in there
             // was not explicitly passed in.
             UpdateInputAssemblies(file, isExplicitlySpecified: false);
         }
     }
     else if (File.Exists(path))
     {
         // Only add files with valid PE extensions to the list of
         // assemblies to analyze since others are not valid assemblies
         if (HasValidPEExtension(path))
         {
             var filePath = new FilePathAssemblyFile(path);
             if (_inputAssemblies.TryGetValue(filePath, out var isAssemblySpecified))
             {
                 // If the assembly already exists, and it was not
                 // specified explicitly, in the the case where one
                 // value does not match the other, we default to
                 // saying that the assembly is specified.
                 _inputAssemblies[filePath] = isExplicitlySpecified || isAssemblySpecified;
             }
             else
             {
                 _inputAssemblies.Add(filePath, isExplicitlySpecified);
             }
         }
     }
     else
     {
         _invalidInputFiles.Add(path);
     }
 }
        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>());
        }
Exemplo n.º 5
0
        private static (ImmutableDictionary <IAssemblyFile, bool>, IReadOnlyCollection <string>) ProcessInputAssemblies(IEnumerable <string> files)
        {
            var s_ValidExtensions = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
            {
                ".dll",
                ".exe",
                ".winmd",
                ".ilexe",
                ".ildll"
            };

            var inputAssemblies   = new SortedDictionary <IAssemblyFile, bool>(AssemblyFileComparer.Instance);
            var invalidInputFiles = new List <string>();

            void ProcessInputAssemblies(string path, bool isExplicitlySpecified)
            {
                bool HasValidPEExtension(string assemblyLocation)
                {
                    return(s_ValidExtensions.Contains(Path.GetExtension(assemblyLocation)));
                }

                if (Directory.Exists(path))
                {
                    foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
                    {
                        // If the user passes in a whole directory, any assembly we find in there
                        // was not explicitly passed in.
                        ProcessInputAssemblies(file, isExplicitlySpecified: false);
                    }
                }
                else if (File.Exists(path))
                {
                    // Only add files with valid PE extensions to the list of
                    // assemblies to analyze since others are not valid assemblies
                    if (HasValidPEExtension(path))
                    {
                        var filePath = new FilePathAssemblyFile(path);
                        if (inputAssemblies.TryGetValue(filePath, out var isAssemblySpecified))
                        {
                            // If the assembly already exists, and it was not
                            // specified explicitly, in the the case where one
                            // value does not match the other, we default to
                            // saying that the assembly is specified.
                            inputAssemblies[filePath] = isExplicitlySpecified || isAssemblySpecified;
                        }
                        else
                        {
                            inputAssemblies.Add(filePath, isExplicitlySpecified);
                        }
                    }
                }
                else
                {
                    invalidInputFiles.Add(path);
                }
            }

            foreach (var file in files)
            {
                ProcessInputAssemblies(file, isExplicitlySpecified: true);
            }

            return(inputAssemblies.ToImmutableDictionary(), invalidInputFiles);
        }