Skip to content

Commit

Permalink
Added support for scoped css attribute and .net preview 8 (#195)
Browse files Browse the repository at this point in the history
* Added support for scoped css attribute

* updated changelog
  • Loading branch information
egil committed Aug 26, 2020
1 parent 5ca56c7 commit 6c66b41
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ List of new features.

- Added `InvokeAsync(Func<Task>)` to `RenderedComponentInvokeAsyncExtensions`. By [@JeroenBos](https://github.com/JeroenBos) in [#151](https://github.com/egil/bUnit/pull/177).
- Added `ITestRenderer Renderer { get ; }` to `IRenderedFragment` to make it possible to simplify the `IRenderedComponentBase<TComponent>` interface. By [@JeroenBos](https://github.com/JeroenBos) in [#151](https://github.com/egil/bUnit/pull/177).
- Added support for scoped CSS to `MarkupMatches` and related comparer methods. By [@egil](https://github.com/egil) in [#195](https://github.com/egil/bUnit/pull/195).

### Changed
List of changes in existing functionality.
Expand Down
10 changes: 5 additions & 5 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0' AND $(MSBuildProjectName)!='bunit.template' AND $(MSBuildProjectName)!='bunit'">
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-preview.8.*" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName)!='bunit.template' AND $(MSBuildProjectName)!='bunit'">
Expand Down
4 changes: 3 additions & 1 deletion src/bunit.web/Rendering/Internal/Htmlizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ internal class Htmlizer
};

private const string BLAZOR_INTERNAL_ATTR_PREFIX = "__internal_";
private const string BLAZOR_CSS_SCOPE_ATTR_PREFIX = "b-";
public const string BLAZOR_ATTR_PREFIX = "blazor:";
public const string ELEMENT_REFERENCE_ATTR_NAME = BLAZOR_ATTR_PREFIX + "elementreference";

public static bool IsBlazorAttribute(string attributeName)
=> attributeName.StartsWith(BLAZOR_ATTR_PREFIX, StringComparison.Ordinal);
=> attributeName.StartsWith(BLAZOR_ATTR_PREFIX, StringComparison.Ordinal) ||
attributeName.StartsWith(BLAZOR_CSS_SCOPE_ATTR_PREFIX, StringComparison.Ordinal);

public static string ToBlazorAttribute(string attributeName)
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0' AND $(MSBuildProjectName)!='bunit.testassets'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-preview.8.*" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName)!='bunit.testassets'">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello Pink World!</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
color: deeppink;
}
11 changes: 7 additions & 4 deletions tests/bunit.testassets/bunit.testassets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
<RazorLangVersion>3.0</RazorLangVersion>
<RootNamespace>Bunit.TestAssets</RootNamespace>
<AssemblyName>Bunit.TestAssets</AssemblyName>
<IsPackable>false</IsPackable>
Expand All @@ -15,15 +14,19 @@
<WarningsAsErrors>CS8602;CS8603;CS8625</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.0-preview.8.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-preview.8.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if NET5_0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Bunit.TestAssets.SampleComponents;

using Xunit;

namespace Bunit
{
public partial class MarkupMatchesAssertExtensionsTest : TestContext
{
[Fact(DisplayName = "MarkupMatches correctly ignores scoped css attributes")]
public void Test_net5_001()
{
var cut = RenderComponent<ScopedCssElements>();

cut.MarkupMatches("<h1>Hello Pink World!</h1>");
}
}
}

#endif
6 changes: 4 additions & 2 deletions tests/bunit.web.tests/Rendering/Internal/HtmlizerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using Bunit.TestAssets.BlazorE2E;
using Bunit.TestAssets.SampleComponents;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.Web;
Expand All @@ -8,9 +10,9 @@

namespace Bunit.Rendering.Internal
{
public class HtmlizerTests : TestContext
public partial class HtmlizerTests : TestContext
{
[Theory(DisplayName = "The component contains correctly prefixed internal attributes.")]
[Theory(DisplayName = "Htmlizer correctly prefixed stopPropagation and preventDefault attributes")]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
Expand Down
27 changes: 27 additions & 0 deletions tests/bunit.web.tests/Rendering/Internal/HtmlizerTests.net5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if NET5_0
using System;
using Bunit.TestAssets.BlazorE2E;
using Bunit.TestAssets.SampleComponents;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.Web;
using Shouldly;
using Xunit;

namespace Bunit.Rendering.Internal
{
public partial class HtmlizerTests : TestContext
{
[Theory(DisplayName = "IsBlazorAttribute correctly identifies Blazor attributes")]
[InlineData("b-twl12ishk1=\"\"")]
[InlineData("blazor:onclick=\"1\"")]
[InlineData("blazor:__internal_stopPropagation_onclick=\"\"")]
[InlineData("blazor:__internal_preventDefault_onclick=\"\"")]
public void TestNET5_001(string blazorAttribute)
{
Htmlizer.IsBlazorAttribute(blazorAttribute).ShouldBeTrue();
}
}
}
#endif

0 comments on commit 6c66b41

Please sign in to comment.