-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for ImportLocationsViewModel, MenuViewModel and Sett…
…ingsViewModel
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/App/UnitTest/ViewModels/ImportLocationsViewModelTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using WhereToFly.App.Core.ViewModels; | ||
|
||
namespace WhereToFly.App.UnitTest.ViewModels | ||
{ | ||
/// <summary> | ||
/// Unit tests for class ImportLocationsViewModel | ||
/// </summary> | ||
[TestClass] | ||
public class ImportLocationsViewModelTest | ||
{ | ||
/// <summary> | ||
/// Tests default ctor of view model | ||
/// </summary> | ||
[TestMethod] | ||
public void TestDefaultCtor() | ||
{ | ||
// run | ||
var viewModel = new ImportLocationsViewModel(); | ||
|
||
// check | ||
Assert.IsNotNull(viewModel.ImportIncludedCommand, "import included command must be non-null"); | ||
Assert.IsNotNull(viewModel.ImportFromStorageCommand, "import from storage command must be non-null"); | ||
Assert.IsNotNull(viewModel.DownloadFromWebCommand, "download from web command must be non-null"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Linq; | ||
using WhereToFly.App.Core; | ||
using WhereToFly.App.Core.ViewModels; | ||
using Xamarin.Forms; | ||
|
||
namespace WhereToFly.App.UnitTest.ViewModels | ||
{ | ||
/// <summary> | ||
/// Unit tests for class MenuViewModel | ||
/// </summary> | ||
[TestClass] | ||
public class MenuViewModelTest | ||
{ | ||
/// <summary> | ||
/// Sets up tests by initializing Xamarin.Forms.Mocks and DependencyService with | ||
/// DataService. | ||
/// </summary> | ||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
Xamarin.Forms.Mocks.MockForms.Init(); | ||
DependencyService.Register<IPlatform, UnitTestPlatform>(); | ||
DependencyService.Register<SvgImageCache>(); | ||
|
||
var imageCache = DependencyService.Get<SvgImageCache>(); | ||
imageCache.AddImage("icons/map.svg", string.Empty); | ||
imageCache.AddImage("icons/format-list-bulleted.svg", string.Empty); | ||
imageCache.AddImage("icons/compass.svg", string.Empty); | ||
imageCache.AddImage("icons/weather-partlycloudy.svg", string.Empty); | ||
imageCache.AddImage("icons/settings.svg", string.Empty); | ||
imageCache.AddImage("icons/information-outline.svg", string.Empty); | ||
} | ||
|
||
/// <summary> | ||
/// Tests default ctor of view model | ||
/// </summary> | ||
[TestMethod] | ||
public void TestDefaultCtor() | ||
{ | ||
// run | ||
var viewModel = new MenuViewModel(); | ||
|
||
// check | ||
Assert.IsTrue(viewModel.MenuItemList.Any(), "menu item list must contain items"); | ||
|
||
foreach (var menuItem in viewModel.MenuItemList) | ||
{ | ||
var imageSource = menuItem.ImageSource; | ||
Assert.IsNotNull(imageSource, "image source must not be null"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using WhereToFly.App.Core.ViewModels; | ||
using WhereToFly.App.Model; | ||
|
||
namespace WhereToFly.App.UnitTest.ViewModels | ||
{ | ||
/// <summary> | ||
/// Unit tests for class SettingsViewModel | ||
/// </summary> | ||
[TestClass] | ||
public class SettingsViewModelTest | ||
{ | ||
/// <summary> | ||
/// Sets up tests by initializing app settings object | ||
/// </summary> | ||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
Core.App.Settings = new AppSettings(); | ||
} | ||
|
||
/// <summary> | ||
/// Tests default ctor of view model | ||
/// </summary> | ||
[TestMethod] | ||
public void TestDefaultCtor() | ||
{ | ||
// run | ||
var viewModel = new SettingsViewModel(); | ||
|
||
Debug.WriteLine($"SelectedMapImageryType = {viewModel.SelectedMapImageryType}"); | ||
Debug.WriteLine($"SelectedMapOverlayType = {viewModel.SelectedMapOverlayType}"); | ||
Debug.WriteLine($"SelectedMapShadingModeItem = {viewModel.SelectedMapShadingModeItem}"); | ||
Debug.WriteLine($"SelectedCoordinateDisplayFormatItem = {viewModel.SelectedCoordinateDisplayFormatItem}"); | ||
|
||
viewModel.SelectedMapImageryType = viewModel.MapImageryTypeItems.Last(); | ||
viewModel.SelectedMapOverlayType = viewModel.MapOverlayTypeItems.Last(); | ||
viewModel.SelectedMapShadingModeItem = viewModel.MapShadingModeItems.Last(); | ||
viewModel.SelectedCoordinateDisplayFormatItem = viewModel.CoordinateDisplayFormatItems.Last(); | ||
|
||
// check | ||
Assert.IsTrue(viewModel.MapImageryTypeItems.Any(), "map imagery type list must contain items"); | ||
Assert.IsTrue(viewModel.MapOverlayTypeItems.Any(), "map overlay type list must contain items"); | ||
Assert.IsTrue(viewModel.MapShadingModeItems.Any(), "map shading mode list must contain items"); | ||
Assert.IsTrue(viewModel.CoordinateDisplayFormatItems.Any(), "coordinate display format list must contain items"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters