コード例 #1
0
        public void GetCompilationReferences_CombinesApplicationPartAndOptionMetadataReferences()
        {
            // Arrange
            var options = new RazorViewEngineOptions();
            var objectAssemblyLocation          = typeof(object).GetTypeInfo().Assembly.Location;
            var objectAssemblyMetadataReference = MetadataReference.CreateFromFile(objectAssemblyLocation);

            options.AdditionalCompilationReferences.Add(objectAssemblyMetadataReference);

            var applicationPartManager = GetApplicationPartManager();
            var feature = new MetadataReferenceFeature();

            applicationPartManager.PopulateFeature(feature);
            var partReferences            = feature.MetadataReferences;
            var expectedReferenceDisplays = partReferences
                                            .Concat(new[] { objectAssemblyMetadataReference })
                                            .Select(r => r.Display);
            var referenceManager = new DefaultRazorReferenceManager(
                applicationPartManager,
                Options.Create(options));

            // Act
            var references        = referenceManager.CompilationReferences;
            var referenceDisplays = references.Select(reference => reference.Display);

            // Assert
            Assert.Equal(expectedReferenceDisplays, referenceDisplays);
        }
コード例 #2
0
        public void PopulateFeature_ReturnsEmptyList_IfNoAssemblyPartsAreRegistered()
        {
            // Arrange
            var applicationPartManager = new ApplicationPartManager();

            applicationPartManager.ApplicationParts.Add(Mock.Of <ApplicationPart>());
            applicationPartManager.FeatureProviders.Add(new MetadataReferenceFeatureProvider());
            var feature = new MetadataReferenceFeature();

            // Act
            applicationPartManager.PopulateFeature(feature);

            // Assert
            Assert.Empty(feature.MetadataReferences);
        }
コード例 #3
0
        private IReadOnlyList <MetadataReference> GetCompilationReferences()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var feature = new MetadataReferenceFeature();
#pragma warning restore CS0618 // Type or member is obsolete
            _partManager.PopulateFeature(feature);
            var applicationReferences = feature.MetadataReferences;

            if (_additionalMetadataReferences.Count == 0)
            {
                return(applicationReferences.ToArray());
            }

            var compilationReferences = new List <MetadataReference>(applicationReferences.Count + _additionalMetadataReferences.Count);
            compilationReferences.AddRange(applicationReferences);
            compilationReferences.AddRange(_additionalMetadataReferences);

            return(compilationReferences);
        }
コード例 #4
0
        public void PopulateFeature_AddsMetadataReferenceForAssemblyPartsWithDependencyContext()
        {
            // Arrange
            var applicationPartManager = new ApplicationPartManager();
            var currentAssembly        = GetType().GetTypeInfo().Assembly;
            var assemblyPart1          = new AssemblyPart(currentAssembly);

            applicationPartManager.ApplicationParts.Add(assemblyPart1);
            var assemblyPart2 = new AssemblyPart(typeof(MetadataReferenceFeatureProvider).GetTypeInfo().Assembly);

            applicationPartManager.ApplicationParts.Add(assemblyPart2);
            applicationPartManager.FeatureProviders.Add(new MetadataReferenceFeatureProvider());
            var feature = new MetadataReferenceFeature();

            // Act
            applicationPartManager.PopulateFeature(feature);

            // Assert
            Assert.Contains(
                feature.MetadataReferences,
                reference => reference.Display.Equals(currentAssembly.Location));
        }