|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved.
|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3 | 3 |
|
4 |
| -using System.Linq; |
5 |
| -using Microsoft.AspNetCore.Components.Razor; |
6 |
| -using Microsoft.AspNetCore.Components; |
7 | 4 | using Microsoft.AspNetCore.Components.RenderTree;
|
8 | 5 | using Microsoft.AspNetCore.Components.Test.Helpers;
|
9 | 6 | using Microsoft.CodeAnalysis.CSharp;
|
10 | 7 | using Xunit;
|
| 8 | +using Xunit.Abstractions; |
11 | 9 |
|
12 | 10 | namespace Microsoft.AspNetCore.Components.Build.Test
|
13 | 11 | {
|
@@ -84,6 +82,11 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
|
84 | 82 | }
|
85 | 83 | ");
|
86 | 84 |
|
| 85 | + public ChildContentRazorIntegrationTest(ITestOutputHelper output) |
| 86 | + : base(output) |
| 87 | + { |
| 88 | + } |
| 89 | + |
87 | 90 | internal override bool UseTwoPhaseCompilation => true;
|
88 | 91 |
|
89 | 92 | [Fact]
|
@@ -410,174 +413,5 @@ public void Render_MultipleChildContent_ContextParameterOnComponent_SetsSameName
|
410 | 413 | frame => AssertFrame.Text(frame, " Content", 9),
|
411 | 414 | frame => AssertFrame.Text(frame, "Bye!", 11));
|
412 | 415 | }
|
413 |
| - |
414 |
| - [Fact] |
415 |
| - public void Render_ChildContent_AttributeAndBody_ProducesDiagnostic() |
416 |
| - { |
417 |
| - // Arrange |
418 |
| - AdditionalSyntaxTrees.Add(RenderChildContentComponent); |
419 |
| - |
420 |
| - // Act |
421 |
| - var generated = CompileToCSharp(@" |
422 |
| -@addTagHelper *, TestAssembly |
423 |
| -@{ RenderFragment<string> template = @<div>@context.ToLowerInvariant()</div>; } |
424 |
| -<RenderChildContent ChildContent=""@template.WithValue(""HI"")""> |
425 |
| -Some Content |
426 |
| -</RenderChildContent>"); |
427 |
| - |
428 |
| - // Assert |
429 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
430 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id); |
431 |
| - } |
432 |
| - |
433 |
| - [Fact] |
434 |
| - public void Render_ChildContent_AttributeAndExplicitChildContent_ProducesDiagnostic() |
435 |
| - { |
436 |
| - // Arrange |
437 |
| - AdditionalSyntaxTrees.Add(RenderChildContentComponent); |
438 |
| - |
439 |
| - // Act |
440 |
| - var generated = CompileToCSharp(@" |
441 |
| -@addTagHelper *, TestAssembly |
442 |
| -@{ RenderFragment<string> template = @<div>@context.ToLowerInvariant()</div>; } |
443 |
| -<RenderChildContent ChildContent=""@template.WithValue(""HI"")""> |
444 |
| -<ChildContent> |
445 |
| -Some Content |
446 |
| -</ChildContent> |
447 |
| -</RenderChildContent>"); |
448 |
| - |
449 |
| - // Assert |
450 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
451 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id); |
452 |
| - } |
453 |
| - |
454 |
| - [Fact] |
455 |
| - public void Render_ChildContent_ExplicitChildContent_UnrecogizedContent_ProducesDiagnostic() |
456 |
| - { |
457 |
| - // Arrange |
458 |
| - AdditionalSyntaxTrees.Add(RenderChildContentComponent); |
459 |
| - |
460 |
| - // Act |
461 |
| - var generated = CompileToCSharp(@" |
462 |
| -@addTagHelper *, TestAssembly |
463 |
| -<RenderChildContent> |
464 |
| -<ChildContent> |
465 |
| -</ChildContent> |
466 |
| -@somethingElse |
467 |
| -</RenderChildContent>"); |
468 |
| - |
469 |
| - // Assert |
470 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
471 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentMixedWithExplicitChildContent.Id, diagnostic.Id); |
472 |
| - Assert.Equal( |
473 |
| - "Unrecognized child content inside component 'RenderChildContent'. The component 'RenderChildContent' accepts " + |
474 |
| - "child content through the following top-level items: 'ChildContent'.", |
475 |
| - diagnostic.GetMessage()); |
476 |
| - } |
477 |
| - |
478 |
| - [Fact] |
479 |
| - public void Render_ChildContent_ExplicitChildContent_UnrecogizedElement_ProducesDiagnostic() |
480 |
| - { |
481 |
| - // Arrange |
482 |
| - AdditionalSyntaxTrees.Add(RenderChildContentComponent); |
483 |
| - |
484 |
| - // Act |
485 |
| - var generated = CompileToCSharp(@" |
486 |
| -@addTagHelper *, TestAssembly |
487 |
| -<RenderChildContent> |
488 |
| -<ChildContent> |
489 |
| -</ChildContent> |
490 |
| -<UnrecognizedChildContent></UnrecognizedChildContent> |
491 |
| -</RenderChildContent>"); |
492 |
| - |
493 |
| - // Assert |
494 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
495 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentMixedWithExplicitChildContent.Id, diagnostic.Id); |
496 |
| - } |
497 |
| - |
498 |
| - [Fact] |
499 |
| - public void Render_ChildContent_ExplicitChildContent_UnrecogizedAttribute_ProducesDiagnostic() |
500 |
| - { |
501 |
| - // Arrange |
502 |
| - AdditionalSyntaxTrees.Add(RenderChildContentComponent); |
503 |
| - |
504 |
| - // Act |
505 |
| - var generated = CompileToCSharp(@" |
506 |
| -@addTagHelper *, TestAssembly |
507 |
| -<RenderChildContent> |
508 |
| -<ChildContent attr> |
509 |
| -</ChildContent> |
510 |
| -</RenderChildContent>"); |
511 |
| - |
512 |
| - // Assert |
513 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
514 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentHasInvalidAttribute.Id, diagnostic.Id); |
515 |
| - } |
516 |
| - |
517 |
| - [Fact] |
518 |
| - public void Render_ChildContent_ExplicitChildContent_InvalidParameterName_ProducesDiagnostic() |
519 |
| - { |
520 |
| - // Arrange |
521 |
| - AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); |
522 |
| - |
523 |
| - // Act |
524 |
| - var generated = CompileToCSharp(@" |
525 |
| -@addTagHelper *, TestAssembly |
526 |
| -<RenderChildContentString> |
527 |
| -<ChildContent Context=""@(""HI"")""> |
528 |
| -</ChildContent> |
529 |
| -</RenderChildContentString>"); |
530 |
| - |
531 |
| - // Assert |
532 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
533 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentHasInvalidParameter.Id, diagnostic.Id); |
534 |
| - } |
535 |
| - |
536 |
| - [Fact] |
537 |
| - public void Render_ChildContent_ExplicitChildContent_RepeatedParameterName_GeneratesDiagnostic() |
538 |
| - { |
539 |
| - // Arrange |
540 |
| - AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); |
541 |
| - |
542 |
| - // Act |
543 |
| - var generated = CompileToCSharp(@" |
544 |
| -@addTagHelper *, TestAssembly |
545 |
| -<RenderChildContentString> |
546 |
| -<ChildContent> |
547 |
| -<RenderChildContentString> |
548 |
| -<ChildContent Context=""context""> |
549 |
| -</ChildContent> |
550 |
| -</RenderChildContentString> |
551 |
| -</ChildContent> |
552 |
| -</RenderChildContentString>"); |
553 |
| - |
554 |
| - // Assert |
555 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
556 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentRepeatedParameterName.Id, diagnostic.Id); |
557 |
| - Assert.Equal( |
558 |
| - "The child content element 'ChildContent' of component 'RenderChildContentString' uses the same parameter name ('context') as enclosing child content " + |
559 |
| - "element 'ChildContent' of component 'RenderChildContentString'. Specify the parameter name like: '<ChildContent Context=\"another_name\"> to resolve the ambiguity", |
560 |
| - diagnostic.GetMessage()); |
561 |
| - } |
562 |
| - |
563 |
| - [Fact] |
564 |
| - public void Render_ChildContent_ContextParameterNameOnComponent_Invalid_ProducesDiagnostic() |
565 |
| - { |
566 |
| - // Arrange |
567 |
| - AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); |
568 |
| - |
569 |
| - // Act |
570 |
| - var generated = CompileToCSharp(@" |
571 |
| -@addTagHelper *, TestAssembly |
572 |
| -<RenderChildContentString Context=""@Foo()""> |
573 |
| -</RenderChildContentString>"); |
574 |
| - |
575 |
| - // Assert |
576 |
| - var diagnostic = Assert.Single(generated.Diagnostics); |
577 |
| - Assert.Same(BlazorDiagnosticFactory.ChildContentHasInvalidParameterOnComponent.Id, diagnostic.Id); |
578 |
| - Assert.Equal( |
579 |
| - "Invalid parameter name. The parameter name attribute 'Context' on component 'RenderChildContentString' can only include literal text.", |
580 |
| - diagnostic.GetMessage()); |
581 |
| - } |
582 | 416 | }
|
583 | 417 | }
|
0 commit comments