33
44using System ;
55using System . Collections . Generic ;
6+ using System . IO ;
67using System . Linq ;
78using System . Text . RegularExpressions ;
89using NuGet . Services . Validation ;
910using NuGet . Services . Validation . Issues ;
10- using RazorEngine . Configuration ;
11- using RazorEngine . Templating ;
1211using Xunit ;
1312using Xunit . Abstractions ;
1413
@@ -24,25 +23,26 @@ public ValidationIssueFacts(ITestOutputHelper output)
2423 _output = output ;
2524 }
2625
26+ [ Theory ]
2727 [ MemberData ( nameof ( HasACaseForAllIssueTypesTestData ) ) ]
2828 public void HasACaseForAllIssueTypes ( ValidationIssue issue )
2929 {
3030 // Arrange & Act
31- var html = CompileView ( issue ) ;
31+ var template = GetTemplate ( ) ;
3232
3333 // Assert
34- Assert . DoesNotContain ( UnknownIssueMessage , html ) ;
34+ Assert . Contains ( "case ValidationIssueCode." + issue . IssueCode . ToString ( ) , template ) ;
3535 }
3636
3737 [ Theory ]
3838 [ MemberData ( nameof ( HasExpectedMessageForUnknownIssueTestData ) ) ]
3939 public void HasExpectedMessageForUnknownIssue ( ValidationIssue issue )
4040 {
4141 // Arrange & Act
42- var html = CompileView ( issue ) ;
42+ var template = GetTemplate ( ) ;
4343
4444 // Assert
45- Assert . Equal ( UnknownIssueMessage , html ) ;
45+ Assert . DoesNotContain ( issue . IssueCode . ToString ( ) , template ) ;
4646 }
4747
4848 [ Theory ]
@@ -57,34 +57,13 @@ public void AllIssueCodesAreHandled(ValidationIssueCode issueCode)
5757 Assert . Contains ( issueCode , issueCodes ) ;
5858 }
5959
60- private string CompileView ( ValidationIssue issue )
60+ private string GetTemplate ( )
6161 {
62- // Arrange
63- var config = new TemplateServiceConfiguration
64- {
65- TemplateManager = new EmbeddedResourceTemplateManager ( GetType ( ) ) ,
66- DisableTempFileLocking = true ,
67- } ;
68-
69- using ( var razorEngine = RazorEngineService . Create ( config ) )
62+ using ( var stream = GetType ( ) . Assembly . GetManifestResourceStream ( "NuGetGallery.Views.Packages._ValidationIssue.cshtml" ) )
63+ using ( var streamReader = new StreamReader ( stream ) )
7064 {
71- _output . WriteLine ( $ "Issue code: { issue . IssueCode } ") ;
72- _output . WriteLine ( $ "Serialized: { issue . Serialize ( ) } ") ;
73-
74- // Act
75- var html = CollapseWhitespace ( razorEngine . RunCompile ( "_ValidationIssue" , model : issue ) )
76- . Trim ( ) ;
77-
78- _output . WriteLine ( $ "HTML:") ;
79- _output . WriteLine ( html ) ;
80-
81- return html ;
82- }
83- }
84-
85- private string CollapseWhitespace ( string input )
86- {
87- return Regex . Replace ( input , @"\s+" , " " ) ;
65+ return streamReader . ReadToEnd ( ) ;
66+ }
8867 }
8968
9069 public static IEnumerable < ValidationIssue > KnownValidationIssues
0 commit comments