@@ -688,6 +688,121 @@ public void DefineStaticWebAssetsCache_CanRoundtripManifest()
688
688
File . Delete ( manifestPath ) ;
689
689
}
690
690
}
691
+
692
+ [ Fact ]
693
+ public void ComputesRelativePath_ForDiscoveredAssetsWithFullPath ( )
694
+ {
695
+ var errorMessages = new List < string > ( ) ;
696
+ var buildEngine = new Mock < IBuildEngine > ( ) ;
697
+ buildEngine . Setup ( e => e . LogErrorEvent ( It . IsAny < BuildErrorEventArgs > ( ) ) )
698
+ . Callback < BuildErrorEventArgs > ( args => errorMessages . Add ( args . Message ) ) ;
699
+ buildEngine . SetupGet ( e => e . ProjectFileOfTaskNode )
700
+ . Returns ( Path . Combine ( Environment . CurrentDirectory , "Debug" , "TestProject.csproj" ) ) ;
701
+
702
+ var debugDir = Path . Combine ( Environment . CurrentDirectory , "Debug" , "wwwroot" ) ;
703
+ var task = new DefineStaticWebAssets
704
+ {
705
+ BuildEngine = buildEngine . Object ,
706
+ CandidateAssets = [
707
+ new TaskItem ( Path . Combine ( debugDir , "Microsoft.AspNetCore.Components.CustomElements.lib.module.js" ) ,
708
+ new Dictionary < string , string > { [ "Integrity" ] = "integrity" , [ "Fingerprint" ] = "fingerprint" } ) ,
709
+ new TaskItem ( Path . Combine ( debugDir , "Microsoft.AspNetCore.Components.CustomElements.lib.module.js.map" ) ,
710
+ new Dictionary < string , string > { [ "Integrity" ] = "integrity" , [ "Fingerprint" ] = "fingerprint" } )
711
+ ] ,
712
+ RelativePathPattern = "wwwroot/**" ,
713
+ SourceType = "Discovered" ,
714
+ SourceId = "Microsoft.AspNetCore.Components.CustomElements" ,
715
+ ContentRoot = debugDir ,
716
+ BasePath = "_content/Microsoft.AspNetCore.Components.CustomElements" ,
717
+ TestResolveFileDetails = _testResolveFileDetails ,
718
+ } ;
719
+
720
+ // Act
721
+ var result = task . Execute ( ) ;
722
+
723
+ // Assert
724
+ result . Should ( ) . BeTrue ( $ "Errors: { Environment . NewLine } { string . Join ( $ "{ Environment . NewLine } ", errorMessages ) } ") ;
725
+ task . Assets . Length . Should ( ) . Be ( 2 ) ;
726
+ task . Assets [ 0 ] . GetMetadata ( nameof ( StaticWebAsset . RelativePath ) ) . Should ( ) . Be ( "Microsoft.AspNetCore.Components.CustomElements.lib.module.js" ) ;
727
+ task . Assets [ 0 ] . GetMetadata ( nameof ( StaticWebAsset . BasePath ) ) . Should ( ) . Be ( "_content/Microsoft.AspNetCore.Components.CustomElements" ) ;
728
+ task . Assets [ 1 ] . GetMetadata ( nameof ( StaticWebAsset . RelativePath ) ) . Should ( ) . Be ( "Microsoft.AspNetCore.Components.CustomElements.lib.module.js.map" ) ;
729
+ task . Assets [ 1 ] . GetMetadata ( nameof ( StaticWebAsset . BasePath ) ) . Should ( ) . Be ( "_content/Microsoft.AspNetCore.Components.CustomElements" ) ;
730
+ }
731
+
732
+ [ Fact ]
733
+ public void ComputesRelativePath_WorksForItemsWithRelativePaths ( )
734
+ {
735
+ var errorMessages = new List < string > ( ) ;
736
+ var buildEngine = new Mock < IBuildEngine > ( ) ;
737
+ buildEngine . Setup ( e => e . LogErrorEvent ( It . IsAny < BuildErrorEventArgs > ( ) ) )
738
+ . Callback < BuildErrorEventArgs > ( args => errorMessages . Add ( args . Message ) ) ;
739
+ buildEngine . SetupGet ( e => e . ProjectFileOfTaskNode )
740
+ . Returns ( Path . Combine ( Environment . CurrentDirectory , "Debug" , "TestProject.csproj" ) ) ;
741
+
742
+ var debugDir = Path . Combine ( Environment . CurrentDirectory , "Debug" , "wwwroot" ) ;
743
+ var task = new DefineStaticWebAssets
744
+ {
745
+ BuildEngine = buildEngine . Object ,
746
+ CandidateAssets = [
747
+ new TaskItem ( Path . Combine ( "wwwroot" , "Microsoft.AspNetCore.Components.CustomElements.lib.module.js" ) ,
748
+ new Dictionary < string , string > { [ "Integrity" ] = "integrity" , [ "Fingerprint" ] = "fingerprint" } ) ,
749
+ new TaskItem ( Path . Combine ( "wwwroot" , "Microsoft.AspNetCore.Components.CustomElements.lib.module.js.map" ) ,
750
+ new Dictionary < string , string > { [ "Integrity" ] = "integrity" , [ "Fingerprint" ] = "fingerprint" } )
751
+ ] ,
752
+ RelativePathPattern = "wwwroot/**" ,
753
+ SourceType = "Discovered" ,
754
+ SourceId = "Microsoft.AspNetCore.Components.CustomElements" ,
755
+ ContentRoot = debugDir ,
756
+ BasePath = "_content/Microsoft.AspNetCore.Components.CustomElements" ,
757
+ TestResolveFileDetails = _testResolveFileDetails ,
758
+ } ;
759
+
760
+ // Act
761
+ var result = task . Execute ( ) ;
762
+
763
+ // Assert
764
+ result . Should ( ) . BeTrue ( $ "Errors: { Environment . NewLine } { string . Join ( $ "{ Environment . NewLine } ", errorMessages ) } ") ;
765
+ task . Assets . Length . Should ( ) . Be ( 2 ) ;
766
+ task . Assets [ 0 ] . GetMetadata ( nameof ( StaticWebAsset . RelativePath ) ) . Should ( ) . Be ( "Microsoft.AspNetCore.Components.CustomElements.lib.module.js" ) ;
767
+ task . Assets [ 0 ] . GetMetadata ( nameof ( StaticWebAsset . BasePath ) ) . Should ( ) . Be ( "_content/Microsoft.AspNetCore.Components.CustomElements" ) ;
768
+ task . Assets [ 1 ] . GetMetadata ( nameof ( StaticWebAsset . RelativePath ) ) . Should ( ) . Be ( "Microsoft.AspNetCore.Components.CustomElements.lib.module.js.map" ) ;
769
+ task . Assets [ 1 ] . GetMetadata ( nameof ( StaticWebAsset . BasePath ) ) . Should ( ) . Be ( "_content/Microsoft.AspNetCore.Components.CustomElements" ) ;
770
+ }
771
+
772
+ [ Fact ]
773
+ public void ComputesRelativePath_ForAssets_ExplicitPaths ( )
774
+ {
775
+ var errorMessages = new List < string > ( ) ;
776
+ var buildEngine = new Mock < IBuildEngine > ( ) ;
777
+ buildEngine . Setup ( e => e . LogErrorEvent ( It . IsAny < BuildErrorEventArgs > ( ) ) )
778
+ . Callback < BuildErrorEventArgs > ( args => errorMessages . Add ( args . Message ) ) ;
779
+
780
+ var debugDir = Path . Combine ( Environment . CurrentDirectory , "Debug" ) ;
781
+ var task = new DefineStaticWebAssets
782
+ {
783
+ BuildEngine = buildEngine . Object ,
784
+ CandidateAssets = [
785
+ new TaskItem ( "/home/user/work/Repo/Project/Components/Dropdown/Dropdown.razor.js" ,
786
+ new Dictionary < string , string > { [ "Integrity" ] = "integrity" , [ "Fingerprint" ] = "fingerprint" } ) ,
787
+ ] ,
788
+ RelativePathPattern = "**" ,
789
+ SourceType = "Discovered" ,
790
+ SourceId = "Project" ,
791
+ ContentRoot = "/home/user/work/Repo/Project" ,
792
+ BasePath = "_content/Project" ,
793
+ TestResolveFileDetails = _testResolveFileDetails ,
794
+ } ;
795
+
796
+ // Act
797
+ var result = task . Execute ( ) ;
798
+
799
+ // Assert
800
+ result . Should ( ) . BeTrue ( $ "Errors: { Environment . NewLine } { string . Join ( $ "{ Environment . NewLine } ", errorMessages ) } ") ;
801
+ task . Assets . Length . Should ( ) . Be ( 1 ) ;
802
+ task . Assets [ 0 ] . GetMetadata ( nameof ( StaticWebAsset . RelativePath ) ) . Should ( ) . Be ( "Components/Dropdown/Dropdown.razor.js" ) ;
803
+ task . Assets [ 0 ] . GetMetadata ( nameof ( StaticWebAsset . BasePath ) ) . Should ( ) . Be ( "_content/Project" ) ;
804
+ }
805
+
691
806
private static TaskLoggingHelper CreateLogger ( )
692
807
{
693
808
var errorMessages = new List < string > ( ) ;
0 commit comments