Skip to content

Commit 2578bc0

Browse files
authored
Merge pull request dotnet-architecture#176 from dotnet-architecture/xamarin
Unit tests
2 parents 8784653 + dfe4588 commit 2578bc0

25 files changed

Lines changed: 701 additions & 94 deletions

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/EventToCommandBehavior.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class EventToCommandBehavior : BindableBehavior<View>
3131
BindableProperty.CreateAttached("EventArgsConverterParameter", typeof(object), typeof(EventToCommandBehavior), null,
3232
BindingMode.OneWay);
3333

34-
private Delegate _handler;
34+
protected Delegate _handler;
3535
private EventInfo _eventInfo;
3636

3737
public string EventName

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Basket/BasketService.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public BasketService(IRequestProvider requestProvider)
1616
}
1717

1818
public async Task<CustomerBasket> GetBasketAsync(string guidUser, string token)
19-
{
20-
19+
{
2120
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint);
2221

2322
builder.Path = guidUser;
@@ -30,18 +29,17 @@ public async Task<CustomerBasket> GetBasketAsync(string guidUser, string token)
3029
ServicesHelper.FixBasketItemPictureUri(basket?.Items);
3130

3231
return basket;
33-
3432
}
3533

3634
public async Task<CustomerBasket> UpdateBasketAsync(CustomerBasket customerBasket, string token)
3735
{
38-
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint);
36+
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint);
3937

40-
string uri = builder.ToString();
38+
string uri = builder.ToString();
4139

42-
var result = await _requestProvider.PostAsync(uri, customerBasket, token);
40+
var result = await _requestProvider.PostAsync(uri, customerBasket, token);
4341

44-
return result;
42+
return result;
4543
}
4644

4745
public async Task ClearBasketAsync(string guidUser, string token)

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogMockService.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,5 @@ public async Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync()
6161

6262
return MockCatalogType;
6363
}
64-
65-
public async Task<CatalogItem> GetCatalogItemAsync(string id)
66-
{
67-
await Task.Delay(500);
68-
69-
return MockCatalog.FirstOrDefault(c => c.Id == id);
70-
}
7164
}
7265
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/CatalogService.cs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public CatalogService(IRequestProvider requestProvider)
2020

2121
public async Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId)
2222
{
23-
2423
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);
2524

2625
builder.Path = string.Format("api/v1/catalog/items/type/{0}/brand/{1}", catalogTypeId, catalogBrandId);
@@ -34,12 +33,10 @@ public async Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBran
3433
return catalog?.Data.ToObservableCollection();
3534
else
3635
return new ObservableCollection<CatalogItem>();
37-
3836
}
3937

4038
public async Task<ObservableCollection<CatalogItem>> GetCatalogAsync()
4139
{
42-
4340
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);
4441

4542
builder.Path = "api/v1/catalog/items";
@@ -56,37 +53,28 @@ public async Task<ObservableCollection<CatalogItem>> GetCatalogAsync()
5653
return catalog?.Data.ToObservableCollection();
5754
}
5855
else
59-
return new ObservableCollection<CatalogItem>();
60-
61-
}
62-
63-
public Task<CatalogItem> GetCatalogItemAsync(string id)
64-
{
65-
throw new NotImplementedException();
56+
return new ObservableCollection<CatalogItem>();
6657
}
6758

6859
public async Task<ObservableCollection<CatalogBrand>> GetCatalogBrandAsync()
6960
{
61+
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);
7062

71-
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);
72-
73-
builder.Path = "api/v1/catalog/catalogbrands";
74-
75-
string uri = builder.ToString();
63+
builder.Path = "api/v1/catalog/catalogbrands";
7664

77-
IEnumerable<CatalogBrand> brands =
78-
await _requestProvider.GetAsync<IEnumerable<CatalogBrand>>(uri);
65+
string uri = builder.ToString();
7966

80-
if (brands != null)
81-
return brands?.ToObservableCollection();
82-
else
83-
return new ObservableCollection<CatalogBrand>();
67+
IEnumerable<CatalogBrand> brands =
68+
await _requestProvider.GetAsync<IEnumerable<CatalogBrand>>(uri);
8469

70+
if (brands != null)
71+
return brands?.ToObservableCollection();
72+
else
73+
return new ObservableCollection<CatalogBrand>();
8574
}
8675

8776
public async Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync()
8877
{
89-
9078
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);
9179

9280
builder.Path = "api/v1/catalog/catalogtypes";
@@ -99,8 +87,7 @@ public async Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync()
9987
if (types != null)
10088
return types.ToObservableCollection();
10189
else
102-
return new ObservableCollection<CatalogType>();
103-
90+
return new ObservableCollection<CatalogType>();
10491
}
10592
}
10693
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Catalog/ICatalogService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ public interface ICatalogService
1010
Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId);
1111
Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync();
1212
Task<ObservableCollection<CatalogItem>> GetCatalogAsync();
13-
Task<CatalogItem> GetCatalogItemAsync(string id);
1413
}
1514
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/CatalogViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using eShopOnContainers.Core.Models.Catalog;
66
using eShopOnContainers.Core.Services.Catalog;
77
using System.Windows.Input;
8-
using eShopOnContainers.Core.Services.Basket;
9-
using eShopOnContainers.Core.Services.User;
108

119
namespace eShopOnContainers.Core.ViewModels
1210
{

src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/MainActivity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected override void OnCreate(Bundle bundle)
1414
AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);
1515

1616
// or in any reference assemblies getting the Assembly from any type/class
17-
AddTestAssembly(typeof(UnitTests.DummyTests).Assembly);
17+
AddTestAssembly(typeof(UnitTests.CatalogViewModelTests).Assembly);
1818

1919
base.OnCreate(bundle);
2020
}

src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
2121
<NuGetPackageImportStamp>
2222
</NuGetPackageImportStamp>
23+
<AndroidTlsProvider></AndroidTlsProvider>
2324
</PropertyGroup>
2425
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2526
<DebugSymbols>true</DebugSymbols>

src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Windows/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protected override void OnInitializeRunner()
1212
{
1313
// Otherwise you need to ensure that the test assemblies will
1414
// become part of the app bundle
15-
AddTestAssembly(typeof(UnitTests.DummyTests).GetTypeInfo().Assembly);
15+
AddTestAssembly(typeof(UnitTests.CatalogViewModelTests).GetTypeInfo().Assembly);
1616
}
1717
}
1818
}

src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.iOS/AppDelegate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
1717

1818
// Otherwise you need to ensure that the test assemblies will
1919
// become part of the app bundle
20-
AddTestAssembly(typeof(UnitTests.DummyTests).Assembly);
20+
AddTestAssembly(typeof(UnitTests.CatalogViewModelTests).Assembly);
2121

2222
return base.FinishedLaunching(app, options);
2323
}

0 commit comments

Comments
 (0)