Skip to content

Commit

Permalink
Tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Dec 11, 2024
1 parent bbb595a commit c302ea1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" NoWarn="NU1608" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" NoWarn="NU1608" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Verify.DiffPlex" Version="3.1.2" />
<PackageReference Include="Verify.NUnit" Version="28.3.1" />
<PackageReference Include="Verify.NUnit" Version="28.4.0" />
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -429,7 +428,7 @@ private static GeneratorDriverRunResult Generate(string input,
.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithNullableContextOptions(NullableContextOptions.Enable));

var result = CSharpGeneratorDriver.Create(new RazorBladeSourceGenerator())
.AddAdditionalTexts(ImmutableArray.Create<AdditionalText>(new AdditionalTextMock(input, "./TestFile.cshtml")))
.AddAdditionalTexts([new AdditionalTextMock(input, "./TestFile.cshtml")])
.WithUpdatedAnalyzerConfigOptions(analyzerConfigOptionsProvider)
.RunGeneratorsAndUpdateCompilation(compilation, out var updatedCompilation, out _)
.GetRunResult();
Expand Down
6 changes: 6 additions & 0 deletions src/RazorBlade.IntegrationTest.Embedded/TestTemplate.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
@using System
@inherits RazorBlade.HtmlTemplate<string>

<b>Hello, @Name and @Model!</b>

@{
Func<string, IEncodedContent> bold = @<b>@item</b>;
}
@bold("Bold text")

@functions {
public string? Name { get; set; }
}
3 changes: 1 addition & 2 deletions src/RazorBlade.IntegrationTest/TestTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
@{
Func<string, IEncodedContent> bold = @<b>@item</b>;
}

@bold("Bold text")
@bold("Other bold text")
@bold("Other <i>bold</i> text")

@(new Footer())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.0" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
Expand Down
26 changes: 26 additions & 0 deletions src/RazorBlade.Library.Tests/RazorTemplateTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -234,6 +235,31 @@ public async Task should_buffer_output_until_flushed()
}

[Test]
public void should_push_pop_writers()
{
var writerA = new StringWriter();
var writerB = new StringWriter();

var template = new Template(t =>
{
t.Write("A");
t.PushWriter(writerA);
t.Write("B");
t.PushWriter(writerB);
t.Write("C");
t.PopWriter();
t.Write("D");
t.PopWriter();
t.Write("E");
});

template.Render().ShouldEqual("AE");
writerA.ToString().ShouldEqual("BD");
writerB.ToString().ShouldEqual("C");
}

[Test]
[SuppressMessage("ReSharper", "ConvertToLocalFunction")]
public void should_execute_templated_delegate()
{
var template = new Template(t =>
Expand Down
8 changes: 6 additions & 2 deletions src/RazorBlade.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B4D42B3B_002D434D_002D4899_002DA17F_002D1B53AA7A94D0_002Ff_003ATestTemplate_002Ecshtml_002Fz_003A2_002D0/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B4D42B3B_002D434D_002D4899_002DA17F_002D1B53AA7A94D0_002Ff_003ATestTemplateAsync_002Ecshtml_002Fz_003A2_002D0/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B4D42B3B_002D434D_002D4899_002DA17F_002D1B53AA7A94D0_002Ff_003ATestTemplateAsync_002Ecshtml_002Fz_003A2_002D0/@EntryIndexRemoved">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B4D42B3B_002D434D_002D4899_002DA17F_002D1B53AA7A94D0_002Ff_003ATestTemplate_002Ecshtml_002Fz_003A2_002D0/@EntryIndexedValue"></s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B4D42B3B_002D434D_002D4899_002DA17F_002D1B53AA7A94D0_002Ff_003ATestTemplateAsync_002Ecshtml_002Fz_003A2_002D0/@EntryIndexedValue"></s:String>
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B4D42B3B_002D434D_002D4899_002DA17F_002D1B53AA7A94D0_002Ff_003ATestTemplate_002Ecshtml_002Fz_003A2_002D0/@EntryIndexRemoved">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=RazorBlade_002EIntegrationTest/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=RazorBlade_002EIntegrationTest_002EEmbedded/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=BCD4D9F3D5D80845AFB05282C2AD202D/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=BCD4D9F3D5D80845AFB05282C2AD202D/Applicability/=Live/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=BCD4D9F3D5D80845AFB05282C2AD202D/Description/@EntryValue">Unit test</s:String>
Expand Down

0 comments on commit c302ea1

Please sign in to comment.