public void DoesNotReturnErrors_WhenOptionalArgumentsMissing() { var expectedResult = new MetadataGeneratorOptions { Package = @"Cake.Common" }; var parserResult = Subject.Parse <MetadataGeneratorOptions>(new[] { "--Package", "Cake.Common" }); parserResult.Should().NotBeNull(); parserResult.Errors.Should().BeEmpty(); parserResult.Result.Should().NotBeNull(); parserResult.Result.ShouldBeEquivalentTo(expectedResult); }
public void ReturnsNull_WhenNugetPackageNotFound() { Get <IPackageManager>().InstallPackage(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <FrameworkName>()) .Returns((IPackage)null); var metadataGeneratorOptions = new MetadataGeneratorOptions { PackageVersion = "0.17.0", Package = "Cake.Common", TargetFramework = ".NETFramework,Version=v4.5" }; var result = Subject.Generate(metadataGeneratorOptions); result.Should().BeNull(); Get <IPackageManager>() .Received(1) .InstallPackage( Arg.Is <string>(val => val == metadataGeneratorOptions.Package), Arg.Is <string>(val => val == metadataGeneratorOptions.PackageVersion), Arg.Is <FrameworkName>(val => val.FullName == metadataGeneratorOptions.TargetFramework)); }
public GeneratorResult Generate(MetadataGeneratorOptions options) { var generatorResult = new GeneratorResult(); var targetFramework = new FrameworkName(options.TargetFramework); var package = _packageManager.InstallPackage(options.Package, options.PackageVersion, targetFramework); if (package == null) { Logger.Error("Unable to find package {0} {1}", options.Package, options.PackageVersion ?? string.Empty); return(null); } if (!string.IsNullOrWhiteSpace(options.OutputFolder) && !_fileSystem.DirectoryExists(options.OutputFolder)) { _fileSystem.CreateDirectory(options.OutputFolder); } var packages = _dependencyResolver.GetDependenciesAndSelf(package, targetFramework).ToList(); var assemblies = _packageAssemblyResolver.ResolveAssemblies(package, targetFramework); foreach (var assembly in assemblies) { var compilationUnit = _cakeSourceGenerator.Generate(assembly); var rewrittenNode = _cakeSyntaxRewriterService.Rewrite(compilationUnit, assembly); var emitedAssemblyName = $"{assembly.GetName().Name}.{MetadataClassSuffix}"; var compilation = _compilationProvider.Get( emitedAssemblyName, new[] { SyntaxFactory.ParseSyntaxTree(rewrittenNode.NormalizeWhitespace().ToFullString()) }, _metadataReferenceLoader.CreateFromPackages(packages, targetFramework), new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var result = _compiler.Compile(compilation, Path.Combine(options.OutputFolder ?? string.Empty, $"{emitedAssemblyName}.dll")); generatorResult.EmitedAssemblies.Add(result); generatorResult.SourceAssemblies.Add(assembly); } return(generatorResult); }
public void CanParseAllMetadataGeneratorOptions() { var expectedResult = new MetadataGeneratorOptions { OutputFolder = @"C:\Temp", PackageVersion = "0.17.0", Package = "Cake.Common", TargetFramework = ".NETFramework,Version=v4.5" }; var parserResult = Subject.Parse <MetadataGeneratorOptions>(new[] { "--Package", "Cake.Common", "--PackageVersion", "0.17.0", "--OutputFolder", @"C:\Temp", "--TargetFramework", ".NETFramework,Version=v4.5" }); parserResult.Should().NotBeNull(); parserResult.Errors.Should().BeEmpty(); parserResult.Result.Should().NotBeNull(); parserResult.Result.ShouldBeEquivalentTo(expectedResult); }