コード例 #1
0
 public async Task Scan_No_StartingPath_Throws_ArgumentException()
 {
     var scanner = new DefaultAssemblyScanner((s) => null, () => null);
     await Assert.ThrowsExceptionAsync <ArgumentException>(() => scanner.Scan(new AssemblyScannerOptions
     {
         PluginType = typeof(ITestPlugin)
     }));
 }
コード例 #2
0
 public async Task Scan_No_PluginType_Throws_ArgumentException()
 {
     var scanner = new DefaultAssemblyScanner((s) => null, () => null);
     await Assert.ThrowsExceptionAsync <ArgumentException>(() => scanner.Scan(new AssemblyScannerOptions
     {
         StartingPath = "/home/maarten"
     }));
 }
コード例 #3
0
 public async Task Scan_Unrooted_Path_Throws_AssemblyScanningException()
 {
     var scanner = new DefaultAssemblyScanner((s) => null, () => null);
     await Assert.ThrowsExceptionAsync <AssemblyScanningException>(() => scanner.Scan(new AssemblyScannerOptions
     {
         StartingPath = "../home/maarten",
         PluginType   = typeof(ITestPlugin)
     }));
 }
コード例 #4
0
        public async Task Scan_Succeeds()
        {
            var startingPath        = "/home/maarten";
            var metadataLoadContext = this.mockRepository.Create <IMetadataLoadContext>();
            var assemblyShim        = this.mockRepository.Create <IAssemblyShim>();
            var directoryTraverser  = this.mockRepository.Create <IDirectoryTraverser>();

            directoryTraverser.Setup(d => d.TraverseDirectories(startingPath)).Returns(new[] { "pathy/mcpathface" });
            directoryTraverser.Setup(d => d.TraverseFiles(It.IsAny <string>(), It.IsAny <IEnumerable <string> >())).Returns(new[] { "filey.mcfile.face" });

            var contract = TestableTypeBuilder.New()
                           .WithName("IMyTestType")
                           .WithNamespace("Test.Type")
                           .Build();

            var pluginAttributeTypedValue = new CustomAttributeTypedArgument(contract);
            var pluginAttribute           = new TestableAttribute
            {
                _AttributeType  = typeof(Prise.Plugin.PluginAttribute),
                _NamedArguments = new[] { new CustomAttributeNamedArgument(new TestableMemberInfo {
                        _Name = "PluginType"
                    }, pluginAttributeTypedValue) }
            };

            var testableType = TestableTypeBuilder.New()
                               .WithCustomAttributes(pluginAttribute)
                               .WithName("MyTestType")
                               .WithNamespace("Test.Type")
                               .Build();

            assemblyShim.Setup(a => a.Types).Returns(new[] { testableType });

            metadataLoadContext.Setup(c => c.LoadFromAssemblyName(It.IsAny <string>())).Returns(assemblyShim.Object);

            var scanner = new DefaultAssemblyScanner(
                (s) => metadataLoadContext.Object,
                () => directoryTraverser.Object
                );
            var types = await scanner.Scan(new AssemblyScannerOptions
            {
                StartingPath = startingPath,
                PluginType   = contract
            });

            var result = types.FirstOrDefault();

            Assert.IsNotNull(result);
            Assert.AreEqual("MyTestType", result.PluginType.Name);
            Assert.AreEqual("Test.Type", result.PluginType.Namespace);
        }
コード例 #5
0
 public async Task Scan_No_Options_Throws_ArgumentNullException()
 {
     var scanner = new DefaultAssemblyScanner((s) => null, () => null);
     await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => scanner.Scan(null));
 }