Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted ClientApp.UnitTests from xUnit to MSTest #409

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
paths-ignore:
- '**.md'
- 'src/ClientApp/**'
- 'test/ClientApp.UnitTests/**'
- 'tests/ClientApp.UnitTests/**'
- '.github/workflows/pr-validation-maui.yml'
pull_request:
branches: [ main ]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-validation-maui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- '**'
paths:
- 'src/ClientApp/**'
- 'test/ClientApp.UnitTests/**'
- 'tests/ClientApp.UnitTests/**'
- '.github/workflows/pr-validation-maui.yml'
push:
branches:
- main
paths:
- 'src/ClientApp/**'
- 'test/ClientApp.UnitTests/**'
- 'tests/ClientApp.UnitTests/**'
- '.github/workflows/pr-validation-maui.yml'

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ on:
paths-ignore:
- '**.md'
- 'src/ClientApp/**'
- 'test/ClientApp.UnitTests/**'
- 'tests/ClientApp.UnitTests/**'
- '.github/workflows/pr-validation-maui.yml'
push:
branches:
- main
paths-ignore:
- '**.md'
- 'src/ClientApp/**'
- 'test/ClientApp.UnitTests/**'
- 'tests/ClientApp.UnitTests/**'
- '.github/workflows/pr-validation-maui.yml'

jobs:
Expand Down
11 changes: 4 additions & 7 deletions tests/ClientApp.UnitTests/ClientApp.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />

<PackageReference Include="xunit" Version="2.8.0" />

<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />

<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions tests/ClientApp.UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
global using Xunit;
global using eShop.ClientApp.Services;
global using eShop.ClientApp.Services;
global using eShop.ClientApp.Services.AppEnvironment;
global using eShop.ClientApp.Services.Basket;
global using eShop.ClientApp.Services.Catalog;
global using eShop.ClientApp.Services.Order;
global using eShop.ClientApp.Services.Settings;
global using eShop.ClientApp.ViewModels;
global using Microsoft.VisualStudio.TestTools.UnitTesting;
5 changes: 3 additions & 2 deletions tests/ClientApp.UnitTests/Services/BasketServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
namespace ClientApp.UnitTests.Services;

[TestClass]
public class BasketServiceTests
{
[Fact]
[TestMethod]
public async Task GetFakeBasketTest()
{
var catalogMockService = new CatalogMockService();
var result = await catalogMockService.GetCatalogAsync();
Assert.NotEmpty(result);
Assert.AreNotEqual(result.Count(), 0);
}
}
13 changes: 7 additions & 6 deletions tests/ClientApp.UnitTests/Services/CatalogServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
namespace ClientApp.UnitTests.Services;

[TestClass]
public class CatalogServiceTests
{
[Fact]
[TestMethod]
public async Task GetFakeCatalogTest()
{
var catalogMockService = new CatalogMockService();
var catalog = await catalogMockService.GetCatalogAsync();

Assert.NotEmpty(catalog);
Assert.AreNotEqual(catalog.Count(), 0);
}

[Fact]
[TestMethod]
public async Task GetFakeCatalogBrandTest()
{
var catalogMockService = new CatalogMockService();
var catalogBrand = await catalogMockService.GetCatalogBrandAsync();

Assert.NotEmpty(catalogBrand);
Assert.AreNotEqual(catalogBrand.Count(), 0);
}

[Fact]
[TestMethod]
public async Task GetFakeCatalogTypeTest()
{
var catalogMockService = new CatalogMockService();
var catalogType = await catalogMockService.GetCatalogTypeAsync();

Assert.NotEmpty(catalogType);
Assert.AreNotEqual(catalogType.Count(), 0);
}
}
11 changes: 6 additions & 5 deletions tests/ClientApp.UnitTests/Services/OrdersServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using ClientApp.UnitTests.Mocks;
using ClientApp.UnitTests.Mocks;

namespace ClientApp.UnitTests.Services;

[TestClass]
public class OrdersServiceTests
{
private readonly ISettingsService _settingsService;
Expand All @@ -11,21 +12,21 @@ public OrdersServiceTests()
_settingsService = new MockSettingsService();
}

[Fact]
[TestMethod]
public async Task GetFakeOrderTest()
{
var ordersMockService = new OrderMockService();
var order = await ordersMockService.GetOrderAsync(1);

Assert.NotNull(order);
Assert.IsNotNull(order);
}

[Fact]
[TestMethod]
public async Task GetFakeOrdersTest()
{
var ordersMockService = new OrderMockService();
var result = await ordersMockService.GetOrdersAsync();

Assert.NotEmpty(result);
Assert.AreNotEqual(result.Count(), 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace ClientApp.UnitTests.ViewModels;

[TestClass]
public class CatalogItemViewModelTests
{
private readonly INavigationService _navigationService;
Expand All @@ -29,14 +30,14 @@ public CatalogItemViewModelTests()
_appEnvironmentService.UpdateDependencies(true);
}

[Fact]
[TestMethod]
public void AddCatalogItemCommandIsNotNullTest()
{
var CatalogItemViewModel = new CatalogItemViewModel(_appEnvironmentService, _navigationService);
Assert.NotNull(CatalogItemViewModel.AddCatalogItemCommand);
Assert.IsNotNull(CatalogItemViewModel.AddCatalogItemCommand);
}

[Fact]
[TestMethod]
public async Task AddCatalogItemCommandSendsAddProductMessageTest()
{
bool messageReceived = false;
Expand All @@ -55,7 +56,7 @@ public async Task AddCatalogItemCommandSendsAddProductMessageTest()

await catalogItemViewModel.AddCatalogItemCommand.ExecuteUntilComplete();

Assert.True(messageReceived);
Assert.IsTrue(messageReceived);
}

}
59 changes: 30 additions & 29 deletions tests/ClientApp.UnitTests/ViewModels/CatalogViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using ClientApp.UnitTests.Mocks;
using ClientApp.UnitTests.Mocks;
using eShop.ClientApp.Services.Identity;

namespace ClientApp.UnitTests.ViewModels;

[TestClass]
public class CatalogViewModelTests
{
private readonly INavigationService _navigationService;
Expand All @@ -27,93 +28,93 @@ public CatalogViewModelTests()
_appEnvironmentService.UpdateDependencies(true);
}

[Fact]
[TestMethod]
public void FilterCommandIsNotNullTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.NotNull(catalogViewModel.FilterCommand);
Assert.IsNotNull(catalogViewModel.FilterCommand);
}

[Fact]
[TestMethod]
public void ClearFilterCommandIsNotNullTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.NotNull(catalogViewModel.ClearFilterCommand);
Assert.IsNotNull(catalogViewModel.ClearFilterCommand);
}

[Fact]
[TestMethod]
public void ProductsPropertyIsEmptyWhenViewModelInstantiatedTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.Empty(catalogViewModel.Products);
Assert.AreEqual(catalogViewModel.Products.Count,0);
}

[Fact]
[TestMethod]
public void BrandsPropertyIsEmptyWhenViewModelInstantiatedTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.Empty(catalogViewModel.Brands);
Assert.AreEqual(catalogViewModel.Brands.Count, 0);
}

[Fact]
[TestMethod]
public void BrandPropertyIsNullWhenViewModelInstantiatedTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.Null(catalogViewModel.SelectedBrand);
Assert.IsNull(catalogViewModel.SelectedBrand);
}

[Fact]
[TestMethod]
public void TypesPropertyIsEmptyWhenViewModelInstantiatedTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.Empty(catalogViewModel.Types);
Assert.AreEqual(catalogViewModel.Types.Count, 0);
}

[Fact]
[TestMethod]
public void TypePropertyIsNullWhenViewModelInstantiatedTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.Null(catalogViewModel.SelectedType);
Assert.IsNull(catalogViewModel.SelectedType);
}

[Fact]
[TestMethod]
public void IsFilterPropertyIsFalseWhenViewModelInstantiatedTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);
Assert.False(catalogViewModel.IsFiltering);
Assert.IsFalse(catalogViewModel.IsFiltering);
}

[Fact]
[TestMethod]
public async Task ProductsPropertyIsNotNullAfterViewModelInitializationTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);

await catalogViewModel.InitializeAsync();

Assert.NotNull(catalogViewModel.Products);
Assert.IsNotNull(catalogViewModel.Products);
}

[Fact]
[TestMethod]
public async Task BrandsPropertyIsNotNullAfterViewModelInitializationTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);

await catalogViewModel.InitializeAsync();

Assert.NotNull(catalogViewModel.Brands);
Assert.IsNotNull(catalogViewModel.Brands);
}

[Fact]
[TestMethod]
public async Task TypesPropertyIsNotNullAfterViewModelInitializationTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);

await catalogViewModel.InitializeAsync();

Assert.NotNull(catalogViewModel.Types);
Assert.IsNotNull(catalogViewModel.Types);
}

[Fact]
[TestMethod]
public async Task SettingBadgeCountPropertyShouldRaisePropertyChanged()
{
bool invoked = false;
Expand All @@ -129,19 +130,19 @@ public async Task SettingBadgeCountPropertyShouldRaisePropertyChanged()
};
await catalogViewModel.InitializeAsync();

Assert.True(invoked);
Assert.IsTrue(invoked);
}

[Fact]
[TestMethod]
public async Task ClearFilterCommandResetsPropertiesTest()
{
var catalogViewModel = new CatalogViewModel(_appEnvironmentService, _navigationService);

await catalogViewModel.InitializeAsync();
await catalogViewModel.ClearFilterCommand.ExecuteUntilComplete(null);

Assert.Null(catalogViewModel.SelectedBrand);
Assert.Null(catalogViewModel.SelectedType);
Assert.NotNull(catalogViewModel.Products);
Assert.IsNull(catalogViewModel.SelectedBrand);
Assert.IsNull(catalogViewModel.SelectedType);
Assert.IsNotNull(catalogViewModel.Products);
}
}
9 changes: 5 additions & 4 deletions tests/ClientApp.UnitTests/ViewModels/MainViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ClientApp.UnitTests.ViewModels;

[TestClass]
public class MainViewModelTests
{
private readonly INavigationService _navigationService;
Expand All @@ -11,17 +12,17 @@ public MainViewModelTests()
_navigationService = new MockNavigationService();
}

[Fact]
[TestMethod]
public void SettingsCommandIsNotNullWhenViewModelInstantiatedTest()
{
var mainViewModel = new MainViewModel(_navigationService);
Assert.NotNull(mainViewModel.SettingsCommand);
Assert.IsNotNull(mainViewModel.SettingsCommand);
}

[Fact]
[TestMethod]
public void IsBusyPropertyIsFalseWhenViewModelInstantiatedTest()
{
var mainViewModel = new MainViewModel(_navigationService);
Assert.False(mainViewModel.IsBusy);
Assert.IsFalse(mainViewModel.IsBusy);
}
}
Loading
Loading