Skip to content

Commit

Permalink
Set up test projects for the core api, maui and the blazor UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
stijuh committed May 20, 2023
1 parent f3d29ff commit ed8ffb9
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 11 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
# This is a simple workflow that will build a .NET MAUI project, specifically targeting the android platform.
# It's meant for continuous integration, so running tests and making sure it all builds without failure.

name: GainsTracker Native

on:
push:
branches: [ "main", "workflow/actions" ]
branches: [ "main" ]
pull_request:
branches: [ "main", "workflow/actions" ]
branches: [ "main" ]

permissions:
contents: read
Expand All @@ -17,6 +17,7 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Disable the .NET first time experience
DOTNET_CLI_TELEMETRY_OPTOUT: true # Disable sending .NET CLI telemetry

# This should be updated in the future to include actual signing and publishing for each platform.
jobs:
build:
runs-on: windows-latest
Expand Down
6 changes: 3 additions & 3 deletions GainsTracker.ClientNative/GainsTracker.ClientNative.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks>net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
<OutputType Condition="'$(TargetFramework)' != 'net7.0'">Exe</OutputType>
<RootNamespace>GainsTracker.ClientNative</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
Expand Down
9 changes: 9 additions & 0 deletions GainsTracker.Testing.ClientNative/BuildTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GainsTracker.Testing.ClientNative;

public class BuildTest
{
[Fact]
public void Build()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions GainsTracker.Testing.ClientNative/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
9 changes: 9 additions & 0 deletions GainsTracker.Testing.CoreAPI/BuildTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GainsTracker.Testing.CoreAPI;

public class BuildTest
{
[Fact]
public void Build()
{
}
}
25 changes: 25 additions & 0 deletions GainsTracker.Testing.CoreAPI/GainsTracker.Testing.CoreAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions GainsTracker.Testing.CoreAPI/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
30 changes: 30 additions & 0 deletions GainsTracker.Testing.UI/GainsTracker.Testing.UI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.19.14" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GainsTracker.UI\GainsTracker.UI.csproj" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions GainsTracker.Testing.UI/MainLayoutTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Bunit;
using GainsTracker.UI.Shared;

namespace GainsTracker.Testing.UI;

public class MainLayoutTest : TestContext
{
public MainLayoutTest()
{
JSInterop.SetupVoid("toggleThemeStyleSheet", _ => true);
}

[Fact]
public void Build()
{
}

[Fact]
public void DarkModeToggleShouldSwitchProperty()
{
var cut = RenderComponent<MainLayout>(parameters =>
parameters.Add(p => p.IsDark, true));

Assert.True(cut.Instance.IsDark);

cut.Find("#toggleThemeButton").Click();

Assert.False(cut.Instance.IsDark);
}
}
1 change: 1 addition & 0 deletions GainsTracker.Testing.UI/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
9 changes: 5 additions & 4 deletions GainsTracker.UI/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@using GainsTracker.UI.Components
@inherits LayoutComponentBase
<ElementManipulator IsDarkTheme="_isDark"></ElementManipulator>
<ElementManipulator IsDarkTheme="IsDark"></ElementManipulator>

<div class="page">
<header class="navigation">
<NavMenu/>
</header>

<main>
<button @onclick="ToggleDarkMode">Toggle theme</button>
<button id="toggleThemeButton" @onclick="ToggleDarkMode">Toggle theme</button>

<article class="content">
@Body
Expand All @@ -17,11 +17,12 @@
</div>

@code {
bool _isDark;
[Parameter]
public bool IsDark { get; set; }

private void ToggleDarkMode()
{
_isDark = !_isDark;
IsDark = !IsDark;
}

}
18 changes: 18 additions & 0 deletions GainsTracker.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GainsTracker.ClientNative",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GainsTracker.Common", "GainsTracker.Common\GainsTracker.Common.csproj", "{412D30DA-7B16-4D3C-8ED0-DFF544305178}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GainsTracker.Testing.ClientNative", "GainsTracker.Testing.ClientNative\GainsTracker.Testing.ClientNative.csproj", "{3CCA4E21-F530-49A0-8EA0-17EB43D901E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GainsTracker.Testing.CoreAPI", "GainsTracker.Testing.CoreAPI\GainsTracker.Testing.CoreAPI.csproj", "{5196C9DD-7FFE-4729-8A63-7BC7046A907C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GainsTracker.Testing.UI", "GainsTracker.Testing.UI\GainsTracker.Testing.UI.csproj", "{75BFFEC2-C80D-43D0-8FD4-FAEDA0FF4F9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,5 +36,17 @@ Global
{412D30DA-7B16-4D3C-8ED0-DFF544305178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{412D30DA-7B16-4D3C-8ED0-DFF544305178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{412D30DA-7B16-4D3C-8ED0-DFF544305178}.Release|Any CPU.Build.0 = Release|Any CPU
{3CCA4E21-F530-49A0-8EA0-17EB43D901E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CCA4E21-F530-49A0-8EA0-17EB43D901E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CCA4E21-F530-49A0-8EA0-17EB43D901E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CCA4E21-F530-49A0-8EA0-17EB43D901E1}.Release|Any CPU.Build.0 = Release|Any CPU
{5196C9DD-7FFE-4729-8A63-7BC7046A907C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5196C9DD-7FFE-4729-8A63-7BC7046A907C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5196C9DD-7FFE-4729-8A63-7BC7046A907C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5196C9DD-7FFE-4729-8A63-7BC7046A907C}.Release|Any CPU.Build.0 = Release|Any CPU
{75BFFEC2-C80D-43D0-8FD4-FAEDA0FF4F9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75BFFEC2-C80D-43D0-8FD4-FAEDA0FF4F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75BFFEC2-C80D-43D0-8FD4-FAEDA0FF4F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75BFFEC2-C80D-43D0-8FD4-FAEDA0FF4F9F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit ed8ffb9

Please sign in to comment.