Skip to content

Commit

Permalink
Replace Radzen with MudBlazor (#51)
Browse files Browse the repository at this point in the history
* DO PACKAGE UPGRADE
* migrate person view to MudBlazor
* migrate edit and listing person
* fix residence selector
* migrate person listing
* add contract page
* show tax calculation results
* remove Radzen completely
---------

Co-authored-by: Dieter Niggeler <dieter.niggeler@swisslife.ch>
  • Loading branch information
dniggeler and dniggeler committed Jul 2, 2023
1 parent b04b54a commit 35493e2
Show file tree
Hide file tree
Showing 131 changed files with 4,253 additions and 23,230 deletions.
28 changes: 28 additions & 0 deletions src/BlazorApp.Components.Tests/BlazorApp.Components.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage.TestExtensions" Version="4.3.0" />
<PackageReference Include="bunit" Version="1.20.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<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="..\BlazorApp\BlazorApp.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions src/BlazorApp.Components.Tests/BrowserStorageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Blazored.LocalStorage;
using Bunit;

namespace BlazorApp.Components.Tests
{
public class BrowserStorageTests : TestContext
{
private readonly ILocalStorageService localStorageService;

public BrowserStorageTests()
{
localStorageService = this.AddBlazoredLocalStorage();
}

[Fact]
public async Task Successfully_Use_LocalStorage()
{
// given
string key = "name";
Guid expectedValue = Guid.NewGuid();

// when
await localStorageService.ClearAsync();
await localStorageService.SetItemAsync(key, expectedValue);
Guid result = await localStorageService.GetItemAsync<Guid>(key);

// then
Assert.True(result == expectedValue);
}
}
}
98 changes: 98 additions & 0 deletions src/BlazorApp.Components.Tests/PersonServiceMockTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using BlazorApp.Services;
using BlazorApp.ViewModels;
using Bunit;
using PensionCoach.Tools.CommonTypes;

namespace BlazorApp.Components.Tests;

public class PersonServiceMockTests : TestContext
{
public PersonServiceMockTests()
{
this.AddBlazoredLocalStorage();
Services.AddMockServices();
}

[Fact(DisplayName = "Add New Person")]
public async Task Add_New_Person()
{
// given
Guid newId = Guid.NewGuid();

// when
IPersonService personService = Services.GetService<IPersonService>();

PersonViewModel result = await AddNewPersonAsync(personService, newId);

// then
Assert.True(result is not null);
}

[Fact(DisplayName = "Delete Person")]
public async Task Delete_Person()
{
// given
Guid newId = Guid.NewGuid();

// when
IPersonService personService = Services.GetService<IPersonService>();

await AddNewPersonAsync(personService, newId);

await personService.DeletePersonAsync(newId);

var result = await personService.GetAsync(newId);

// then
Assert.True(result is null);
}

[Fact(DisplayName = "Edit and Save Person")]
public async Task Edit_And_Save_Person()
{
// given
Guid newId = Guid.NewGuid();
DateTime birthday = new DateTime(1966, 2, 10);

// when
IPersonService personService = Services.GetService<IPersonService>();

PersonViewModel newPerson = await AddNewPersonAsync(personService, newId);
newPerson.DateOfBirth = birthday;
await personService.UpdateAsync(newPerson);

PersonViewModel result = await personService.GetAsync(newId);

// then
Assert.True(result.DateOfBirth == birthday);
}

private async Task<PersonViewModel> AddNewPersonAsync(IPersonService personService, Guid id)
{
PersonViewModel newPerson = CreatePerson(id);
await personService.AddAsync(newPerson);

return await personService.GetAsync(id);
}

private PersonViewModel CreatePerson(Guid id)
{
return new PersonViewModel
{
Id = id,
Name = "Tester 1",
DateOfBirth = new DateTime(1990, 11, 11),
Gender = Gender.Male,
CivilStatus = CivilStatus.Single,
BfsMunicipalityId = 136,
Canton = Canton.ZH,
MunicipalityName = "Langnau aA",
NumberOfChildren = 0,
ReligiousGroupType = ReligiousGroupType.Protestant,
TaxableIncome = 100_000,
TaxableWealth = 500_000,
FinalCapital3a = 150_000,
FinalRetirementCapital = 500_000
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using BlazorApp.Services;
using BlazorApp.ViewModels;
using Bunit;
using PensionCoach.Tools.CommonTypes;

namespace BlazorApp.Components.Tests;

public class PersonServiceWithBrowserStorageTests : TestContext
{
public PersonServiceWithBrowserStorageTests()
{
this.AddBlazoredLocalStorage(null);
Services.AddServices();
}

[Fact(DisplayName = "Add New Person")]
public async Task Add_New_Person()
{
// given
Guid newId = Guid.NewGuid();

// when
IPersonService personService = Services.GetService<IPersonService>();

PersonViewModel result = await AddNewPersonAsync(personService, newId);

// then
Assert.True(result is not null);
}

[Fact(DisplayName = "Delete Person")]
public async Task Delete_Person()
{
// given
Guid newId = Guid.NewGuid();

// when
IPersonService personService = Services.GetService<IPersonService>();

await AddNewPersonAsync(personService, newId);

await personService.DeletePersonAsync(newId);

var result = await personService.GetAsync(newId);

// then
Assert.True(result is null);
}

[Fact(DisplayName = "Edit and Save Person")]
public async Task Edit_And_Save_Person()
{
// given
Guid newId = Guid.NewGuid();
DateTime birthday = new DateTime(1966, 2, 10);

// when
IPersonService personService = Services.GetService<IPersonService>();

PersonViewModel newPerson = await AddNewPersonAsync(personService, newId);
newPerson.DateOfBirth = birthday;
await personService.UpdateAsync(newPerson);

PersonViewModel result = await personService.GetAsync(newId);

// then
Assert.True(result.DateOfBirth == birthday);
}

private async Task<PersonViewModel> AddNewPersonAsync(IPersonService personService, Guid id)
{
PersonViewModel newPerson = CreatePerson(id);
await personService.AddAsync(newPerson);

return await personService.GetAsync(id);
}

private PersonViewModel CreatePerson(Guid id)
{
return new PersonViewModel
{
Id = id,
Name = "Tester 1",
DateOfBirth = new DateTime(1990, 11, 11),
Gender = Gender.Male,
CivilStatus = CivilStatus.Single,
BfsMunicipalityId = 136,
Canton = Canton.ZH,
MunicipalityName = "Langnau aA",
NumberOfChildren = 0,
ReligiousGroupType = ReligiousGroupType.Protestant,
TaxableIncome = 100_000,
TaxableWealth = 500_000,
FinalCapital3a = 150_000,
FinalRetirementCapital = 500_000
};
}
}
1 change: 1 addition & 0 deletions src/BlazorApp.Components.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
8 changes: 4 additions & 4 deletions src/BlazorApp.Services.Tests/BlazorApp.Services.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand All @@ -8,14 +8,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Snapshooter.Xunit" Version="0.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Snapshooter.Xunit" Version="0.13.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.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorApp/App.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayoutRadzen)" />
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainPensionToolsLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayoutRadzen)">
<LayoutView Layout="@typeof(MainPensionToolsLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
Expand Down
19 changes: 14 additions & 5 deletions src/BlazorApp/BlazorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Blazor-ApexCharts" Version="0.9.21-beta" />
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
<PackageReference Include="Radzen.Blazor" Version="4.3.6" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
<PackageReference Include="MudBlazor" Version="6.6.0" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -59,4 +60,12 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<UpToDateCheckInput Remove="MyComponents\JsonPrettyFormat.razor" />
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="MyComponents\JsonPrettyFormat.razor" />
</ItemGroup>

</Project>
48 changes: 48 additions & 0 deletions src/BlazorApp/MyComponents/CantonSelector.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@using PensionCoach.Tools.CommonTypes
@using PensionCoach.Tools.CommonTypes.Tax

<MudSelect T="Canton" Label="@Label" ReadOnly="@IsReadOnly" Value="@CantonCode" ValueChanged="HandleCantonChange">
@foreach (var m in cantons)
{
<MudSelectItem Value="m.Canton">@m.Name</MudSelectItem>
}
</MudSelect>


@code {

internal record CantonHolder
{
public Canton Canton { get; init; }
public string Name { get; init; }
}

[Parameter]
public bool IsReadOnly { get; set; }

[Parameter]
public string Label { get; set; }

[Parameter]
public Canton CantonCode { get; set; }

[Parameter]
public EventCallback<Canton> OnSelected { get; set; }

private List<CantonHolder> cantons = new();

protected override void OnInitialized()
{
cantons = Enum.GetValues(typeof(Canton))
.Cast<Canton>()
.Select(c => new CantonHolder { Canton = c, Name = c.ToString() })
.ToList();
}

private async Task HandleCantonChange(Canton value)
{
CantonCode = value;

await OnSelected.InvokeAsync(CantonCode);
}
}
Loading

0 comments on commit 35493e2

Please sign in to comment.