|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the Apache 2.0 License |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | +// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone |
| 5 | + |
| 6 | +namespace UnitTest.Components; |
| 7 | + |
| 8 | +public class BootstrapBlazorRootOutletTest : BootstrapBlazorTestBase |
| 9 | +{ |
| 10 | + [Fact] |
| 11 | + public async Task Content_Ok() |
| 12 | + { |
| 13 | + var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb => |
| 14 | + { |
| 15 | + pb.Add(a => a.EnableErrorLogger, false); |
| 16 | + pb.AddChildContent<BootstrapBlazorRootContent>(pbc => |
| 17 | + { |
| 18 | + pbc.Add(a => a.RootName, "test"); |
| 19 | + pbc.AddChildContent("test-content"); |
| 20 | + }); |
| 21 | + }); |
| 22 | + cut.DoesNotContain("test-content"); |
| 23 | + |
| 24 | + var content = cut.FindComponent<BootstrapBlazorRootContent>(); |
| 25 | + content.SetParametersAndRender(pb => |
| 26 | + { |
| 27 | + pb.Add(a => a.RootName, null); |
| 28 | + }); |
| 29 | + cut.Contains("test-content"); |
| 30 | + |
| 31 | + content.SetParametersAndRender(pb => |
| 32 | + { |
| 33 | + pb.Add(a => a.RootId, new object()); |
| 34 | + }); |
| 35 | + cut.DoesNotContain("test-content"); |
| 36 | + |
| 37 | + content.SetParametersAndRender(pb => |
| 38 | + { |
| 39 | + pb.Add(a => a.RootId, null); |
| 40 | + }); |
| 41 | + cut.Contains("test-content"); |
| 42 | + |
| 43 | + content.SetParametersAndRender(pb => |
| 44 | + { |
| 45 | + pb.AddChildContent((RenderFragment)null!); |
| 46 | + }); |
| 47 | + |
| 48 | + var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => |
| 49 | + { |
| 50 | + content.SetParametersAndRender(pb => |
| 51 | + { |
| 52 | + pb.Add(a => a.RootName, "test"); |
| 53 | + pb.Add(a => a.RootId, new object()); |
| 54 | + }); |
| 55 | + return Task.CompletedTask; |
| 56 | + }); |
| 57 | + Assert.Equal("BootstrapBlazorRootContent requires that 'RootName' and 'RootId' cannot both have non-null values.", exception.Message); |
| 58 | + } |
| 59 | + |
| 60 | + [Fact] |
| 61 | + public async Task Outlet_Ok() |
| 62 | + { |
| 63 | + var cut = Context.RenderComponent<BootstrapBlazorRootOutlet>(pb => |
| 64 | + { |
| 65 | + pb.Add(a => a.RootId, new object()); |
| 66 | + }); |
| 67 | + Assert.Empty(cut.Markup); |
| 68 | + |
| 69 | + cut.SetParametersAndRender(pb => |
| 70 | + { |
| 71 | + pb.Add(a => a.RootId, null); |
| 72 | + pb.Add(a => a.RootName, "test"); |
| 73 | + }); |
| 74 | + Assert.Empty(cut.Markup); |
| 75 | + |
| 76 | + var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => |
| 77 | + { |
| 78 | + cut.SetParametersAndRender(pb => |
| 79 | + { |
| 80 | + pb.Add(a => a.RootName, "test"); |
| 81 | + pb.Add(a => a.RootId, new object()); |
| 82 | + }); |
| 83 | + return Task.CompletedTask; |
| 84 | + }); |
| 85 | + Assert.Equal("BootstrapBlazorRootOutlet requires that 'RootName' and 'RootId' cannot both have non-null values.", exception.Message); |
| 86 | + } |
| 87 | +} |
0 commit comments