Exemple #1
0
 public async Task Scan_No_PluginType_Throws_ArgumentException()
 {
     var scanner = new DefaultNugetPackageAssemblyScanner((s) => null, () => null, () => null);
     await Assert.ThrowsExceptionAsync <ArgumentException>(() => scanner.Scan(new AssemblyScannerOptions
     {
         StartingPath = "/home/maarten"
     }));
 }
Exemple #2
0
 public async Task Scan_No_StartingPath_Throws_ArgumentException()
 {
     var scanner = new DefaultNugetPackageAssemblyScanner((s) => null, () => null, () => null);
     await Assert.ThrowsExceptionAsync <ArgumentException>(() => scanner.Scan(new AssemblyScannerOptions
     {
         PluginType = typeof(ITestPlugin)
     }));
 }
Exemple #3
0
 public async Task Scan_Unrooted_Path_Throws_AssemblyScanningException()
 {
     var scanner = new DefaultNugetPackageAssemblyScanner((s) => null, () => null, () => null);
     await Assert.ThrowsExceptionAsync <AssemblyScanningException>(() => scanner.Scan(new AssemblyScannerOptions
     {
         StartingPath = "../home/maarten",
         PluginType   = typeof(ITestPlugin)
     }));
 }
Exemple #4
0
        public async Task Scan_No_Nugets_Throws_AssemblyScanningException()
        {
            var startingPath   = "/home/maarten";
            var nugetUtilities = this.mockRepository.Create <INugetPackageUtilities>();

            nugetUtilities.Setup(n => n.FindAllNugetPackagesFiles(startingPath)).Returns(Enumerable.Empty <string>());
            var scanner = new DefaultNugetPackageAssemblyScanner((s) => null, () => null, () => nugetUtilities.Object);

            await Assert.ThrowsExceptionAsync <AssemblyScanningException>(() => scanner.Scan(new AssemblyScannerOptions
            {
                StartingPath = startingPath,
                PluginType   = typeof(ITestPlugin)
            }));
        }
Exemple #5
0
        public async Task Compressed_NugetPackage_Must_Be_UnCompressed()
        {
            var package              = "Prise.Plugin.Package.1.0.0.nupkg";
            var startingPath         = "/home/maarten";
            var nugetUtilities       = this.mockRepository.Create <INugetPackageUtilities>();
            var metadataLoadContext  = this.mockRepository.Create <IMetadataLoadContext>();
            var assemblyShim         = this.mockRepository.Create <IAssemblyShim>();
            var directoryTraverser   = this.mockRepository.Create <IDirectoryTraverser>();
            var actualNugetUtilities = new DefaultNugetPackageUtilities();

            nugetUtilities.Setup(n => n.FindAllNugetPackagesFiles(startingPath)).Returns(new[] { package });
            // Call actual implementation here
            nugetUtilities.Setup(n => n.GetVersionFromPackageFile(It.IsAny <string>())).Returns <string>((s) => actualNugetUtilities.GetVersionFromPackageFile(s));
            // Call actual implementation here
            nugetUtilities.Setup(n => n.GetPackageName(It.IsAny <string>())).Returns <string>((s) => actualNugetUtilities.GetPackageName(s));
            nugetUtilities.Setup(n => n.HasAlreadyBeenExtracted(It.IsAny <string>())).Returns(false);
            nugetUtilities.Setup(n => n.UnCompressNugetPackage(It.IsAny <string>(), It.IsAny <string>())).Verifiable();

            directoryTraverser.Setup(d => d.TraverseDirectories($"{startingPath}/_extracted")).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 DefaultNugetPackageAssemblyScanner(
                (s) => metadataLoadContext.Object,
                () => directoryTraverser.Object,
                () => nugetUtilities.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);
        }
Exemple #6
0
 public async Task Scan_No_Options_Throws_ArgumentNullException()
 {
     var scanner = new DefaultNugetPackageAssemblyScanner((s) => null, () => null, () => null);
     await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => scanner.Scan(null));
 }