View model unit tests added.
This commit is contained in:
parent
7d3a0db546
commit
40dddbaa3f
@ -31,7 +31,7 @@ namespace eShopOnContainers.Core.Behaviors
|
|||||||
BindableProperty.CreateAttached("EventArgsConverterParameter", typeof(object), typeof(EventToCommandBehavior), null,
|
BindableProperty.CreateAttached("EventArgsConverterParameter", typeof(object), typeof(EventToCommandBehavior), null,
|
||||||
BindingMode.OneWay);
|
BindingMode.OneWay);
|
||||||
|
|
||||||
private Delegate _handler;
|
protected Delegate _handler;
|
||||||
private EventInfo _eventInfo;
|
private EventInfo _eventInfo;
|
||||||
|
|
||||||
public string EventName
|
public string EventName
|
||||||
|
@ -14,7 +14,7 @@ namespace eShopOnContainers.TestRunner.Droid
|
|||||||
AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);
|
AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);
|
||||||
|
|
||||||
// or in any reference assemblies getting the Assembly from any type/class
|
// or in any reference assemblies getting the Assembly from any type/class
|
||||||
AddTestAssembly(typeof(UnitTests.DummyTests).Assembly);
|
AddTestAssembly(typeof(UnitTests.CatalogViewModelTests).Assembly);
|
||||||
|
|
||||||
base.OnCreate(bundle);
|
base.OnCreate(bundle);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||||
<NuGetPackageImportStamp>
|
<NuGetPackageImportStamp>
|
||||||
</NuGetPackageImportStamp>
|
</NuGetPackageImportStamp>
|
||||||
|
<AndroidTlsProvider></AndroidTlsProvider>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@ -17,7 +17,7 @@ namespace eShopOnContainers.TestRunner.iOS
|
|||||||
|
|
||||||
// Otherwise you need to ensure that the test assemblies will
|
// Otherwise you need to ensure that the test assemblies will
|
||||||
// become part of the app bundle
|
// become part of the app bundle
|
||||||
AddTestAssembly(typeof(UnitTests.DummyTests).Assembly);
|
AddTestAssembly(typeof(UnitTests.CatalogViewModelTests).Assembly);
|
||||||
|
|
||||||
return base.FinishedLaunching(app, options);
|
return base.FinishedLaunching(app, options);
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,12 @@
|
|||||||
<HintPath>..\..\..\..\packages\xunit.runner.utility.2.2.0-beta4-build3444\lib\netstandard1.1\xunit.runner.utility.dotnet.dll</HintPath>
|
<HintPath>..\..\..\..\packages\xunit.runner.utility.2.2.0-beta4-build3444\lib\netstandard1.1\xunit.runner.utility.dotnet.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Plugin.Settings.Abstractions">
|
||||||
|
<HintPath>..\..\..\..\packages\Xam.Plugins.Settings.2.6.0.12-beta\lib\Xamarin.iOS10\Plugin.Settings.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Plugin.Settings">
|
||||||
|
<HintPath>..\..\..\..\packages\Xam.Plugins.Settings.2.6.0.12-beta\lib\Xamarin.iOS10\Plugin.Settings.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="AppDelegate.cs.txt" />
|
<Content Include="AppDelegate.cs.txt" />
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="CommonServiceLocator" version="1.3" targetFramework="xamarinios10" />
|
<package id="CommonServiceLocator" version="1.3" targetFramework="xamarinios10" />
|
||||||
|
<package id="Xam.Plugins.Settings" version="2.6.0.12-beta" targetFramework="xamarinios10" />
|
||||||
<package id="Xamarin.Forms" version="2.3.3.175" targetFramework="xamarinios10" />
|
<package id="Xamarin.Forms" version="2.3.3.175" targetFramework="xamarinios10" />
|
||||||
<package id="xunit" version="2.2.0-beta4-build3444" targetFramework="xamarinios10" />
|
<package id="xunit" version="2.2.0-beta4-build3444" targetFramework="xamarinios10" />
|
||||||
<package id="xunit.abstractions" version="2.0.1" targetFramework="xamarinios10" />
|
<package id="xunit.abstractions" version="2.0.1" targetFramework="xamarinios10" />
|
||||||
|
@ -0,0 +1,120 @@
|
|||||||
|
using Xunit;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace eShopOnContainers.UnitTests
|
||||||
|
{
|
||||||
|
public class EventToCommandBehaviorTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void InvalidEventNameShouldThrowArgumentExceptionText()
|
||||||
|
{
|
||||||
|
var behavior = new MockEventToCommandBehavior
|
||||||
|
{
|
||||||
|
EventName = "OnItemTapped"
|
||||||
|
};
|
||||||
|
var listView = new ListView();
|
||||||
|
|
||||||
|
Assert.Throws<ArgumentException>(() => listView.Behaviors.Add(behavior));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CommandExecutedWhenEventFiresText()
|
||||||
|
{
|
||||||
|
bool executedCommand = false;
|
||||||
|
var behavior = new MockEventToCommandBehavior
|
||||||
|
{
|
||||||
|
EventName = "ItemTapped",
|
||||||
|
Command = new Command(() =>
|
||||||
|
{
|
||||||
|
executedCommand = true;
|
||||||
|
})
|
||||||
|
};
|
||||||
|
var listView = new ListView();
|
||||||
|
listView.Behaviors.Add(behavior);
|
||||||
|
|
||||||
|
behavior.RaiseEvent(listView, null);
|
||||||
|
|
||||||
|
Assert.True(executedCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CommandCanExecuteTest()
|
||||||
|
{
|
||||||
|
var behavior = new MockEventToCommandBehavior
|
||||||
|
{
|
||||||
|
EventName = "ItemTapped",
|
||||||
|
Command = new Command(() => Assert.True(false), () => false)
|
||||||
|
};
|
||||||
|
var listView = new ListView();
|
||||||
|
listView.Behaviors.Add(behavior);
|
||||||
|
|
||||||
|
behavior.RaiseEvent(listView, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CommandCanExecuteWithParameterShouldNotExecuteTest()
|
||||||
|
{
|
||||||
|
bool shouldExecute = false;
|
||||||
|
var behavior = new MockEventToCommandBehavior
|
||||||
|
{
|
||||||
|
EventName = "ItemTapped",
|
||||||
|
CommandParameter = shouldExecute,
|
||||||
|
Command = new Command<string>(o => Assert.True(false), o => o.Equals(true))
|
||||||
|
};
|
||||||
|
var listView = new ListView();
|
||||||
|
listView.Behaviors.Add(behavior);
|
||||||
|
|
||||||
|
behavior.RaiseEvent(listView, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CommandWithConverterTest()
|
||||||
|
{
|
||||||
|
const string item = "ItemProperty";
|
||||||
|
bool executedCommand = false;
|
||||||
|
var behavior = new MockEventToCommandBehavior
|
||||||
|
{
|
||||||
|
EventName = "ItemTapped",
|
||||||
|
EventArgsConverter = new ItemTappedEventArgsConverter(false),
|
||||||
|
Command = new Command<string>(o =>
|
||||||
|
{
|
||||||
|
executedCommand = true;
|
||||||
|
Assert.NotNull(o);
|
||||||
|
Assert.Equal(item, o);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
var listView = new ListView();
|
||||||
|
listView.Behaviors.Add(behavior);
|
||||||
|
|
||||||
|
behavior.RaiseEvent(listView, new ItemTappedEventArgs(listView, item));
|
||||||
|
|
||||||
|
Assert.True(executedCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ItemTappedEventArgsConverter : IValueConverter
|
||||||
|
{
|
||||||
|
private readonly bool _returnParameter;
|
||||||
|
|
||||||
|
public bool HasConverted { get; private set; }
|
||||||
|
|
||||||
|
public ItemTappedEventArgsConverter(bool returnParameter)
|
||||||
|
{
|
||||||
|
_returnParameter = returnParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
HasConverted = true;
|
||||||
|
return _returnParameter ? parameter : (value as ItemTappedEventArgs)?.Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace eShopOnContainers.UnitTests
|
|
||||||
{
|
|
||||||
public class DummyTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void ThisShouldPass_Sync()
|
|
||||||
{
|
|
||||||
Assert.True(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ThisShouldPass_Async()
|
|
||||||
{
|
|
||||||
await Task.Run(() => { Assert.True(true); });
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ThisShouldFail_Async()
|
|
||||||
{
|
|
||||||
await Task.Run(() => { throw new Exception("Oops!"); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
using eShopOnContainers.Core.Behaviors;
|
||||||
|
|
||||||
|
namespace eShopOnContainers.UnitTests
|
||||||
|
{
|
||||||
|
public class MockEventToCommandBehavior : EventToCommandBehavior
|
||||||
|
{
|
||||||
|
public void RaiseEvent(params object[] args)
|
||||||
|
{
|
||||||
|
_handler.DynamicInvoke(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
using eShopOnContainers.Core;
|
using eShopOnContainers.Core;
|
||||||
using eShopOnContainers.Core.Services.Order;
|
using eShopOnContainers.Core.Services.Order;
|
||||||
using eShopOnContainers.Core.Services.RequestProvider;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -8,6 +7,15 @@ namespace eShopOnContainers.UnitTests
|
|||||||
{
|
{
|
||||||
public class OrdersServiceTests
|
public class OrdersServiceTests
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task GetFakeOrderTest()
|
||||||
|
{
|
||||||
|
var ordersMockService = new OrderMockService();
|
||||||
|
var order = await ordersMockService.GetOrderAsync(1, GlobalSetting.Instance.AuthToken);
|
||||||
|
|
||||||
|
Assert.NotNull(order);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetFakeOrdersTest()
|
public async Task GetFakeOrdersTest()
|
||||||
{
|
{
|
||||||
@ -16,15 +24,5 @@ namespace eShopOnContainers.UnitTests
|
|||||||
|
|
||||||
Assert.NotEqual(0, result.Count);
|
Assert.NotEqual(0, result.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetOrdersTest()
|
|
||||||
{
|
|
||||||
var requestProvider = new RequestProvider();
|
|
||||||
var ordersService = new OrderService(requestProvider);
|
|
||||||
var result = await ordersService.GetOrdersAsync(GlobalSetting.Instance.AuthToken);
|
|
||||||
|
|
||||||
Assert.NotEqual(0, result.Count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,248 @@
|
|||||||
|
using Xunit;
|
||||||
|
using eShopOnContainers.Core.ViewModels;
|
||||||
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
|
using eShopOnContainers.Core.Services.Catalog;
|
||||||
|
using eShopOnContainers.Core.Models.Catalog;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace eShopOnContainers.UnitTests
|
||||||
|
{
|
||||||
|
public class CatalogViewModelTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void AddCatalogItemCommandIsNotNullTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.NotNull(catalogViewModel.AddCatalogItemCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FilterCommandIsNotNullTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.NotNull(catalogViewModel.FilterCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ClearFilterCommandIsNotNullTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.NotNull(catalogViewModel.ClearFilterCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProductsPropertyIsNullWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.Null(catalogViewModel.Products);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BrandsPropertyuIsNullWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.Null(catalogViewModel.Brands);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BrandPropertyIsNullWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.Null(catalogViewModel.Brand);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TypesPropertyIsNullWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.Null(catalogViewModel.Types);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TypePropertyIsNullWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.Null(catalogViewModel.Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsFilterPropertyIsFalseWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Assert.False(catalogViewModel.IsFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ProductsPropertyIsNotNullAfterViewModelInitializationTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
|
||||||
|
Assert.NotNull(catalogViewModel.Products);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task BrandsPropertyIsNotNullAfterViewModelInitializationTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
|
||||||
|
Assert.NotNull(catalogViewModel.Brands);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task TypesPropertyIsNotNullAfterViewModelInitializationTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
|
||||||
|
Assert.NotNull(catalogViewModel.Types);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SettingProductsPropertyShouldRaisePropertyChanged()
|
||||||
|
{
|
||||||
|
bool invoked = false;
|
||||||
|
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
catalogViewModel.PropertyChanged += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName.Equals("Products"))
|
||||||
|
invoked = true;
|
||||||
|
};
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
|
||||||
|
Assert.True(invoked);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SettingBrandsPropertyShouldRaisePropertyChanged()
|
||||||
|
{
|
||||||
|
bool invoked = false;
|
||||||
|
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
catalogViewModel.PropertyChanged += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName.Equals("Brands"))
|
||||||
|
invoked = true;
|
||||||
|
};
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
|
||||||
|
Assert.True(invoked);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SettingTypesPropertyShouldRaisePropertyChanged()
|
||||||
|
{
|
||||||
|
bool invoked = false;
|
||||||
|
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
catalogViewModel.PropertyChanged += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName.Equals("Types"))
|
||||||
|
invoked = true;
|
||||||
|
};
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
|
||||||
|
Assert.True(invoked);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddCatalogItemCommandSendsAddProductMessageTest()
|
||||||
|
{
|
||||||
|
bool messageReceived = false;
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
Xamarin.Forms.MessagingCenter.Subscribe<CatalogViewModel, CatalogItem>(this, MessageKeys.AddProduct, (sender, arg) =>
|
||||||
|
{
|
||||||
|
messageReceived = true;
|
||||||
|
});
|
||||||
|
catalogViewModel.AddCatalogItemCommand.Execute(null);
|
||||||
|
|
||||||
|
Assert.True(messageReceived);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task FilterCommandSendsFilterMessageTest()
|
||||||
|
{
|
||||||
|
bool messageReceived = false;
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
catalogViewModel.Brand = catalogViewModel.Brands.FirstOrDefault();
|
||||||
|
catalogViewModel.Type = catalogViewModel.Types.FirstOrDefault();
|
||||||
|
|
||||||
|
Xamarin.Forms.MessagingCenter.Subscribe<CatalogViewModel>(this, MessageKeys.Filter, (sender) =>
|
||||||
|
{
|
||||||
|
messageReceived = true;
|
||||||
|
});
|
||||||
|
catalogViewModel.FilterCommand.Execute(null);
|
||||||
|
|
||||||
|
Assert.True(messageReceived);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ClearFilterCommandResetsPropertiesTest()
|
||||||
|
{
|
||||||
|
var catalogService = new CatalogMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var catalogViewModel = new CatalogViewModel(catalogService);
|
||||||
|
|
||||||
|
await catalogViewModel.InitializeAsync(null);
|
||||||
|
catalogViewModel.ClearFilterCommand.Execute(null);
|
||||||
|
|
||||||
|
Assert.Null(catalogViewModel.Brand);
|
||||||
|
Assert.Null(catalogViewModel.Type);
|
||||||
|
Assert.NotNull(catalogViewModel.Products);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
using Xunit;
|
||||||
|
using eShopOnContainers.Core.ViewModels;
|
||||||
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
|
using eShopOnContainers.Core.Models.Navigation;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace eShopOnContainers.UnitTests
|
||||||
|
{
|
||||||
|
public class MainViewModelTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void SettingsCommandIsNotNullWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var mainViewModel = new MainViewModel();
|
||||||
|
|
||||||
|
Assert.NotNull(mainViewModel.SettingsCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ViewModelInitializationSendsChangeTabMessageTest()
|
||||||
|
{
|
||||||
|
bool messageReceived = false;
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var mainViewModel = new MainViewModel();
|
||||||
|
var tabParam = new TabParameter { TabIndex = 2 };
|
||||||
|
|
||||||
|
Xamarin.Forms.MessagingCenter.Subscribe<MainViewModel, int>(this, MessageKeys.ChangeTab, (sender, arg) =>
|
||||||
|
{
|
||||||
|
messageReceived = true;
|
||||||
|
});
|
||||||
|
await mainViewModel.InitializeAsync(tabParam);
|
||||||
|
|
||||||
|
Assert.True(messageReceived);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsBusyPropertyIsFalseWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var mainViewModel = new MainViewModel();
|
||||||
|
Assert.False(mainViewModel.IsBusy);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task IsBusyPropertyIsTrueAfterViewModelInitializationTest()
|
||||||
|
{
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var mainViewModel = new MainViewModel();
|
||||||
|
|
||||||
|
await mainViewModel.InitializeAsync(null);
|
||||||
|
|
||||||
|
Assert.True(mainViewModel.IsBusy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
using Xunit;
|
||||||
|
using eShopOnContainers.Core;
|
||||||
|
using eShopOnContainers.Core.ViewModels;
|
||||||
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
|
using eShopOnContainers.Core.Services.Order;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace eShopOnContainers.UnitTests
|
||||||
|
{
|
||||||
|
public class OrderViewModelTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void OrderPropertyIsNullWhenViewModelInstantiatedTest()
|
||||||
|
{
|
||||||
|
var orderService = new OrderMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var orderViewModel = new OrderDetailViewModel(orderService);
|
||||||
|
|
||||||
|
Assert.Null(orderViewModel.Order);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task OrderPropertyIsNotNullAfterViewModelInitializationTest()
|
||||||
|
{
|
||||||
|
var orderService = new OrderMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var orderViewModel = new OrderDetailViewModel(orderService);
|
||||||
|
|
||||||
|
var order = await orderService.GetOrderAsync(1, GlobalSetting.Instance.AuthToken);
|
||||||
|
await orderViewModel.InitializeAsync(order);
|
||||||
|
|
||||||
|
Assert.NotNull(orderViewModel.Order);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SettingOrderPropertyShouldRaisePropertyChanged()
|
||||||
|
{
|
||||||
|
bool invoked = false;
|
||||||
|
|
||||||
|
var orderService = new OrderMockService();
|
||||||
|
ViewModelLocator.RegisterDependencies(true);
|
||||||
|
var orderViewModel = new OrderDetailViewModel(orderService);
|
||||||
|
|
||||||
|
orderViewModel.PropertyChanged += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.PropertyName.Equals("Order"))
|
||||||
|
invoked = true;
|
||||||
|
};
|
||||||
|
var order = await orderService.GetOrderAsync(1, GlobalSetting.Instance.AuthToken);
|
||||||
|
await orderViewModel.InitializeAsync(order);
|
||||||
|
|
||||||
|
Assert.True(invoked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -34,11 +34,15 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="BasketServiceTests.cs" />
|
|
||||||
<Compile Include="CatalogServiceTests.cs" />
|
|
||||||
<Compile Include="DummyTests.cs" />
|
|
||||||
<Compile Include="OrdersServiceTests.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Mocks\MockEventToCommandBehavior.cs" />
|
||||||
|
<Compile Include="Services\BasketServiceTests.cs" />
|
||||||
|
<Compile Include="Services\CatalogServiceTests.cs" />
|
||||||
|
<Compile Include="ViewModels\CatalogViewModelTests.cs" />
|
||||||
|
<Compile Include="ViewModels\MainViewModelTests.cs" />
|
||||||
|
<Compile Include="ViewModels\OrderViewModelTests.cs" />
|
||||||
|
<Compile Include="Services\OrdersServiceTests.cs" />
|
||||||
|
<Compile Include="Behaviors\EventToCommandBehaviorTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||||
@ -57,6 +61,15 @@
|
|||||||
<HintPath>..\..\..\..\packages\xunit.extensibility.execution.2.2.0-beta4-build3444\lib\netstandard1.0\xunit.execution.dotnet.dll</HintPath>
|
<HintPath>..\..\..\..\packages\xunit.extensibility.execution.2.2.0-beta4-build3444\lib\netstandard1.0\xunit.execution.dotnet.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Xamarin.Forms.Core">
|
||||||
|
<HintPath>..\..\..\..\packages\Xamarin.Forms.2.3.4.231\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Xamarin.Forms.Platform">
|
||||||
|
<HintPath>..\..\..\..\packages\Xamarin.Forms.2.3.4.231\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Platform.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Xamarin.Forms.Xaml">
|
||||||
|
<HintPath>..\..\..\..\packages\Xamarin.Forms.2.3.4.231\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Xaml.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
@ -68,6 +81,12 @@
|
|||||||
<Name>eShopOnContainers.Core</Name>
|
<Name>eShopOnContainers.Core</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Mocks\" />
|
||||||
|
<Folder Include="Services\" />
|
||||||
|
<Folder Include="ViewModels\" />
|
||||||
|
<Folder Include="Behaviors\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
@ -76,4 +95,5 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
|
<Import Project="..\..\..\..\packages\Xamarin.Forms.2.3.4.231\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\..\..\packages\Xamarin.Forms.2.3.4.231\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
||||||
</Project>
|
</Project>
|
@ -1,10 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="xunit" version="2.2.0-beta4-build3444" targetFramework="portable46-net451+win81" />
|
<package id="Xamarin.Forms" version="2.3.4.231" targetFramework="portable46-net451+win81" />
|
||||||
<package id="xunit.abstractions" version="2.0.1" targetFramework="portable46-net451+win81" />
|
<package id="xunit" version="2.2.0-beta4-build3444" targetFramework="portable-net451+win81" />
|
||||||
<package id="xunit.assert" version="2.2.0-beta4-build3444" targetFramework="portable46-net451+win81" />
|
<package id="xunit.abstractions" version="2.0.1" targetFramework="portable-net451+win81" requireReinstallation="True" />
|
||||||
<package id="xunit.core" version="2.2.0-beta4-build3444" targetFramework="portable46-net451+win81" />
|
<package id="xunit.assert" version="2.2.0-beta4-build3444" targetFramework="portable-net451+win81" requireReinstallation="True" />
|
||||||
<package id="xunit.extensibility.core" version="2.2.0-beta4-build3444" targetFramework="portable46-net451+win81" />
|
<package id="xunit.core" version="2.2.0-beta4-build3444" targetFramework="portable-net451+win81" requireReinstallation="True" />
|
||||||
<package id="xunit.extensibility.execution" version="2.2.0-beta4-build3444" targetFramework="portable46-net451+win81" />
|
<package id="xunit.extensibility.core" version="2.2.0-beta4-build3444" targetFramework="portable-net451+win81" requireReinstallation="True" />
|
||||||
<package id="xunit.runner.console" version="2.2.0-beta4-build3444" targetFramework="portable46-net451+win81" developmentDependency="true" />
|
<package id="xunit.extensibility.execution" version="2.2.0-beta4-build3444" targetFramework="portable-net451+win81" requireReinstallation="True" />
|
||||||
|
<package id="xunit.runner.console" version="2.2.0-beta4-build3444" targetFramework="portable-net451+win81" developmentDependency="true" />
|
||||||
</packages>
|
</packages>
|
Loading…
x
Reference in New Issue
Block a user