private static void VerifyContextWithAdditionalReferences(CompilationAssemblyResolverDependencyContext dc
                                                                  , string expectedPath, StringComparison comparisonType, Action <Assembly> verification)
        {
            var attemptedAssemblyResolution = dc.AssertNotNull()[expectedPath.AssertNotNull().AssertNotEmpty(), comparisonType];

            verification.AssertNotNull().Invoke(attemptedAssemblyResolution);
        }
        public void Resolvers_Correct_After_Standalone_Reference_Added()
        {
            void Verify(string path, ref CompilationAssemblyResolverDependencyContext dc
                        , Action <CompositeCompilationAssemblyResolver, ICompilationAssemblyResolver[]> verify)
            {
                path = GetFullPath(path.AssertFileExists());

                dc = dc ?? DefaultContext.AssertTrue(x => x.AssertNotNull().Context.AssertNotNull() != null);

                var ac = dc;

                ac.AssertSame(dc);

                ac.AddDependency(path.AssertFileExists());

                var actualResolver = ac.Resolver.AssertNotNull();

                // TODO: TBD: a deeper question here is this: should ReferenceAssemblyPathResolver/PackageCompilationAssemblyResolver happen with every added dependency? or just the first one?
                // TODO: TBD: might be worth reviewing the original code and determine how that was done... and/or contact the author(s) to determine the finer points...
                // With deeper levels simply walking lambda arguments to the next letters.
                actualResolver.AssertReflectedField(InternalResolvers, InternalResolversBindingFlags, verify);
            }

            CompilationAssemblyResolverDependencyContext actualContext = null;

            void Verification(CompositeCompilationAssemblyResolver v, ICompilationAssemblyResolver[] f)
            {
                f.AssertNotNull().AssertNotEmpty().AssertTrue(x => x.Length == 2);

                f[0].AssertNotNull().AssertIsType <CompositeCompilationAssemblyResolver>()
                .AssertReflectedField(InternalResolvers, InternalResolversBindingFlags
                                      , (CompositeCompilationAssemblyResolver w, ICompilationAssemblyResolver[] g) =>
                {
                    g.AssertNotNull().AssertNotEmpty().AssertTrue(x => x.Length == 2);
                    g[0].AssertNotNull().AssertIsType <ReferenceAssemblyPathResolver>();
                    g[1].AssertNotNull().AssertIsType <PackageCompilationAssemblyResolver>();
                });

                f[1].AssertNotNull().AssertIsType <AppBaseCompilationAssemblyResolver>();
            }

            var firstPath = KingdomSimpleCalculatorsPath.AssertNotNull().AssertNotEmpty();

            // TODO: TBD: consider refactoring a general use private static method for use with both standalone and chaining dependencies...
            Verify(firstPath, ref actualContext, Verification);

            var expectedContextContext = actualContext.Context.AssertNotNull();

            actualContext.AssertNotNull();

            Verify(firstPath.AssertNotNull().AssertNotEmpty(), ref actualContext, Verification);

            actualContext.AssertNotNull().Context.AssertNotNull().AssertSame(expectedContextContext);

            expectedContextContext.AssertTrue(
                x => x.CompileLibraries.Any(y => HasLibrary(y, firstPath)) ||
                x.RuntimeLibraries.Any(y => HasLibrary(y, firstPath))
                );
        }
Esempio n. 3
0
        /// <summary>
        /// Internal Constructor.
        /// </summary>
        /// <param name="outputDirectory">The Output Directory.</param>
        /// <param name="registryFileName">The Registry File Name.</param>
        /// <param name="additionalReferencePaths">The Additional Reference Paths.</param>
        /// <param name="searchPaths">The Assembly Search Paths.</param>
        /// <inheritdoc />
        internal AssemblyReferenceServiceManager(string outputDirectory, string registryFileName
                                                 , IReadOnlyCollection <string> additionalReferencePaths, IReadOnlyCollection <string> searchPaths)
            : base(outputDirectory, registryFileName, () => AssemblyDescriptorRegistryJsonConverter.Converter)
        {
            Verify.Operation(additionalReferencePaths != null, FormatVerifyOperationMessage(nameof(additionalReferencePaths)));
            Verify.Operation(searchPaths != null, FormatVerifyOperationMessage(nameof(searchPaths)));

            AdditionalReferencePaths = additionalReferencePaths;
            SearchPaths = searchPaths;

            PrivateDependencyContext = new CompilationAssemblyResolverDependencyContext(additionalReferencePaths);
        }
        public void Resolvers_Correct_After_Dependency_References_Added()
        {
            void Verify(string path, ref CompilationAssemblyResolverDependencyContext dc
                        , Action <CompositeCompilationAssemblyResolver, ICompilationAssemblyResolver[]> verify)
            {
                path = GetFullPath(path.AssertFileExists());

                dc = dc ?? DefaultContext.AssertTrue(x => x.AssertNotNull().Context.AssertNotNull() != null);

                var ac = dc;

                ac.AssertSame(dc);

                ac.AddDependency(path.AssertFileExists());

                var actualResolver = ac.Resolver.AssertNotNull();

                actualResolver.AssertReflectedField(InternalResolvers, InternalResolversBindingFlags, verify);
            }

            // TODO: TBD: first of all... this is correct? As we fold in more references, the resolution folds in on itself?
            CompilationAssemblyResolverDependencyContext actualContext = null;

            void BaseVerification(CompositeCompilationAssemblyResolver v, ICompilationAssemblyResolver[] f)
            {
                f.AssertNotNull().AssertNotEmpty().AssertTrue(x => x.Length == 2);

                f[0].AssertNotNull().AssertIsType <CompositeCompilationAssemblyResolver>()
                .AssertReflectedField(InternalResolvers, InternalResolversBindingFlags
                                      , (CompositeCompilationAssemblyResolver w, ICompilationAssemblyResolver[] g) =>
                {
                    g.AssertNotNull().AssertNotEmpty().AssertTrue(x => x.Length == 2);
                    g[0].AssertNotNull().AssertIsType <ReferenceAssemblyPathResolver>();
                    g[1].AssertNotNull().AssertIsType <PackageCompilationAssemblyResolver>();
                });

                f[1].AssertNotNull().AssertIsType <AppBaseCompilationAssemblyResolver>();
            }

            var firstPath = KingdomSimpleServicesDefinitionsPath.AssertNotNull().AssertNotEmpty();

            // With deeper levels simply walking lambda arguments to the next letters.
            Verify(firstPath, ref actualContext, BaseVerification);

            var expectedContextContext = actualContext.Context.AssertNotNull();

            expectedContextContext.AssertTrue(
                x => x.CompileLibraries.Any(y => HasLibrary(y, firstPath)) ||
                x.RuntimeLibraries.Any(y => HasLibrary(y, firstPath))
                );

            var secondPath = KingdomSimpleServicesPath.AssertNotNull().AssertNotEmpty();

            Verify(secondPath, ref actualContext
                   , (v, f) =>
            {
                f.AssertNotNull().AssertNotEmpty();
                f.AssertTrue(x => x.Length == 2);

                f[0].AssertNotNull().AssertIsType <CompositeCompilationAssemblyResolver>()
                .AssertReflectedField(InternalResolvers, InternalResolversBindingFlags
                                      , (CompositeCompilationAssemblyResolver w, ICompilationAssemblyResolver[] g) =>
                {
                    g.AssertNotNull().AssertNotEmpty().AssertTrue(x => x.Length == 2);

                    g[0].AssertIsType <CompositeCompilationAssemblyResolver>()
                    .AssertReflectedField(InternalResolvers, InternalResolversBindingFlags
                                          , (CompositeCompilationAssemblyResolver x, ICompilationAssemblyResolver[] h) =>
                    {
                        h.AssertNotNull().AssertNotEmpty().AssertTrue(y => y.Length == 2);
                        h[0].AssertNotNull().AssertIsType <ReferenceAssemblyPathResolver>();
                        h[1].AssertNotNull().AssertIsType <PackageCompilationAssemblyResolver>();
                    });

                    g[1].AssertNotNull().AssertIsType <AppBaseCompilationAssemblyResolver>();
                });

                f[1].AssertNotNull().AssertIsType <AppBaseCompilationAssemblyResolver>();
            });

            var actualContextContext = actualContext.AssertNotNull().Context.AssertNotNull();

            actualContextContext.AssertNotSame(expectedContextContext);

            actualContextContext.AssertTrue(
                x => x.CompileLibraries.Any(y => HasLibrary(y, secondPath)) ||
                x.RuntimeLibraries.Any(y => HasLibrary(y, secondPath))
                );
        }