public void Convert2Blazor_Comments_Out_Control_Tags() { var testInput = $@"{TestInputNodeStartTag} {TestInputNodeEndTag}"; var expectedOutput = $@"{ExpectedNodeStartTag} {ExpectedNodeEndTag}"; var actualOutput = UnknownControlRemover.RemoveUnknownTags(testInput); Assert.AreEqual(expectedOutput, actualOutput); }
public void Convert2Blazor_Preserves_Content() { var testInput = $@"{TestInputNodeStartTag} {TestInputNodeInnerHtml} {TestInputNodeEndTag}"; var expectedOutput = $@"{ExpectedNodeStartTag} {TestInputNodeInnerHtml} {ExpectedNodeEndTag}"; var actualOutput = UnknownControlRemover.RemoveUnknownTags(testInput); Assert.AreEqual(expectedOutput, actualOutput); }
// View file converters will return razor file contents with // only view layer, code behind will be created in another file public override Task <IEnumerable <FileInformation> > MigrateFileAsync() { LogStart(); _metricsContext.CollectActionMetrics(WebFormsActionType.FileConversion, ChildActionType); var result = new List <FileInformation>(); try { var htmlString = File.ReadAllText(FullPath); // Replace directives first to build up list of user controls to be converted later by the ControlConverters var projectName = Path.GetFileName(ProjectPath); htmlString = EmbeddedCodeReplacers.ReplaceDirectives(htmlString, RelativePath, projectName, _viewImportService, _metricsContext); // Convert the Web Forms controls to Blazor equivalent var migratedDocument = GetRazorContents(htmlString); var contents = migratedDocument.DocumentNode.WriteTo(); // We comment out the unknown user controls here instead of during // traversal because the post-order nature may comment out controls // that are migrated as part of an ancestor control before that ancestor // can be processed contents = ControlConverter.ConvertEmbeddedCode(contents, RelativePath, _viewImportService); contents = UnknownControlRemover.RemoveUnknownTags(contents); // Currently just changing extension to .razor, keeping filename and directory the same // but Razor files are renamed and moved around, can't always use same filename/directory in the future var newRelativePath = FilePathHelper.AlterFileName(RelativePath, newExtension: ".razor"); if (RelativePath.EndsWith(Constants.WebFormsPageMarkupFileExtension, StringComparison.InvariantCultureIgnoreCase)) { newRelativePath = Path.Combine(Constants.RazorPageDirectoryName, newRelativePath); } else if (RelativePath.EndsWith(Constants.WebFormsMasterPageMarkupFileExtension, StringComparison.InvariantCultureIgnoreCase)) { newRelativePath = Path.Combine(Constants.RazorLayoutDirectoryName, newRelativePath); } else if (RelativePath.EndsWith(Constants.WebFormsControlMarkupFileExtenion, StringComparison.InvariantCultureIgnoreCase)) { newRelativePath = Path.Combine(Constants.RazorComponentDirectoryName, newRelativePath); } else { // Default action: file type is not supported. Set newRelativePath to null to // prevent file creation. newRelativePath = null; } DoCleanUp(); LogEnd(); if (newRelativePath != null) { var fileInformation = new FileInformation(FilePathHelper.RemoveDuplicateDirectories(newRelativePath), Encoding.UTF8.GetBytes(contents)); result.Add(fileInformation); } } catch (Exception e) { LogHelper.LogError(e, $"{Rules.Config.Constants.WebFormsErrorTag}Error migrating view file {FullPath}. A new file could not be generated."); } return(Task.FromResult((IEnumerable <FileInformation>)result)); }