예제 #1
0
        public bool Execute()
        {
            var paths   = new Paths();
            var success = true;

            try
            {
                var currentCode = string.Empty;
                if (File.Exists(paths.SnippetsFilePath))
                {
                    currentCode = File.ReadAllText(paths.SnippetsFilePath);
                }

                var cb = new CodeBuilder();
                cb.AddHeader();
                cb.AddLine("namespace MudBlazor.Docs.Models");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("public static partial class Snippets");
                cb.AddLine("{");
                cb.IndentLevel++;

                foreach (var entry in Directory.EnumerateFiles(paths.DocsDirPath, "*.razor", SearchOption.AllDirectories)
                         .OrderBy(e => e.Replace("\\", "/"), StringComparer.Ordinal))
                {
                    var filename      = Path.GetFileName(entry);
                    var componentName = Path.GetFileNameWithoutExtension(filename);
                    if (!componentName.EndsWith(Paths.ExampleDiscriminator))
                    {
                        continue;
                    }
                    cb.AddLine($"public const string {componentName} = @\"{EscapeComponentSource(entry)}\";\n");
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.SnippetsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.SnippetsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }
예제 #2
0
        public bool Execute()
        {
            var  paths   = new Paths();
            bool success = true;

            try
            {
                string currentCode = string.Empty;
                if (File.Exists(paths.DocStringsFilePath))
                {
                    currentCode = File.ReadAllText(paths.DocStringsFilePath);
                }

                var cb = new CodeBuilder();
                cb.AddHeader();
                cb.AddLine("namespace MudBlazor.Docs.Models");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("public static partial class DocStrings");
                cb.AddLine("{");
                cb.IndentLevel++;

                var assembly = typeof(MudText).Assembly;
                foreach (var type in assembly.GetTypes().OrderBy(t => GetSaveTypename(t)))
                {
                    foreach (var info in type.GetPropertyInfosWithAttribute <ParameterAttribute>())
                    {
                        var doc = info.GetDocumentation();
                        doc = Regex.Replace(doc ?? "", @"</?.+?>", "");
                        cb.AddLine($"public const string {GetSaveTypename(type).TrimEnd('_')}_{info.Name} = @\"{EscapeDescription(doc)}\";\n");
                    }
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.DocStringsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.DocStringsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }
예제 #3
0
        public bool Execute()
        {
            var  paths   = new Paths();
            bool success = true;

            try
            {
                Directory.CreateDirectory(paths.TestDirPath);

                string currentCode = string.Empty;
                if (File.Exists(paths.ComponentTestsFilePath))
                {
                    currentCode = File.ReadAllText(paths.ComponentTestsFilePath);
                }

                var cb = new CodeBuilder();

                cb.AddHeader();

                cb.AddLine("using Bunit;");
                cb.AddLine("using Bunit.TestDoubles;");
                cb.AddLine("using Microsoft.AspNetCore.Components;");
                cb.AddLine("using Microsoft.Extensions.DependencyInjection;");
                cb.AddLine("using NUnit.Framework;");
                cb.AddLine("using MudBlazor.UnitTests.Mocks;");
                cb.AddLine("using MudBlazor.Docs.Examples;");
                cb.AddLine("using MudBlazor.Docs.Wireframes;");
                cb.AddLine("using MudBlazor.Services;");
                cb.AddLine("using System.Net.Http;");
                cb.AddLine();
                cb.AddLine("namespace MudBlazor.UnitTests.Components");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("// These tests just check if all the examples from the doc page render without errors");
                cb.AddLine("[TestFixture]");
                cb.AddLine("public class _AllComponents");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("private Bunit.TestContext ctx;");
                cb.AddLine();
                cb.AddLine("[SetUp]");
                cb.AddLine("public void Setup()");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("ctx = new Bunit.TestContext();");
                cb.AddLine("ctx.JSInterop.Mode = JSRuntimeMode.Loose;");
                cb.AddLine("ctx.Services.AddSingleton<NavigationManager>(new MockNavigationManager());");
                cb.AddLine("ctx.Services.AddSingleton<IDialogService>(new DialogService());");
                cb.AddLine("ctx.Services.AddSingleton<ISnackbar>(new MockSnackbar());");
                cb.AddLine("ctx.Services.AddSingleton<IResizeListenerService>(new MockResizeListenerService());");
                cb.AddLine("ctx.Services.AddScoped(sp => new HttpClient());");
                cb.IndentLevel--;
                cb.AddLine("}");
                cb.AddLine();
                cb.AddLine("[TearDown]");
                cb.AddLine("public void TearDown() => ctx.Dispose();");
                cb.AddLine();

                foreach (var entry in Directory.EnumerateFiles(paths.DocsDirPath, "*.razor", SearchOption.AllDirectories)
                         .OrderBy(e => e.Replace("\\", "/"), StringComparer.Ordinal))
                {
                    if (entry.EndsWith("Code.razor"))
                    {
                        continue;
                    }
                    var filename      = Path.GetFileName(entry);
                    var componentName = Path.GetFileNameWithoutExtension(filename);
                    if (!filename.Contains(Paths.ExampleDiscriminator))
                    {
                        continue;
                    }
                    cb.AddLine("[Test]");
                    cb.AddLine($"public void {componentName}_Test()");
                    cb.AddLine("{");
                    cb.IndentLevel++;
                    cb.AddLine($"ctx.RenderComponent<{componentName}>();");
                    cb.IndentLevel--;
                    cb.AddLine("}");
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.ComponentTestsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.ComponentTestsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }
예제 #4
0
        public bool Execute()
        {
            var paths   = new Paths();
            var success = true;

            try
            {
                var currentCode = string.Empty;
                if (File.Exists(paths.DocStringsFilePath))
                {
                    currentCode = File.ReadAllText(paths.DocStringsFilePath);
                }

                var cb = new CodeBuilder();
                cb.AddHeader();
                cb.AddLine("namespace MudBlazor.Docs.Models");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("public static partial class DocStrings");
                cb.AddLine("{");
                cb.IndentLevel++;

                var assembly = typeof(MudText).Assembly;
                foreach (var type in assembly.GetTypes().OrderBy(t => GetSaveTypename(t)))
                {
                    foreach (var property in type.GetPropertyInfosWithAttribute <ParameterAttribute>())
                    {
                        var doc = property.GetDocumentation() ?? "";
                        doc = Regex.Replace(doc, @"</?.+?>", "");
                        cb.AddLine($"public const string {GetSaveTypename(type)}_{property.Name} = @\"{EscapeDescription(doc).Trim()}\";\n");
                    }

                    // TableContext was causing conflicts due to the imperfect mapping from the name of class to the name of field in DocStrings
                    if (type.IsSubclassOf(typeof(Attribute)) || GetSaveTypename(type) == "TypeInference" || type == typeof(Utilities.CssBuilder) || type == typeof(TableContext))
                    {
                        continue;
                    }

                    foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy))
                    {
                        if (!hiddenMethods.Any(x => x.Contains(method.Name)) && !method.Name.StartsWith("get_") && !method.Name.StartsWith("set_"))
                        {
                            // omit methods defined in System.Enum
                            if (GetBaseDefinitionClass(method) == typeof(Enum))
                            {
                                continue;
                            }

                            var doc = method.GetDocumentation() ?? "";
                            cb.AddLine($"public const string {GetSaveTypename(type)}_method_{GetSaveMethodIdentifier(method)} = @\"{EscapeDescription(doc)}\";\n");
                        }
                    }
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.DocStringsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.DocStringsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }
예제 #5
0
        public bool Execute()
        {
            var paths   = new Paths();
            var success = true;

            try
            {
                Directory.CreateDirectory(paths.TestDirPath);

                var currentCode = string.Empty;
                if (File.Exists(paths.ComponentTestsFilePath))
                {
                    currentCode = File.ReadAllText(paths.ComponentTestsFilePath);
                }

                var cb = new CodeBuilder();

                cb.AddHeader();
                cb.AddLine("using MudBlazor.Docs.Examples;");
                cb.AddLine("using MudBlazor.Docs.Wireframes;");
                cb.AddLine("using NUnit.Framework;");
                cb.AddLine();

                cb.AddLine("namespace MudBlazor.UnitTests.Components");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("// These tests just check if all the examples from the doc page render without errors");
                cb.AddLine("public partial class ExampleDocsTests");
                cb.AddLine("{");
                cb.IndentLevel++;

                foreach (var entry in Directory.EnumerateFiles(paths.DocsDirPath, "*.razor", SearchOption.AllDirectories)
                         .OrderBy(e => e.Replace("\\", "/"), StringComparer.Ordinal))
                {
                    if (entry.EndsWith("Code.razor"))
                    {
                        continue;
                    }
                    var filename      = Path.GetFileName(entry);
                    var componentName = Path.GetFileNameWithoutExtension(filename);
                    if (!filename.Contains(Paths.ExampleDiscriminator))
                    {
                        continue;
                    }
                    // skip over table/data grid virutalization since it takes too long.
                    if (filename == "TableVirtualizationExample.razor" || filename == "DataGridVirtualizationExample.razor")
                    {
                        continue;
                    }
                    cb.AddLine("[Test]");
                    cb.AddLine($"public void {componentName}_Test()");
                    cb.AddLine("{");
                    cb.IndentLevel++;
                    cb.AddLine($"ctx.RenderComponent<{componentName}>();");
                    cb.IndentLevel--;
                    cb.AddLine("}");
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.ComponentTestsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.ComponentTestsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }
예제 #6
0
        public bool Execute()
        {
            var paths   = new Paths();
            var success = true;

            try
            {
                Directory.CreateDirectory(paths.TestDirPath);

                var currentCode = string.Empty;
                if (File.Exists(paths.ApiPageTestsFilePath))
                {
                    currentCode = File.ReadAllText(paths.ApiPageTestsFilePath);
                }

                var cb = new CodeBuilder();

                cb.AddHeader();
                cb.AddLine("using MudBlazor.Charts;");
                cb.AddLine("using MudBlazor.Docs.Components;");
                cb.AddLine("using MudBlazor.Internal;");
                cb.AddLine("using NUnit.Framework;");
                cb.AddLine("using ComponentParameter = Bunit.ComponentParameter;");
                cb.AddLine();

                cb.AddLine("namespace MudBlazor.UnitTests.Components");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("// These tests just check all the API pages to see if they throw any exceptions");
                cb.AddLine("public partial class ApiDocsTests");
                cb.AddLine("{");
                cb.IndentLevel++;
                var mudBlazorComponents = typeof(MudAlert).Assembly.GetTypes().OrderBy(t => t.FullName).Where(t => t.IsSubclassOf(typeof(ComponentBase)));
                foreach (var type in mudBlazorComponents)
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }
                    if (type.Name.Contains("Base"))
                    {
                        continue;
                    }
                    if (type.Namespace.Contains("InternalComponents"))
                    {
                        continue;
                    }
                    cb.AddLine("[Test]");
                    cb.AddLine($"public void {SafeTypeName(type, removeT: true)}_API_Test()");
                    cb.AddLine("{");
                    cb.IndentLevel++;
                    cb.AddLine(@$ "ctx.RenderComponent<DocsApi>(ComponentParameter.CreateParameter(" "Type" ", typeof({SafeTypeName(type)})));");
                    cb.IndentLevel--;
                    cb.AddLine("}");
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.ApiPageTestsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.ApiPageTestsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }
예제 #7
0
        public bool Execute()
        {
            var paths   = new Paths();
            var success = true;

            try
            {
                Directory.CreateDirectory(paths.TestDirPath);

                var currentCode = string.Empty;
                if (File.Exists(paths.ApiPageTestsFilePath))
                {
                    currentCode = File.ReadAllText(paths.ApiPageTestsFilePath);
                }

                var cb = new CodeBuilder();

                cb.AddHeader();
                cb.AddUsings();

                cb.AddLine("namespace MudBlazor.UnitTests.Components");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("// These tests just check all the API pages to see if they throw any exceptions");
                cb.AddLine("[TestFixture]");
                cb.AddLine("public class _AllApiPages");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("private Bunit.TestContext ctx;");
                cb.AddLine();
                cb.AddLine("[SetUp]");
                cb.AddLine("public void Setup()");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("ctx = new Bunit.TestContext();");
                cb.AddLine("ctx.JSInterop.Mode = JSRuntimeMode.Loose;");
                cb.AddLine("ctx.Services.AddSingleton<NavigationManager>(new MockNavigationManager());");
                cb.AddLine("ctx.Services.AddSingleton<IDialogService>(new DialogService());");
                cb.AddLine("ctx.Services.AddSingleton<ISnackbar>(new SnackbarService());");
                cb.AddLine("ctx.Services.AddSingleton<IResizeListenerService>(new MockResizeListenerService());");
                cb.AddLine("ctx.Services.AddTransient<IScrollManager, MockScrollManager>();");
                cb.AddLine("ctx.Services.AddTransient<IScrollListener, MockScrollListener>();");
                cb.AddLine("ctx.Services.AddSingleton<IHeadElementHelper>(new MockHeadElementHelper());");
                cb.AddLine("ctx.Services.AddSingleton<IBrowserWindowSizeProvider>(new MockBrowserWindowSizeProvider());");
                cb.AddLine("ctx.Services.AddSingleton<IDomService>(new MockDomService());");
                cb.AddLine("ctx.Services.AddScoped(sp => new HttpClient());");
                cb.IndentLevel--;
                cb.AddLine("}");
                cb.AddLine();
                cb.AddLine("[TearDown]");
                cb.AddLine("public void TearDown() => ctx.Dispose();");
                cb.AddLine();
                var mudBlazorComponents = typeof(MudAlert).Assembly.GetTypes().OrderBy(t => t.FullName).Where(t => t.IsSubclassOf(typeof(ComponentBase)));
                foreach (var type in mudBlazorComponents)
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }
                    if (type.Name.Contains("Base"))
                    {
                        continue;
                    }
                    if (type.Namespace.Contains("InternalComponents"))
                    {
                        continue;
                    }
                    cb.AddLine("[Test]");
                    cb.AddLine($"public void {SafeTypeName(type, removeT: true)}_API_Test()");
                    cb.AddLine("{");
                    cb.IndentLevel++;
                    cb.AddLine(@$ "ctx.RenderComponent<DocsApi>(ComponentParameter.CreateParameter(" "Type" ", typeof({SafeTypeName(type)})));");
                    cb.IndentLevel--;
                    cb.AddLine("}");
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.ApiPageTestsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.ApiPageTestsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }
예제 #8
0
        public bool Execute()
        {
            var  paths   = new Paths();
            bool success = true;

            try
            {
                Directory.CreateDirectory(paths.TestDirPath);

                string currentCode = string.Empty;
                if (File.Exists(paths.ApiPageTestsFilePath))
                {
                    currentCode = File.ReadAllText(paths.ApiPageTestsFilePath);
                }

                var cb = new CodeBuilder();

                cb.AddHeader();
                cb.AddLine("using Bunit.TestDoubles.JSInterop;");
                cb.AddLine("using Microsoft.AspNetCore.Components;");
                cb.AddLine("using Microsoft.Extensions.DependencyInjection;");
                cb.AddLine("using NUnit.Framework;");
                cb.AddLine("using MudBlazor.UnitTests.Mocks;");
                cb.AddLine("using MudBlazor.Docs.Examples;");
                cb.AddLine("using MudBlazor.Services;");
                cb.AddLine("using MudBlazor.Docs.Components;");
                cb.AddLine("using Bunit.Rendering;");
                cb.AddLine("using System;");
                cb.AddLine("using Toolbelt.Blazor.HeadElement;");
                cb.AddLine("using MudBlazor.UnitTests;");
                cb.AddLine("using MudBlazor.Charts;");
                cb.AddLine("using Bunit;");
                cb.AddLine();
                cb.AddLine("#if NET5_0");
                cb.AddLine("using ComponentParameter = Bunit.ComponentParameter;");
                cb.AddLine("#endif");
                cb.AddLine();
                cb.AddLine("namespace MudBlazor.UnitTests.Components");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("// These tests just check all the API pages to see if they throw any exceptions");
                cb.AddLine("[TestFixture]");
                cb.AddLine("public class _AllApiPages");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("private Bunit.TestContext ctx;");
                cb.AddLine();
                cb.AddLine("[SetUp]");
                cb.AddLine("public void Setup()");
                cb.AddLine("{");
                cb.IndentLevel++;
                cb.AddLine("ctx = new Bunit.TestContext();");
                cb.AddLine("ctx.Services.AddMockJSRuntime();");
                cb.AddLine("ctx.Services.AddSingleton<NavigationManager>(new MockNavigationManager());");
                cb.AddLine("ctx.Services.AddSingleton<IDialogService>(new DialogService());");
                cb.AddLine("ctx.Services.AddSingleton<ISnackbar>(new MockSnackbar());");
                cb.AddLine("ctx.Services.AddSingleton<IResizeListenerService>(new MockResizeListenerService());");
                cb.AddLine("ctx.Services.AddSingleton<IHeadElementHelper>(new MockHeadElementHelper());");
                cb.IndentLevel--;
                cb.AddLine("}");
                cb.AddLine();
                cb.AddLine("[TearDown]");
                cb.AddLine("public void TearDown() => ctx.Dispose();");
                cb.AddLine();
                var mudBlazorComponents = typeof(MudAlert).Assembly.GetTypes().OrderBy(t => t.FullName).Where(t => t.IsSubclassOf(typeof(ComponentBase)));
                foreach (var type in mudBlazorComponents)
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }
                    if (type.Name.Contains("Base"))
                    {
                        continue;
                    }
                    if (type.Namespace.Contains("InternalComponents"))
                    {
                        continue;
                    }
                    cb.AddLine("[Test]");
                    cb.AddLine($"public void {SafeTypeName(type, removeT: true)}_API_Test()");
                    cb.AddLine("{");
                    cb.IndentLevel++;
                    cb.AddLine(@$ "ctx.RenderComponent<DocsApi>(ComponentParameter.CreateParameter(" "Type" ", typeof({SafeTypeName(type)})));");
                    cb.IndentLevel--;
                    cb.AddLine("}");
                }

                cb.IndentLevel--;
                cb.AddLine("}");
                cb.IndentLevel--;
                cb.AddLine("}");

                if (currentCode != cb.ToString())
                {
                    File.WriteAllText(paths.ApiPageTestsFilePath, cb.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error generating {paths.ApiPageTestsFilePath} : {e.Message}");
                success = false;
            }

            return(success);
        }