public void SetupProjectWithModelPropertyInParentDbContextClass(TemporaryFileProvider fileProvider, ITestOutputHelper output)
        {
            fileProvider.Add("global.json", GlobalJsonText);
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Models"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Data"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Controllers"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "toolAssets", "netcoreapp2.0"));

            fileProvider.Add($"TestCodeGeneration.targets", MsBuildProjectStrings.DbContextInheritanceTestCodeGenerationTargetFileText);

            var msbuildTaskDllPath = Path.Combine(Path.GetDirectoryName(typeof(MsBuildProjectSetupHelper).Assembly.Location), "Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            fileProvider.Copy(msbuildTaskDllPath, "toolAssets/netcoreapp2.0/Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            var rootProjectTxt = MsBuildProjectStrings.DbContextInheritanceProjectTxt;

            fileProvider.Add(MsBuildProjectStrings.RootProjectName, rootProjectTxt);
            fileProvider.Add("Startup.cs", MsBuildProjectStrings.DerivedContextTestStartupText);
            fileProvider.Add(MsBuildProjectStrings.DbContextInheritanceProgramName, MsBuildProjectStrings.DbContextInheritanceProjectProgramText);
            fileProvider.Add(MsBuildProjectStrings.AppSettingsFileName, MsBuildProjectStrings.AppSettingsFileTxt);

            fileProvider.Add("Models/Blog.cs", MsBuildProjectStrings.BlogModelText);
            fileProvider.Add("Data/BaseDbContext.cs", MsBuildProjectStrings.BaseDbContextText);
            fileProvider.Add($"Data/{MsBuildProjectStrings.DerivedDbContextFileName}", MsBuildProjectStrings.DerivedDbContextText);

            RestoreAndBuild(fileProvider.Root, output);
        }
        public void SetupProjects(TemporaryFileProvider fileProvider, ITestOutputHelper output, bool fullFramework = false)
        {
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "toolAssets", "netstandard2.0"));
            fileProvider.Add("global.json", GlobalJsonText);

            var rootProjectTxt = fullFramework ? MsBuildProjectStrings.RootNet45ProjectTxt : MsBuildProjectStrings.RootProjectTxt;

            fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", rootProjectTxt);
            fileProvider.Add($"Root/TestCodeGeneration.targets", MsBuildProjectStrings.TestCodeGenerationTargetFileText);

            // Copy Msbuild task dlls.
            var msbuildTaskDllPath = Path.Combine(Path.GetDirectoryName(typeof(MsBuildProjectSetupHelper).Assembly.Location), "Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            fileProvider.Copy(msbuildTaskDllPath, "toolAssets/netstandard2.0/Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");
            fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupTxt);
            fileProvider.Add($"Root/{MsBuildProjectStrings.ProgramFileName}", MsBuildProjectStrings.ProgramFileText);

            fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
            fileProvider.Add($"Library1/ModelWithMatchingShortName.cs", "namespace Library1.Models { public class ModelWithMatchingShortName { } }");
            fileProvider.Add($"Library1/Car.cs", MsBuildProjectStrings.CarTxt);
            fileProvider.Add($"Library1/Product.cs", MsBuildProjectStrings.ProductTxt);
            RestoreAndBuild(Path.Combine(fileProvider.Root, "Root"), output);
        }
Example #3
0
        public void SetupProjectsWithDbContextInDependency(TemporaryFileProvider fileProvider, ITestOutputHelper output)
        {
            fileProvider.Add("global.json", GlobalJsonText);
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "DAL"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "toolAssets", "netcoreapp2.0"));

            fileProvider.Add($"Root/TestCodeGeneration.targets", MsBuildProjectStrings.TestCodeGenerationTargetFileText);

            // Copy Msbuild task dlls.
            var msbuildTaskDllPath = Path.Combine(Path.GetDirectoryName(typeof(MsBuildProjectSetupHelper).Assembly.Location), "Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            fileProvider.Copy(msbuildTaskDllPath, "toolAssets/netcoreapp2.0/Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            var rootProjectTxt = MsBuildProjectStrings.WebProjectTxt;

            fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", rootProjectTxt);
            fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupWithDbContext);
            fileProvider.Add($"Root/{MsBuildProjectStrings.ProgramFileName}", MsBuildProjectStrings.ProgramFileText);
            fileProvider.Add($"Root/{MsBuildProjectStrings.AppSettingsFileName}", MsBuildProjectStrings.AppSettingsFileTxt);

            fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
            fileProvider.Add($"Library1/ModelWithMatchingShortName.cs", "namespace Library1.Models { public class ModelWithMatchingShortName { } }");
            fileProvider.Add($"Library1/Car.cs", MsBuildProjectStrings.CarTxt);
            fileProvider.Add($"Library1/Product.cs", MsBuildProjectStrings.ProductTxt);

            fileProvider.Add($"DAL/{MsBuildProjectStrings.DALProjectName}", MsBuildProjectStrings.DAL);
            fileProvider.Add($"DAL/{MsBuildProjectStrings.CarContextFileName}", MsBuildProjectStrings.CarContextTxt);


            RestoreAndBuild(Path.Combine(fileProvider.Root, "Root"), output);
        }
Example #4
0
        public void SetupProjectsWithDbContextInDependency(TemporaryFileProvider fileProvider, ITestOutputHelper output)
        {
            fileProvider.Add("global.json", GlobalJsonText);
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "DAL"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));

            var rootProjectTxt = MsBuildProjectStrings.WebProjectTxt;

            fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", rootProjectTxt);
            fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupWithDbContext);
            fileProvider.Add($"Root/{MsBuildProjectStrings.ProgramFileName}", MsBuildProjectStrings.ProgramFileText);
            fileProvider.Add($"Root/{MsBuildProjectStrings.AppSettingsFileName}", MsBuildProjectStrings.AppSettingsFileTxt);

            fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
            fileProvider.Add($"Library1/ModelWithMatchingShortName.cs", "namespace Library1.Models { public class ModelWithMatchingShortName { } }");
            fileProvider.Add($"Library1/Car.cs", MsBuildProjectStrings.CarTxt);
            fileProvider.Add($"Library1/Product.cs", MsBuildProjectStrings.ProductTxt);

            fileProvider.Add($"DAL/{MsBuildProjectStrings.DALProjectName}", MsBuildProjectStrings.DAL);
            fileProvider.Add($"DAL/{MsBuildProjectStrings.CarContextFileName}", MsBuildProjectStrings.CarContextTxt);


            RestoreAndBuild(Path.Combine(fileProvider.Root, "Root"), output);
        }
Example #5
0
        public void SetupProjects(TemporaryFileProvider fileProvider, ITestOutputHelper output, bool fullFramework = false)
        {
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));
            fileProvider.Add("NuGet.config", NuGetConfigText);

            var rootProjectTxt = fullFramework ? MsBuildProjectStrings.RootNet45ProjectTxt : MsBuildProjectStrings.RootProjectTxt;

            fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", string.Format(rootProjectTxt, AspNetCoreVersion, CodeGenerationVersion, RuntimeFrameworkVersion));
            fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupTxt);
            fileProvider.Add($"Root/{MsBuildProjectStrings.ProgramFileName}", MsBuildProjectStrings.ProgramFileText);

            fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
            fileProvider.Add($"Library1/ModelWithMatchingShortName.cs", "namespace Library1.Models { public class ModelWithMatchingShortName { } }");
            fileProvider.Add($"Library1/Car.cs", MsBuildProjectStrings.CarTxt);
            fileProvider.Add($"Library1/Product.cs", MsBuildProjectStrings.ProductTxt);
            RestoreAndBuild(Path.Combine(fileProvider.Root, "Root"), output);
        }
        public void SetupProjects(TemporaryFileProvider fileProvider, ITestOutputHelper output, bool fullFramework = false)
        {
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));
            fileProvider.Add("global.json", GlobalJsonText);

            var rootProjectTxt = fullFramework ? MsBuildProjectStrings.RootNet45ProjectTxt : MsBuildProjectStrings.RootProjectTxt;

            fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", rootProjectTxt);
            fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupTxt);
            fileProvider.Add($"Root/{MsBuildProjectStrings.ProgramFileName}", MsBuildProjectStrings.ProgramFileText);

            fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
            fileProvider.Add($"Library1/ModelWithMatchingShortName.cs", "namespace Library1.Models { public class ModelWithMatchingShortName { } }");
            fileProvider.Add($"Library1/Car.cs", MsBuildProjectStrings.CarTxt);
            fileProvider.Add($"Library1/Product.cs", MsBuildProjectStrings.ProductTxt);
            RestoreAndBuild(Path.Combine(fileProvider.Root, "Root"), output);
        }
Example #7
0
        public void SetupProjectsWithoutEF(TemporaryFileProvider fileProvider, ITestOutputHelper output)
        {
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));
            fileProvider.Add("global.json", GlobalJsonText);
            fileProvider.Add("NuGet.config", NuGetConfigText);

            var rootProjectTxt = MsBuildProjectStrings.RootProjectTxtWithoutEF;

            fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", rootProjectTxt);
            fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupTxtWithoutEf);
            fileProvider.Add($"Root/{MsBuildProjectStrings.ProgramFileName}", MsBuildProjectStrings.ProgramFileText);

            fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
            fileProvider.Add($"Library1/ModelWithMatchingShortName.cs", "namespace Library1.Models { public class ModelWithMatchingShortName { } }");
            fileProvider.Add($"Library1/Car.cs", MsBuildProjectStrings.CarTxt);
            fileProvider.Add($"Library1/Product.cs", MsBuildProjectStrings.ProductTxt);

            RestoreAndBuild(Path.Combine(fileProvider.Root, "Root"), output);
        }
        internal void SetupEmptyCodeGenerationProject(TemporaryFileProvider fileProvider, ITestOutputHelper outputHelper)
        {
            fileProvider.Add("global.json", GlobalJsonText);
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "toolAssets", "net5.0"));

            fileProvider.Add($"TestCodeGeneration.targets", MsBuildProjectStrings.ProjectContextWriterMsbuildHelperText);

            var msbuildTaskDllPath = Path.Combine(Path.GetDirectoryName(typeof(MsBuildProjectSetupHelper).Assembly.Location), "Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            fileProvider.Copy(msbuildTaskDllPath, "toolAssets/net5.0/Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            var rootProjectTxt = MsBuildProjectStrings.SimpleNet50ProjectText;

            fileProvider.Add(MsBuildProjectStrings.RootProjectName, rootProjectTxt);
            fileProvider.Add("Startup.cs", MsBuildProjectStrings.EmptyTestStartupText);
            fileProvider.Add(MsBuildProjectStrings.DbContextInheritanceProgramName, MsBuildProjectStrings.DbContextInheritanceProjectProgramText);
            fileProvider.Add(MsBuildProjectStrings.AppSettingsFileName, MsBuildProjectStrings.AppSettingsFileTxt);

            RestoreAndBuild(fileProvider.Root, outputHelper);
        }
Example #9
0
        internal void SetupProjectsForIdentityScaffolder(TemporaryFileProvider fileProvider, ITestOutputHelper output)
        {
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));
            Directory.CreateDirectory(Path.Combine(fileProvider.Root, "toolAssets", "netcoreapp2.0"));

            fileProvider.Add("global.json", GlobalJsonText);
            fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", MsBuildProjectStrings.RootProjectTxt);
            fileProvider.Add($"Root/TestCodeGeneration.targets", MsBuildProjectStrings.TestCodeGenerationTargetFileText);

            // Copy Msbuild task dlls.
            var msbuildTaskDllPath = Path.Combine(Path.GetDirectoryName(typeof(MsBuildProjectSetupHelper).Assembly.Location), "Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");

            fileProvider.Copy(msbuildTaskDllPath, "toolAssets/netcoreapp2.0/Microsoft.VisualStudio.Web.CodeGeneration.Msbuild.dll");
            fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupForIdentityTxt);
            fileProvider.Add($"Root/{MsBuildProjectStrings.ProgramFileName}", MsBuildProjectStrings.ProgramFileText);
            fileProvider.Add($"Root/{MsBuildProjectStrings.IdentityContextName}", MsBuildProjectStrings.IdentityContextText);
            fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
            RestoreAndBuild(Path.Combine(fileProvider.Root, "Root"), output);
        }
        public void CommonUtilities_TestGetAssemblyFromCompilation_MsBuild()
        {
            using (var fileProvider = new TemporaryFileProvider())
            {
                new MsBuildProjectSetupHelper().SetupProjects(fileProvider, _outputHelper);
                var path = Path.Combine(fileProvider.Root, "Root", MsBuildProjectStrings.RootProjectName);

                var projectContext = GetProjectContext(path, true);

                var references = projectContext.CompilationAssemblies.SelectMany(c => c.GetMetadataReference());
                var code       = @"using System;
                            namespace Sample { 
                                public class SampleClass 
                                {
                                } 
                            }";

                var compilation = GetCompilation(code, Path.GetRandomFileName(), references);
                var result      = CommonUtilities.GetAssemblyFromCompilation(loadContext, compilation);

                Assert.True(result.Success);
                Assert.True(result.Assembly.DefinedTypes.Where(_ => _.Name == "SampleClass").Any());
            }
        }