Пример #1
0
        public void TryEditStartupForNewContext_Adds_Context_Registration_To_ConfigureServices(string beforeStartupResource, string afterStartupResource, string dbContextResource)
        {
            string resourcePrefix = "compiler/resources/";

            var beforeStartupText = ResourceUtilities.GetEmbeddedResourceFileContent(resourcePrefix + beforeStartupResource);
            var afterStartupText  = ResourceUtilities.GetEmbeddedResourceFileContent(resourcePrefix + afterStartupResource);
            var dbContextText     = ResourceUtilities.GetEmbeddedResourceFileContent(resourcePrefix + dbContextResource);

            var startupTree = CSharpSyntaxTree.ParseText(beforeStartupText);
            var contextTree = CSharpSyntaxTree.ParseText(dbContextText);
            var efReference = MetadataReference.CreateFromFile(Assembly.GetEntryAssembly().Location);

            var compilation = CSharpCompilation.Create("DoesNotMatter", new[] { startupTree, contextTree }, new[] { efReference });

            DbContextEditorServices testObj = new DbContextEditorServices(
                new Mock <ILibraryManager>().Object,
                new Mock <IApplicationInfo>().Object,
                new Mock <IFilesLocator>().Object,
                new Mock <ITemplating>().Object);

            var types       = RoslynUtilities.GetDirectTypesInCompilation(compilation);
            var startupType = ModelType.FromITypeSymbol(types.Where(ts => ts.Name == "Startup").First());
            var contextType = ModelType.FromITypeSymbol(types.Where(ts => ts.Name == "MyContext").First());

            var result = testObj.EditStartupForNewContext(startupType, "MyContext", "ContextNamespace", "MyContext-NewGuid");

            Assert.True(result.Edited);
            Assert.Equal(afterStartupText, result.NewTree.GetText().ToString());
        }
Пример #2
0
        public void AddModelToContext_Adds_Model_From_Same_Project_To_Context(string beforeContextResource, string modelResource, string afterContextResource)
        {
            string resourcePrefix = "compiler/resources/";

            var beforeDbContextText = ResourceUtilities.GetEmbeddedResourceFileContent(resourcePrefix + beforeContextResource);
            var modelText           = ResourceUtilities.GetEmbeddedResourceFileContent(resourcePrefix + modelResource);
            var afterDbContextText  = ResourceUtilities.GetEmbeddedResourceFileContent(resourcePrefix + afterContextResource);

            var contextTree = CSharpSyntaxTree.ParseText(beforeDbContextText);
            var modelTree   = CSharpSyntaxTree.ParseText(modelText);
            var efReference = MetadataReference.CreateFromFile(Assembly.GetEntryAssembly().Location);

            var compilation = CSharpCompilation.Create("DoesNotMatter", new[] { contextTree, modelTree }, new[] { efReference });

            DbContextEditorServices testObj = new DbContextEditorServices(
                new Mock <ILibraryManager>().Object,
                new Mock <IApplicationInfo>().Object,
                new Mock <IFilesLocator>().Object,
                new Mock <ITemplating>().Object);

            var types       = RoslynUtilities.GetDirectTypesInCompilation(compilation);
            var modelType   = ModelType.FromITypeSymbol(types.Where(ts => ts.Name == "MyModel").First());
            var contextType = ModelType.FromITypeSymbol(types.Where(ts => ts.Name == "MyContext").First());

            var result = testObj.AddModelToContext(contextType, modelType);

            Assert.True(result.Edited);
            Assert.Equal(afterDbContextText, result.NewTree.GetText().ToString());
        }
Пример #3
0
 public IEnumerable <ModelType> GetAllTypes()
 {
     return(_projectWorkspace.CurrentSolution.Projects
            .Select(project => project.GetCompilationAsync().Result)
            .Select(comp => RoslynUtilities.GetDirectTypesInCompilation(comp))
            .Aggregate((col1, col2) => col1.Concat(col2).ToList())
            .Select(ts => ModelType.FromITypeSymbol(ts)));
 }
Пример #4
0
 public IEnumerable <ModelType> GetAllTypes()
 {
     return(_libraryExporter
            .GetProjectsInApp(_application)
            .Select(compilation => RoslynUtilities.GetDirectTypesInCompilation(compilation.Compilation))
            .Aggregate((coll1, coll2) => coll1.Concat(coll2).ToList())
            .Select(ts => ModelType.FromITypeSymbol(ts)));
 }