diff --git a/.gitignore b/.gitignore
index 3e24293..66782cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@ Bullet6/bin/
Bullet6/obj/
BlazorApp.Shared/bin/
.vs/BlazorApp/
+BlazorApp.Tests/bin/
+BlazorApp.Tests/obj/
diff --git a/BlazorApp.Tests/BlazorApp.Tests.csproj b/BlazorApp.Tests/BlazorApp.Tests.csproj
new file mode 100644
index 0000000..1bbfbcf
--- /dev/null
+++ b/BlazorApp.Tests/BlazorApp.Tests.csproj
@@ -0,0 +1,29 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/BlazorApp.Tests/Controllers/CustomerControllerTests.cs b/BlazorApp.Tests/Controllers/CustomerControllerTests.cs
new file mode 100644
index 0000000..6419253
--- /dev/null
+++ b/BlazorApp.Tests/Controllers/CustomerControllerTests.cs
@@ -0,0 +1,104 @@
+using BlazorApp.Controllers;
+using BlazorApp.Interfaces.Services;
+using BlazorApp.Shared.Models;
+using BlazorApp.Shared.Models.Pagination;
+using Microsoft.AspNetCore.Mvc;
+using Moq;
+
+namespace BlazorApp.Tests.Controllers;
+
+public class CustomerControllerTests
+{
+ private readonly Mock _mockService;
+ private readonly CustomerController _controller;
+
+ public CustomerControllerTests()
+ {
+ _mockService = new Mock();
+ _controller = new CustomerController(_mockService.Object);
+ }
+
+ [Fact]
+ public async Task Query_OK()
+ {
+ var customers = new PaginatedResult
+ {
+ TotalCount = 1,
+ Results = new List() { new Customer { Id = "blabla", CompanyName = "blabla" } }
+ };
+ _mockService.Setup(s => s.Query(It.IsAny())).ReturnsAsync(customers);
+
+ var actionResult = await _controller.Query(new Shared.Queries.CustomerQuery());
+
+ var okResult = Assert.IsType(actionResult.Result);
+
+ var returnResult = Assert.IsType>(okResult.Value);
+
+ Assert.Single(returnResult.Results);
+ Assert.Equal(1, returnResult.TotalCount);
+ _mockService.Verify(s => s.Query(It.IsAny()), Times.Once);
+ }
+
+ [Fact]
+ public async Task Get_OK()
+ {
+ var customer = new Customer
+ {
+ Id = "blabla",
+ CompanyName = "blabla"
+ };
+ _mockService.Setup(s => s.Get(It.IsAny())).ReturnsAsync(customer);
+
+ var actionResult = await _controller.Get("blabla");
+
+ var okResult = Assert.IsType(actionResult.Result);
+
+ var returnResult = Assert.IsType(okResult.Value);
+
+ Assert.NotNull(returnResult);
+ _mockService.Verify(s => s.Get("blabla"), Times.Once);
+ }
+
+ [Fact]
+ public async Task Delete_ReturnsNoContent()
+ {
+ _mockService.Setup(s => s.Delete(It.IsAny())).Returns(Task.CompletedTask);
+
+ var actionResult = await _controller.Delete("blabla");
+
+ Assert.IsType(actionResult);
+ _mockService.Verify(s => s.Delete("blabla"), Times.Once);
+ }
+
+ [Fact]
+ public async Task Save_ReturnsNoContent()
+ {
+ var customer = new Customer
+ {
+ Id = "blabla",
+ CompanyName = "blabla"
+ };
+ _mockService.Setup(s => s.Save(It.IsAny())).Returns(Task.CompletedTask);
+
+ var actionResult = await _controller.Save(customer);
+
+ Assert.IsType(actionResult);
+ _mockService.Verify(s => s.Save(customer), Times.Once);
+ }
+
+ [Fact]
+ public async Task Update_ReturnsNoContent()
+ {
+ var customer = new Customer
+ {
+ Id = "blabla",
+ CompanyName = "blabla"
+ };
+ _mockService.Setup(s => s.Update(It.IsAny())).Returns(Task.CompletedTask);
+
+ var actionResult = await _controller.Update(customer);
+
+ Assert.IsType(actionResult);
+ _mockService.Verify(s => s.Update(customer), Times.Once);
+ }
+}
\ No newline at end of file
diff --git a/BlazorApp.sln b/BlazorApp.sln
index fbc8fd3..16bdd33 100644
--- a/BlazorApp.sln
+++ b/BlazorApp.sln
@@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp.Client", "BlazorA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp.Shared", "BlazorApp.Shared\BlazorApp.Shared.csproj", "{C6627F01-4882-40B1-890C-D70AA74B9BD1}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bullet6", "Bullet6\Bullet6.csproj", "{8FA67E47-DDAB-4712-B628-F904086B1F77}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bullet6", "Bullet6\Bullet6.csproj", "{8FA67E47-DDAB-4712-B628-F904086B1F77}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp.Tests", "BlazorApp.Tests\BlazorApp.Tests.csproj", "{80656871-78E1-49BF-8935-34F42BDCF6A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,6 +35,10 @@ Global
{8FA67E47-DDAB-4712-B628-F904086B1F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FA67E47-DDAB-4712-B628-F904086B1F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FA67E47-DDAB-4712-B628-F904086B1F77}.Release|Any CPU.Build.0 = Release|Any CPU
+ {80656871-78E1-49BF-8935-34F42BDCF6A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {80656871-78E1-49BF-8935-34F42BDCF6A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {80656871-78E1-49BF-8935-34F42BDCF6A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {80656871-78E1-49BF-8935-34F42BDCF6A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/BlazorApp/Components/Pages/Weather.razor b/BlazorApp/Components/Pages/Weather.razor
index 94c2a88..f210f7b 100644
--- a/BlazorApp/Components/Pages/Weather.razor
+++ b/BlazorApp/Components/Pages/Weather.razor
@@ -44,7 +44,6 @@ else
protected override async Task OnInitializedAsync()
{
- // Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(500);
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
}
diff --git a/BlazorApp/Program.cs b/BlazorApp/Program.cs
index 8bf2a4a..b436c9d 100644
--- a/BlazorApp/Program.cs
+++ b/BlazorApp/Program.cs
@@ -12,7 +12,6 @@ using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
-// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
@@ -43,7 +42,6 @@ var app = builder.Build();
app.ExecuteDbMigration();
-// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
@@ -51,7 +49,6 @@ if (app.Environment.IsDevelopment())
else
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
- // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}