Skip to content

Commit 038f419

Browse files
committed
Updated samples to p8. Moved to netstandard2.0 target.
1 parent 82225c5 commit 038f419

File tree

8 files changed

+44
-20
lines changed

8 files changed

+44
-20
lines changed
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Razor">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
5-
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
6+
<Nullable>enable</Nullable>
7+
<LangVersion>8.0</LangVersion>
8+
<RazorLangVersion>3.0</RazorLangVersion>
69
</PropertyGroup>
710

811
<ItemGroup>
9-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
12+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="$(AspNetCoreVersion)" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion)" />
1014
</ItemGroup>
1115

1216
</Project>

sample/RazorComponentLibTests/AlertTests.razor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ you want.
8787
If you want to assert directly on the rendered component or change its parameters
8888
and re-render, use the component reference syntax and the Render method.
8989

90+
BUG: Currently @@ref doesn't actually generate the required backing field: https://github.com/aspnet/AspNetCore/issues/13099
91+
9092
@code {
91-
Alert sut;
9293
bool isVisible = true;
9394

9495
[Fact(DisplayName = "When Visible is toggled to false, all child content is removed from alert")]
@@ -97,7 +98,7 @@ and re-render, use the component reference syntax and the Render method.
9798
// initial assert
9899
var result = RenderResults.Single(x => x.Id == (nameof(DismissTest)));
99100
result.RenderedHtml.ShouldBe(result.Snippets[0]);
100-
Assert.Equal(true, sut.Visible);
101+
//Assert.Equal(true, sut.Visible); BUG: https://github.com/aspnet/AspNetCore/issues/13099
101102
102103
// act
103104
isVisible = false;
@@ -106,7 +107,7 @@ and re-render, use the component reference syntax and the Render method.
106107
// dismiss assert
107108
var dismissResult = RenderResults.Single(x => x.Id == (nameof(DismissTest)));
108109
dismissResult.RenderedHtml.ShouldBe(result.Snippets[1]);
109-
Assert.Equal(false, sut.Visible);
110+
//Assert.Equal(false, sut.Visible); BUG: https://github.com/aspnet/AspNetCore/issues/13099
110111
}
111112
}
112113
<Fact Id=@nameof(DismissTest)>

sample/RazorComponentLibTests/RazorComponentLibTests.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
5-
<IsPackable>false</IsPackable>
65
<RootNamespace>RazorComponentLib</RootNamespace>
6+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
7+
<Nullable>enable</Nullable>
8+
<LangVersion>8.0</LangVersion>
9+
<RazorLangVersion>3.0</RazorLangVersion>
710
</PropertyGroup>
811

912
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0-preview7.19365.7" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="$(AspNetCoreVersion)" />
14+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion)" />
1115
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
1216
<PackageReference Include="Moq" Version="4.12.0" />
13-
<PackageReference Include="Razor.Components.Testing.Library" Version="0.1.0-preview7-19365-7-2" />
17+
<PackageReference Include="Razor.Components.Testing.Library" Version="0.1.0-preview8-19405-7-1" />
1418
<PackageReference Include="xunit.assert" Version="2.4.1" />
1519
<PackageReference Include="xunit.core" Version="2.4.1" />
1620
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">

sample/Testing-Sample.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
44
VisualStudioVersion = 16.0.29123.89
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{232D6C4C-0791-4A31-AE4F-8C2C9A3C47DC}"
7+
ProjectSection(SolutionItems) = preProject
8+
..\Directory.Build.props = ..\Directory.Build.props
9+
EndProjectSection
710
EndProject
811
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorComponentLib", "RazorComponentLib\RazorComponentLib.csproj", "{A90B9C4D-631B-46BE-9B2A-A11B50D06E8C}"
912
EndProject

src/Diffing/CssClassAttributeDifferenceEvaluator.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Org.XmlUnit.Diff;
45

@@ -14,15 +15,20 @@ public ComparisonResult Evaluate(Comparison comparison, ComparisonResult outcome
1415
if (comparison.Type != ComparisonType.ATTR_VALUE) return outcome;
1516
if (!comparison.TestDetails.Target.Name.Equals("class", StringComparison.OrdinalIgnoreCase)) return outcome;
1617

17-
// BANG: Value should not be null on ControlDetails and TestDetails.
18-
var expected = comparison.ControlDetails.Value.ToString()!.Split(Space, StringSplitOptions.RemoveEmptyEntries).ToHashSet();
19-
var actual = comparison.TestDetails.Value.ToString()!.Split(Space, StringSplitOptions.RemoveEmptyEntries).ToHashSet();
18+
// BANG: Value should not be null on ControlDetails and TestDetails.
19+
var expected = comparison.ControlDetails.Value.ToString()!.Split(Space, StringSplitOptions.RemoveEmptyEntries);
20+
var actual = comparison.TestDetails.Value.ToString()!.Split(Space, StringSplitOptions.RemoveEmptyEntries);
2021

21-
if (expected.SetEquals(actual))
22-
return ComparisonResult.EQUAL;
22+
if (SetEqual(expected, actual)) return ComparisonResult.EQUAL;
2323
else return outcome;
2424
}
2525

26+
private static bool SetEqual(string[] expected, string[] actual)
27+
{
28+
if (expected.Length != actual.Length) return false;
29+
return new HashSet<string>(expected).SetEquals(new HashSet<string>(actual));
30+
}
31+
2632
public static readonly DifferenceEvaluator Default = new CssClassAttributeDifferenceEvaluator().Evaluate;
2733
}
2834
}

src/Egil.RazorComponents.Testing.Library.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
64
<RootNamespace>Egil.RazorComponents.Testing</RootNamespace>
7-
<LangVersion>8.0</LangVersion>
5+
<TargetFramework>netstandard2.0</TargetFramework>
86
<RazorLangVersion>3.0</RazorLangVersion>
7+
<LangVersion>8.0</LangVersion>
98
<Nullable>enable</Nullable>
109
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
1110
<PackageId>Razor.Components.Testing.Library</PackageId>

src/RazerComponentTestRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static ComponentRenderedText GetResult(Task<ComponentRenderedText> task)
4646
{
4747
if (!task.IsCompleted) throw new InvalidOperationException("This should not happen!");
4848

49-
if (task.IsCompletedSuccessfully)
49+
if (task.Status == TaskStatus.RanToCompletion)
5050
{
5151
return task.Result;
5252
}

tests/Egil.RazorComponents.Testing.Library.Tests.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
56
<IsPackable>false</IsPackable>
7+
<LangVersion>8.0</LangVersion>
8+
<Nullable>enable</Nullable>
9+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
610
<RootNamespace>Egil.RazorComponents.Testing.Library</RootNamespace>
711
</PropertyGroup>
812

913
<ItemGroup>
14+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="$(AspNetCoreVersion)" />
15+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion)" />
1016
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
1117
<PackageReference Include="Shouldly" Version="3.0.2" />
18+
<PackageReference Include="xunit.assert" Version="2.4.1" />
1219
<PackageReference Include="xunit.core" Version="2.4.1" />
1320
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
1421
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)