Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit fafe506

Browse files
committed
Add test
1 parent a004f08 commit fafe506

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<pages:BasePage
3+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.TestCases.SnackBarActionExceptionPage"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages">
7+
8+
<ContentPage.Content>
9+
<Grid RowDefinitions="auto, *, *">
10+
<Button Text="App shouldn't crash when you press this and execute action." Clicked="ShowSnackBar" />
11+
</Grid>
12+
</ContentPage.Content>
13+
14+
</pages:BasePage>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using Xamarin.CommunityToolkit.Extensions;
3+
4+
namespace Xamarin.CommunityToolkit.Sample.Pages.TestCases
5+
{
6+
public partial class SnackBarActionExceptionPage
7+
{
8+
public SnackBarActionExceptionPage() => InitializeComponent();
9+
10+
async void ShowSnackBar(object sender, EventArgs e)
11+
{
12+
try
13+
{
14+
await this.DisplaySnackBarAsync("Execute action to throw exception", "Throw exception", () => throw new Exception());
15+
}
16+
catch
17+
{
18+
await this.DisplayToastAsync("Exception caught");
19+
}
20+
}
21+
}
22+
}

samples/XCT.Sample/ViewModels/TestCases/TestCasesGalleryViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
1111
new SectionModel(
1212
typeof(TouchEffectButtonPage),
1313
"TouchEffect + Button",
14-
"TouchEffect must automatically invoke button'c command execution."),
14+
"TouchEffect must automatically invoke button's command execution."),
1515

1616
new SectionModel(
1717
typeof(TouchEffectCollectionViewPage),
@@ -27,6 +27,11 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
2727
typeof(TabViewBindingPage),
2828
"TabView BindingContext",
2929
"TabView with BindingContext into MainPage and other BindingContext into TabViewItem."),
30+
31+
new SectionModel(
32+
typeof(SnackBarActionExceptionPage),
33+
"SnackBar Action Exception",
34+
"Exception in SnackBar's action doesn't crash the app."),
3035
};
3136
}
3237
}

samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25+
<Compile Update="Pages\TestCases\SnackBarActionExceptionPage.xaml.cs">
26+
<DependentUpon>SnackBarActionExceptionPage.xaml</DependentUpon>
27+
</Compile>
2528
<Compile Update="Pages\TestCases\TabViewItemBindingView.xaml.cs">
2629
<DependentUpon>TabViewItemBindingView.xaml</DependentUpon>
2730
</Compile>

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Snackbar/Options/ToastOptions.shared.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class ToastOptions
4444
/// </summary>
4545
public TaskCompletionSource<bool> Result { get; }
4646

47-
public void SetResult(bool result) => Result.SetResult(result);
47+
public bool SetResult(bool result) => Result.TrySetResult(result);
4848

49-
public void SetException(Exception exception) => Result.SetException(exception);
49+
public bool SetException(Exception exception) => Result.TrySetException(exception);
5050
}
5151
}

0 commit comments

Comments
 (0)