public async Task TestValidateAndBuild() { using (var fileProvider = new TemporaryFileProvider()) { SetupProjects(fileProvider); var workspace = GetWorkspace(Path.Combine(fileProvider.Root, "Root")); var commandLineModel = new IdentityGeneratorCommandLineModel() { RootNamespace = "Test.Namespace", UseSQLite = false }; var applicationInfo = new ApplicationInfo("TestApp", "Sample"); var builder = new IdentityGeneratorTemplateModelBuilder( commandLineModel, applicationInfo, _projectContext, workspace, _loader, new DefaultFileSystem(), _logger.Object); var templateModel = await builder.ValidateAndBuild(); Assert.Equal(commandLineModel.RootNamespace, templateModel.Namespace); Assert.Equal("TestAppIdentityDbContext", templateModel.DbContextClass); Assert.Equal("Test.Namespace.Areas.Identity.Data", templateModel.DbContextNamespace); Assert.False(templateModel.IsUsingExistingDbContext); Assert.Equal("IdentityUser", templateModel.UserClass); Assert.False(templateModel.IsGenerateCustomUser); commandLineModel.UserClass = "MyIdentityUser"; templateModel = await builder.ValidateAndBuild(); Assert.Equal("Test.Namespace.Areas.Identity.Data", templateModel.DbContextNamespace); Assert.False(templateModel.IsUsingExistingDbContext); Assert.Equal("MyIdentityUser", templateModel.UserClass); Assert.True(templateModel.IsGenerateCustomUser); Assert.False(templateModel.IsGeneratingIndividualFiles); } }
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); }