示例#1
0
        public void TestProjectInformationMessageHandler_RequestMessage()
        {
            var projectContext = new CommonProjectContext()
            {
                AssemblyName     = "dummy",
                AssemblyFullPath = "dummyPath"
            };

            var handler = new ProjectInformationMessageHandler(projectContext, new MockLogger());
            var message = new Message()
            {
                MessageType     = MessageTypes.ProjectInfoRequest.Value,
                Payload         = null,
                HostId          = "test",
                ProtocolVersion = 1
            };

            var responseMessage = new Message()
            {
                MessageType     = MessageTypes.ProjectInfoResponse.Value,
                HostId          = "testClient",
                Payload         = JToken.FromObject(projectContext),
                ProtocolVersion = 1
            };

            mockSender.Setup(s => s.CreateMessage(MessageTypes.ProjectInfoResponse, projectContext, 1)).Returns(responseMessage);
            mockSender.Setup(s => s.Send(responseMessage)).Returns(true);
            handler.HandleMessage(mockSender.Object, message);

            mockSender.VerifyAll();
        }
        public async Task <IProjectContext> BuildProjectContext()
        {
            var context = new CommonProjectContext();

            var configuration          = project.ConfigurationManager.ActiveConfiguration.ConfigurationName;
            var vsHierarchy            = VsHierarchyHelper.GetProjectHierarchy(serviceProvider, project);
            var targetPath             = msBuildProjectPropertyService.GetPropertyValue(vsHierarchy, "TargetPath", configuration);
            var outputType             = msBuildProjectPropertyService.GetPropertyValue(vsHierarchy, "OutputType", configuration);
            var targetFramework        = msBuildProjectPropertyService.GetPropertyValue(vsHierarchy, "TargetFramework", configuration);
            var targetFrameworkMoniker = project.Properties.Item("TargetFrameworkMoniker").Value.ToString();
            var targetPathDirectory    = Path.GetDirectoryName(targetPath);

            context.AssemblyFullPath      = targetPath;
            context.AssemblyName          = Path.GetFileName(targetPath);
            context.CompilationAssemblies = GetReferencedAssemblies();
            context.CompilationItems      = GetCompilationItems();
            context.Config        = targetPath + ".config";
            context.Configuration = configuration;
            context.DepsFile      = Path.Combine(targetPathDirectory,
                                                 msBuildProjectPropertyService.GetPropertyValue(vsHierarchy, "ProjectDepsFileName", configuration));
            context.EmbededItems                = Enumerable.Empty <string>();
            context.IsClassLibrary              = "Library".Equals(outputType, StringComparison.OrdinalIgnoreCase);
            context.PackageDependencies         = GetPackageDependencies(targetFramework);
            context.PackagesDirectory           = "";
            context.Platform                    = project.ConfigurationManager.ActiveConfiguration.PlatformName;
            context.ProjectFullPath             = project.FileName;
            context.ProjectName                 = project.Name;
            context.ProjectReferenceInformation = GetProjectReferenceInformation();
            context.ProjectReferences           = context.ProjectReferenceInformation.Select(pi => pi.FullPath).ToList();
            context.RootNamespace               = msBuildProjectPropertyService.GetPropertyValue(vsHierarchy, "RootNamespace", configuration);
            context.RuntimeConfig               = Path.Combine(targetPathDirectory,
                                                               msBuildProjectPropertyService.GetPropertyValue(vsHierarchy, "ProjectRuntimeConfigFileName", configuration));
            context.TargetDirectory = msBuildProjectPropertyService.GetPropertyValue(vsHierarchy, "TargetDir", configuration);
            context.TargetFramework = targetFrameworkMoniker;


            var p1 = context.PackageDependencies.Single(p => p.Name == "CmdScaffolders" && p.Version == "1.0.0");

            p1.AddDependency(new Dependency("Microsoft.VisualStudio.Web.CodeGeneration", ""));

            return(context);
        }
示例#3
0
        public override bool Execute()
        {
            Console.WriteLine("HERE WE ARE!");

            var msBuildContext = new CommonProjectContext()
            {
                AssemblyFullPath      = this.AssemblyFullPath,
                AssemblyName          = string.IsNullOrEmpty(this.AssemblyName) ? Path.GetFileName(this.AssemblyFullPath) : this.AssemblyName,
                CompilationAssemblies = GetCompilationAssemblies(this.ResolvedReferences),
                CompilationItems      = this.CompilationItems.Select(i => i.ItemSpec),
                Config              = this.AssemblyFullPath + ".config",
                Configuration       = this.Configuration,
                DepsFile            = this.ProjectDepsFileName,
                EmbededItems        = this.EmbeddedItems.Select(i => i.ItemSpec),
                IsClassLibrary      = "Library".Equals(this.OutputType, StringComparison.OrdinalIgnoreCase),
                PackageDependencies = this.GetPackageDependencies(PackageDependencies),
                Platform            = this.Platform,
                ProjectFullPath     = this.ProjectFullPath,
                ProjectName         = this.Name,
                ProjectReferences   = this.ProjectReferences.Select(i => i.ItemSpec),
                RootNamespace       = this.RootNamespace,
                RuntimeConfig       = this.ProjectRuntimeConfigFileName,
                TargetDirectory     = this.TargetDirectory,
                TargetFramework     = this.TargetFramework
            };

            var projectReferences        = msBuildContext.ProjectReferences;
            var projReferenceInformation = GetProjectDependency(projectReferences, msBuildContext.ProjectFullPath);

            msBuildContext.ProjectReferenceInformation = projReferenceInformation;
            using (var streamWriter = new StreamWriter(File.Create(OutputFile)))
            {
                var json = JsonConvert.SerializeObject(msBuildContext);
                streamWriter.Write(json);
            }

            return(true);
        }
示例#4
0
        public void SupportFileLocationForExistingLayoutFileTest(bool leadTilde, bool leadSeparator, string[] existingLayoutFileParts, string[] expectedSupportFileLocationParts, string[] expectedLayoutFileParts)
        {
            string expectedSupportFileLocation;
            string expectedLayoutFile;

            if (expectedSupportFileLocationParts.Length > 0)
            {
                expectedSupportFileLocation = Path.Combine(expectedSupportFileLocationParts);
            }
            else
            {
                expectedSupportFileLocation = IdentityGeneratorTemplateModelBuilder._DefaultSupportLocation;
            }

            if (expectedLayoutFileParts.Length > 0)
            {
                expectedLayoutFile = Path.Combine(expectedLayoutFileParts);
            }
            else
            {
                expectedLayoutFile = Path.Combine(IdentityGeneratorTemplateModelBuilder._DefaultSupportLocation, IdentityGeneratorTemplateModelBuilder._LayoutFileName);
            }
            expectedLayoutFile = expectedLayoutFile.Replace("\\", "/");

            string existingLayoutFile = string.Empty;

            if (leadTilde)
            {
                existingLayoutFile += "~";
            }

            if (leadSeparator)
            {
                existingLayoutFile += Path.DirectorySeparatorChar;
            }

            if (existingLayoutFileParts.Length > 0)
            {
                existingLayoutFile = existingLayoutFile + Path.Combine(existingLayoutFileParts);
            }

            IdentityGeneratorCommandLineModel commandLineModel = new IdentityGeneratorCommandLineModel();

            commandLineModel.Layout = existingLayoutFile;

            IApplicationInfo     applicationInfo = new ApplicationInfo("test", LayoutFileLocationTestProjectBasePath);
            CommonProjectContext context         = new CommonProjectContext();

            context.ProjectFullPath       = LayoutFileLocationTestProjectBasePath;
            context.ProjectName           = "TestProject";
            context.AssemblyName          = "TestAssembly";
            context.CompilationItems      = new List <string>();
            context.CompilationAssemblies = new List <ResolvedReference>();

            Workspace workspace = new RoslynWorkspace(context);
            ICodeGenAssemblyLoadContext assemblyLoadContext = new DefaultAssemblyLoadContext();
            IFileSystem mockFileSystem = new MockFileSystem();
            ILogger     logger         = new ConsoleLogger();

            IdentityGeneratorTemplateModelBuilder modelBuilder = new IdentityGeneratorTemplateModelBuilder(commandLineModel, applicationInfo, context, workspace, assemblyLoadContext, mockFileSystem, logger);

            modelBuilder.DetermineSupportFileLocation(out string supportFileLocation, out string layoutFile);
            Assert.Equal(expectedSupportFileLocation, supportFileLocation);
            Assert.Equal(expectedLayoutFile, layoutFile);
        }