public void CanResolveTypeFromReference() { var pluginNamespace = "TestPlugins"; var pluginClass = "MyPlugin"; var pluginAssembly = "MyPlugins"; var pluginWorkspace = TestWorkspaceFactory.GetWorkspace(null, pluginNamespace, pluginClass, pluginAssembly); var pluginBinary = TestWorkspaceFactory.BuildAndGetPe(pluginWorkspace); string pluginPath = $"Z:\\plugins\\{pluginAssembly}.dll"; var reference = AssemblyMetadata.CreateFromImage(pluginBinary).GetReference(filePath: pluginPath, display: $"{pluginAssembly}.dll"); var workspace = TestWorkspaceFactory.GetWorkspace(new[] { reference }); var pathMock = new Mock <IPath>(MockBehavior.Strict); pathMock.Setup(p => p.GetFileName(It.IsAny <string>())).Returns <string>(v => Path.GetFileName(v)); var fileMock = new Mock <IFile>(MockBehavior.Strict); fileMock.Setup(f => f.ReadAllBytes(It.Is <string>(v => v == pluginPath))).Returns(pluginBinary); var fileSystemMock = new Mock <IFileSystem>(MockBehavior.Strict); fileSystemMock.Setup(p => p.Path).Returns(pathMock.Object); fileSystemMock.Setup(p => p.File).Returns(fileMock.Object); var subject = new ProjectReferenceTypeLoader(new WorkspaceManager(workspace), fileSystemMock.Object, AssemblyLoadContext.Default); Action action = () => { subject.LoadType($"{pluginNamespace}.{pluginClass}, {pluginAssembly}"); }; //// Temporary thing. I hope. action.Should().Throw <FileNotFoundException>(); }
public void CanLoadTypeFromWorkspace() { var pluginNamespace = "TestPlugins"; var pluginClass = "MyPlugin"; var pluginAssembly = "MyPlugins"; var pluginWorkspace = TestWorkspaceFactory.GetWorkspace(null, pluginNamespace, pluginClass, pluginAssembly); var subject = new WorkspaceTypeLoader(new WorkspaceManager(pluginWorkspace), AssemblyLoadContext.Default); var result = subject.LoadType($"{pluginNamespace}.{pluginClass}, {pluginAssembly}"); Assert.IsNotNull(result); Assert.AreEqual(pluginClass, result.Name); }
public void CanConstructPipeine() { var fileSystem = new Mock <IFileSystem>(MockBehavior.Strict).Object; var logger = new Mock <ILogger>(MockBehavior.Loose).Object; var basePath = "z:\\fakepath"; var workspaceManager = new WorkspaceManager(TestWorkspaceFactory.GetWorkspace()); PipelineWorkspaceManagersWrapper workspaces = new PipelineWorkspaceManagersWrapper(workspaceManager, workspaceManager); BuilderRegistry builders = new BuilderRegistry(); builders.Register <ICodeFileDestination>(new WorkspaceCodeFileDestinationBuilder(workspaces)); builders.Register <ICodeFileSelector>(new CodeFileSelectorBuilder()); var config = JObject.Parse(Resources.IntegrationTestConfig01); var subject = new PipelineBuilder(builders, workspaces, basePath, fileSystem, new DefaultTypeLoader(), logger); var result = subject.Build(config); result.Should().NotBeNull(); var pipeline = result as CodeGenerationPipeline; pipeline.InputCodeStreamProvider.Should().NotBeNull(); pipeline.PipelineEnvironment.Should().NotBeNull(); pipeline.Batches.Should().NotBeNull(); pipeline.Batches.Count.Should().Be(1); pipeline.Batches[0].Shadow.Should().NotBeNull(); pipeline.Batches[0].Shadow.Count.Should().Be(1); pipeline.Batches[0].Shadow[0].Language.Should().Be("CSharp"); pipeline.Batches[0].Shadow[0].Filter.Should().NotBeNull(); pipeline.Batches[0].Shadow[0].Filter.Should().BeOfType <WorkspaceCodeFileLocationFilter>(); }