Ejemplo n.º 1
0
 public void IconsFontMaterialIconsExample_Test()
 {
     using var ctx = new Bunit.TestContext();
     ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager());
     ctx.Services.AddSingleton <IDialogService>(new DialogService());
     var comp = ctx.RenderComponent <IconsFontMaterialIconsExample>();
 }
Ejemplo n.º 2
0
 public void DrawerPersistentExample_Test()
 {
     using var ctx = new Bunit.TestContext();
     ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager());
     ctx.Services.AddSingleton <IDialogService>(new DialogService());
     var comp = ctx.RenderComponent <DrawerPersistentExample>();
 }
Ejemplo n.º 3
0
 public void TextFieldFormPropsExample_Test()
 {
     using var ctx = new Bunit.TestContext();
     ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager());
     ctx.Services.AddSingleton <IDialogService>(new DialogService());
     var comp = ctx.RenderComponent <TextFieldFormPropsExample>();
 }
Ejemplo n.º 4
0
        public void MudIconButtonShouldRenderAnAnchorIfLinkIsSet()
        {
            using var ctx = new Bunit.TestContext();
            var link   = Parameter(nameof(MudIconButton.Link), "https://www.google.com");
            var target = Parameter(nameof(MudIconButton.Target), "_blank");

            var comp = ctx.RenderComponent <MudIconButton>(link, target);

            //Link property is set, so it has to render an anchor element
            comp.Instance
            .HtmlTag
            .Should()
            .Be("a");

            //Target property is set, so it must have the rel attribute set to noopener
            comp.Markup
            .Should()
            .Contain("rel=\"noopener\"");

            //it is an anchor
            comp.Markup
            .Replace(" ", string.Empty)
            .Should()
            .StartWith("<a");
        }
Ejemplo n.º 5
0
 public void SwitchWithLabelExample_Test()
 {
     using var ctx = new Bunit.TestContext();
     ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager());
     ctx.Services.AddSingleton <IDialogService>(new DialogService());
     var comp = ctx.RenderComponent <SwitchWithLabelExample>();
 }
Ejemplo n.º 6
0
 public void ButtonCustomizedExample_Test()
 {
     using var ctx = new Bunit.TestContext();
     ctx.Services.AddSingleton <NavigationManager>(new MockNavigationManager());
     ctx.Services.AddSingleton <IDialogService>(new DialogService());
     var comp = ctx.RenderComponent <ButtonCustomizedExample>();
 }
        public void Test_CascadingValues()
        {
            using var ctx = new Bunit.TestContext();

            var cut = ctx.RenderComponent <CascadingValuesExample>();

            Assert.IsTrue(
                cut.Markup.Contains("<label>context-value-one</label>") &&
                cut.Markup.Contains("<label>context-value-two</label>"));
        }
Ejemplo n.º 8
0
        public void Test_LowkoderFirstExample()
        {
            using var ctx = new Bunit.TestContext();
            ctx.Services.AddLowKode(config =>
            {
                config.ContributeMetadataForType <WeatherForecast>();
                config.ContributeMetadataForType <Starship>();
            });
            var cut = ctx.RenderComponent <BasicInputSiteExample>();

            cut.Markup.Contains("<h1>Hello world from Blazor</h1>");
        }
Ejemplo n.º 9
0
        public void ResetState()
        {
            this.BunitTc = new Bunit.TestContext();

            BunitTc.Services.AddBlazoredLocalStorage();
            BunitTc.Services.AddFluxor(config => config.ScanAssemblies(typeof(RootState).Assembly));
            BunitTc.Services.AddScoped <IBookmarksApi>(sp => new MockBookmarksApi());
            BunitTc.Services.AddScoped <IBookmarkGroupsApi>(sp => new MockBookmarkGroupsApi());
            BunitTc.Services
            .AddScoped <IBookmarkContainersApi>(sp => new MockBookmarkContainersApi());

            this.Store      = this.BunitTc.Services.GetRequiredService <IStore>();
            this.Dispatcher = this.BunitTc.Services.GetRequiredService <IDispatcher>();
            this.State      = this.BunitTc.Services.GetRequiredService <IState <RootState> >();
            this.Store.InitializeAsync().Wait();
        }
Ejemplo n.º 10
0
        public void Test_LowkoderFirstExample()
        {
            // Arrange
            using var ctx = new Bunit.TestContext();

            // Register services
            ctx.Services.AddLowKode(config =>
            {
                config.ContributeMetadataForType <WeatherForecast>();
                config.ContributeMetadataForType <Starship>();
            });

            // Act
            var cut = ctx.RenderComponent <LowkoderFirstExample>();

            // Assert
            cut.Markup.Contains("<h1>Hello world from Blazor</h1>");
        }
Ejemplo n.º 11
0
        public void MudIconButtonShouldRenderAButtonByDefault()
        {
            using var ctx = new Bunit.TestContext();


            var comp = ctx.RenderComponent <MudIconButton>();

            //no HtmlTag nor Link properties are set, so HtmlTag is button by default
            comp.Instance
            .HtmlTag
            .Should()
            .Be("button");


            //it is a button
            comp.Markup
            .Replace(" ", string.Empty)
            .Should()
            .StartWith("<button");
        }
Ejemplo n.º 12
0
            public void HxInputBase_Renders_WithoutEditContext()
            {
                // Arrange
                var ctx      = new Bunit.TestContext();
                var formData = new FormData();

                RenderFragment componentRenderer = (RenderTreeBuilder builder) =>
                {
                    builder.OpenComponent <HxComponent>(0);
                    builder.AddAttribute(1, "Value", formData.StringValue);
                    builder.AddAttribute(2, "ValueChanged", EventCallback.Factory.Create <string>(this, (value) => { formData.StringValue = value; }));
                    builder.AddAttribute(3, "ValueExpression", (Expression <Func <string> >)(() => formData.StringValue));
                    builder.CloseComponent();
                };

                // Act
                ctx.Render(componentRenderer);

                // Assert
                // No exception thrown
            }
Ejemplo n.º 13
0
        public void MudButtonShouldRenderAButtonByDefault()
        {
            using var ctx = new Bunit.TestContext();


            var comp = ctx.RenderComponent <MudButton>();

            //no HtmlTag nor Link properties are set, so HtmlTag is button by default
            comp.Instance
            .HtmlTag
            .Should()
            .Be("button");


            //it is a button, and has by default stopPropagation on onclick
            comp.Markup
            .Replace(" ", string.Empty)
            .Should()
            .StartWith("<button")
            .And
            .Contain("__internal_stopPropagation_onclick");
        }
Ejemplo n.º 14
0
        public void Test_Starship()
        {
            // Arrange
            using var ctx = new Bunit.TestContext();

            // Register services
            ctx.Services.AddLowKode(config =>
            {
                config.ContributeMetadataForType <WeatherForecast>();
                config.ContributeMetadataForType <Starship>();
            });

            // Act
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var cut = ctx.RenderComponent <StarshipForm>();

            stopwatch.Stop();

            // Assert
            Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500);
            //cut.MarkupMatches("<h1>Hello world from Blazor</h1>");
        }
Ejemplo n.º 15
0
 public virtual void Setup()
 {
     Context = new();
     Context.AddTestServices();
 }
Ejemplo n.º 16
0
 public void Setup()
 {
     ctx = new Bunit.TestContext();
     ctx.AddTestServices();
 }
Ejemplo n.º 17
0
 public void InitBase()
 {
     _testContext = new Bunit.TestContext();
 }