|
1 |
| -// Copyright (c) .NET Foundation. All rights reserved. |
| 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 | 4 | using Microsoft.AspNetCore.Razor.Language.Components;
|
@@ -381,6 +381,60 @@ public void Execute_HasRequiredInfo_AndImport_AddsItemAndSourceChecksum()
|
381 | 381 | Assert.Equal("/Foo/Import.cshtml", checksum.Identifier);
|
382 | 382 | }
|
383 | 383 |
|
| 384 | + [Fact] |
| 385 | + public void Execute_SuppressMetadataSourceChecksumAttributes_DoesNotGenerateSourceChecksumAttributes() |
| 386 | + { |
| 387 | + // Arrange |
| 388 | + var engine = CreateEngine(); |
| 389 | + var pass = new MetadataAttributePass() |
| 390 | + { |
| 391 | + Engine = engine, |
| 392 | + }; |
| 393 | + |
| 394 | + var sourceDocument = TestRazorSourceDocument.Create("", new RazorSourceDocumentProperties(null, "Foo\\Bar.cshtml")); |
| 395 | + var import = TestRazorSourceDocument.Create("@using System", new RazorSourceDocumentProperties(null, "Foo\\Import.cshtml")); |
| 396 | + var codeDocument = RazorCodeDocument.Create(sourceDocument, new[] { import, }); |
| 397 | + |
| 398 | + var irDocument = new DocumentIntermediateNode() |
| 399 | + { |
| 400 | + DocumentKind = "test", |
| 401 | + Options = RazorCodeGenerationOptions.Create(o => o.SuppressMetadataSourceChecksumAttributes = true), |
| 402 | + }; |
| 403 | + var builder = IntermediateNodeBuilder.Create(irDocument); |
| 404 | + var @namespace = new NamespaceDeclarationIntermediateNode |
| 405 | + { |
| 406 | + Annotations = |
| 407 | + { |
| 408 | + [CommonAnnotations.PrimaryNamespace] = CommonAnnotations.PrimaryNamespace, |
| 409 | + }, |
| 410 | + Content = "Some.Namespace" |
| 411 | + }; |
| 412 | + builder.Push(@namespace); |
| 413 | + var @class = new ClassDeclarationIntermediateNode |
| 414 | + { |
| 415 | + Annotations = |
| 416 | + { |
| 417 | + [CommonAnnotations.PrimaryClass] = CommonAnnotations.PrimaryClass, |
| 418 | + }, |
| 419 | + ClassName = "Test", |
| 420 | + }; |
| 421 | + builder.Add(@class); |
| 422 | + |
| 423 | + // Act |
| 424 | + pass.Execute(codeDocument, irDocument); |
| 425 | + |
| 426 | + // Assert |
| 427 | + Assert.Equal(2, irDocument.Children.Count); |
| 428 | + |
| 429 | + var item = Assert.IsType<RazorCompiledItemAttributeIntermediateNode>(irDocument.Children[0]); |
| 430 | + Assert.Equal("/Foo/Bar.cshtml", item.Identifier); |
| 431 | + Assert.Equal("test", item.Kind); |
| 432 | + Assert.Equal("Some.Namespace.Test", item.TypeName); |
| 433 | + |
| 434 | + var child = Assert.Single(@namespace.Children); |
| 435 | + Assert.IsType<ClassDeclarationIntermediateNode>(child); |
| 436 | + } |
| 437 | + |
384 | 438 | private static RazorEngine CreateEngine()
|
385 | 439 | {
|
386 | 440 | return RazorProjectEngine.Create(b =>
|
|
0 commit comments