Skip to content

Commit 75c7d20

Browse files
committed
added sample project
1 parent f87ffc7 commit 75c7d20

17 files changed

+197
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="my-component">
2+
This Blazor component is defined in the <strong>ComponentLib</strong> package.
3+
</div>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<IsPackable>true</IsPackable>
6+
<RestoreAdditionalProjectSources>
7+
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
8+
https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
9+
</RestoreAdditionalProjectSources>
10+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
11+
<Nullable>enable</Nullable>
12+
<LangVersion>8.0</LangVersion>
13+
<RazorLangVersion>3.0</RazorLangVersion>
14+
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
15+
</PropertyGroup>
16+
17+
<ItemGroup>
18+
<!-- .js/.css files will be referenced via <script>/<link> tags; other content files will just be included in the app's 'dist' directory without any tags referencing them -->
19+
<EmbeddedResource Include="content\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
20+
<EmbeddedResource Include="content\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
21+
<EmbeddedResource Include="content\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<PackageReference Include="Microsoft.AspNetCore.Components.Browser" Version="3.0.0-preview7.19365.7" />
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.JSInterop;
2+
using System.Threading.Tasks;
3+
4+
namespace ComponentLib
5+
{
6+
public class ExampleJsInterop
7+
{
8+
public static Task<string> Prompt(IJSRuntime jsRuntime, string message)
9+
{
10+
// Implemented in exampleJsInterop.js
11+
return jsRuntime.InvokeAsync<string>(
12+
"exampleJsFunctions.showPrompt",
13+
message);
14+
}
15+
}
16+
}
378 Bytes
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is to show how a library package may provide JavaScript interop features
2+
// wrapped in a .NET API
3+
4+
window.exampleJsFunctions = {
5+
showPrompt: function (message) {
6+
return prompt(message, 'Type anything here');
7+
}
8+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
This file is to show how CSS and other static resources (such as images) can be
3+
used from a library project/package.
4+
*/
5+
6+
.my-component {
7+
border: 2px dashed red;
8+
padding: 1em;
9+
margin: 1em 0;
10+
background-image: url('background.png');
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Egil.RazorComponents.Testing;
7+
using Xunit;
8+
9+
namespace ComponentLib
10+
{
11+
public class Component1Test : RazorComponentFixture
12+
{
13+
[Fact]
14+
public void Component1Test_1()
15+
{
16+
var expectedHtml = @"<div class=""my-component"">
17+
This Blazor component is defined in the <strong>ComponentLib</strong> package.
18+
</div>
19+
";
20+
21+
var result = Component<Component1>().Render();
22+
23+
result.ShouldBe(expectedHtml);
24+
}
25+
26+
[Fact]
27+
public void Component1Test_1_FAILS()
28+
{
29+
var expectedHtml = @"<hr />";
30+
31+
var result = Component<Component1>().Render();
32+
33+
result.ShouldBe(expectedHtml);
34+
}
35+
}
36+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<LangVersion>8.0</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
8+
<IsPackable>false</IsPackable>
9+
<RootNamespace>ComponentLib</RootNamespace>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0-preview7.19365.7" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
15+
<PackageReference Include="Moq" Version="4.12.0" />
16+
<PackageReference Include="Shouldly" Version="3.0.2" />
17+
<PackageReference Include="XMLUnit.Core" Version="2.7.1" />
18+
<PackageReference Include="xunit" Version="2.4.1" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="..\..\src\razor-component-testing-library.csproj" />
27+
<ProjectReference Include="..\ComponentLib\ComponentLib.csproj" />
28+
</ItemGroup>
29+
30+
</Project>

sample/Testing-Sample.sln

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentLib", "ComponentLib\ComponentLib.csproj", "{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentLibTests", "ComponentLibTests\ComponentLibTests.csproj", "{5B0A2111-A311-470C-B3C7-7D8A5B511E94}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "razor-component-testing-library", "..\src\razor-component-testing-library.csproj", "{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Debug|x64 = Debug|x64
16+
Debug|x86 = Debug|x86
17+
Release|Any CPU = Release|Any CPU
18+
Release|x64 = Release|x64
19+
Release|x86 = Release|x86
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
25+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Debug|x64.ActiveCfg = Debug|Any CPU
28+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Debug|x64.Build.0 = Debug|Any CPU
29+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Debug|x86.ActiveCfg = Debug|Any CPU
30+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Debug|x86.Build.0 = Debug|Any CPU
31+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Release|x64.ActiveCfg = Release|Any CPU
34+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Release|x64.Build.0 = Release|Any CPU
35+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Release|x86.ActiveCfg = Release|Any CPU
36+
{EF6DF0EB-AB3F-4ADA-B0E4-0666F428B7D0}.Release|x86.Build.0 = Release|Any CPU
37+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Debug|x64.ActiveCfg = Debug|Any CPU
40+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Debug|x64.Build.0 = Debug|Any CPU
41+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Debug|x86.ActiveCfg = Debug|Any CPU
42+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Debug|x86.Build.0 = Debug|Any CPU
43+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Release|x64.ActiveCfg = Release|Any CPU
46+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Release|x64.Build.0 = Release|Any CPU
47+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Release|x86.ActiveCfg = Release|Any CPU
48+
{5B0A2111-A311-470C-B3C7-7D8A5B511E94}.Release|x86.Build.0 = Release|Any CPU
49+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Debug|x64.ActiveCfg = Debug|Any CPU
52+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Debug|x64.Build.0 = Debug|Any CPU
53+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Debug|x86.ActiveCfg = Debug|Any CPU
54+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Debug|x86.Build.0 = Debug|Any CPU
55+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Release|x64.ActiveCfg = Release|Any CPU
58+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Release|x64.Build.0 = Release|Any CPU
59+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Release|x86.ActiveCfg = Release|Any CPU
60+
{CE16B524-01E0-45F3-8C0E-1D1BE1639D3B}.Release|x86.Build.0 = Release|Any CPU
61+
EndGlobalSection
62+
EndGlobal

0 commit comments

Comments
 (0)