Esempio n. 1
0
        public void AddViewImport_Ignores_Duplicate_Using_Directives()
        {
            _viewImportService.AddViewImport("@using Microsoft.AspNetCore.Authorization");
            _viewImportService.AddViewImport("@using System.Net.Http");
            var fileInfo = _viewImportService.ConstructImportsFile();

            Assert.AreEqual(ExpectedBasicImportsContent, Encoding.UTF8.GetString(fileInfo.FileBytes));
        }
Esempio n. 2
0
        public string ConvertDirective(string directiveName, string directiveString, string originalFilePath, string projectName, ViewImportService viewImportService)
        {
            // TODO: We want to make sure that certain directives only occur once (i.e. layout,
            // inherits, etc.) Need to find a better way to detect and deal with those or perhaps
            // just leave it up the the developer given that detecting which layout or base class
            // to choose is difficult
            var migrationResults = GetMigratedAttributes(directiveString, directiveName, projectName);

            // Want to ensure that the general directive conversion stays at the front if it exists
            migrationResults = GetMigratedDirectives(directiveName, originalFilePath).Concat(migrationResults);

            // Remove any using directive results and send them to the viewImports service
            migrationResults = migrationResults.Where(migrationResult => {
                if (migrationResult.MigrationResultType == DirectiveMigrationResultType.UsingDirective)
                {
                    viewImportService.AddViewImport(migrationResult.Content);
                    return(false);
                }

                return(true);
            });

            return(string.Join(Environment.NewLine, migrationResults.Select(migrationResult => migrationResult.Content)));
        }