Skip to content

Commit 21299bd

Browse files
committed
Add more Unit Tests
1 parent 3c34065 commit 21299bd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/Blazor/MyBlazorApp.Tests/Services/DashboardDataServiceTest.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using MyBlazorApp.Services;
3+
using MyBlazorApp.Models;
34
using System.Linq;
45
using System.Threading.Tasks;
6+
using System.Collections.Generic;
57
using Telerik.JustMock;
8+
using System;
69

710
namespace MyBlazorApp.Tests.Services;
811

@@ -68,4 +71,50 @@ public async Task TestRevenue()
6871

6972
Mock.Assert(revenue > 0);
7073
}
74+
75+
[TestMethod]
76+
public void PodcastViewModel_ViewsProperty_ReturnsSumOfDownloadsAndStreams()
77+
{
78+
var model = new PodcastViewModel { Downloads = 10, Streams = 15 };
79+
Assert.AreEqual(25, model.Views);
80+
}
81+
82+
[TestMethod]
83+
public async Task GetStreams_ReturnsCorrectSum()
84+
{
85+
var service = new DashboardDataService();
86+
var podcasts = await service.GetPodcasts();
87+
var expected = podcasts.Sum(p => p.Streams);
88+
var actual = await service.GetStreams();
89+
Assert.AreEqual(expected, actual);
90+
}
91+
92+
[TestMethod]
93+
public async Task GetPlatformData_GroupsByPlatformName()
94+
{
95+
var service = new DashboardDataService();
96+
var data = (await service.GetPlatformData(false)).ToList();
97+
Assert.IsTrue(data.Count > 0);
98+
Assert.IsFalse(string.IsNullOrEmpty(data[0].Category));
99+
}
100+
101+
[TestMethod]
102+
public async Task GetPodcasts_EmptyList_ReturnsEmpty()
103+
{
104+
// Arrange
105+
var emptyService = Mock.Create<IDashboardDataService>();
106+
Mock.Arrange(() => emptyService.GetPodcasts()).Returns(Task.FromResult<IEnumerable<PodcastViewModel>>(new List<PodcastViewModel>()));
107+
// Act
108+
var podcasts = await emptyService.GetPodcasts();
109+
// Assert
110+
Assert.IsFalse(podcasts.Any());
111+
}
112+
113+
[TestMethod]
114+
public void PlatformViewModel_PropertyAssignment_Works()
115+
{
116+
var model = new PlatformViewModel { Category = "Test", Views = 123 };
117+
Assert.AreEqual("Test", model.Category);
118+
Assert.AreEqual(123, model.Views);
119+
}
71120
}

0 commit comments

Comments
 (0)