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

Rename IsNullOrEmptyConverter to IsStringNullOrEmptyConverter #289

Merged
merged 7 commits into from
Feb 11, 2022
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
4 changes: 2 additions & 2 deletions samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public partial class AppShell : Shell
{ typeof(InvertedBoolConverterViewModel), (typeof(ConvertersGalleryPage), typeof(InvertedBoolConverterPage)) },
{ typeof(IsListNotNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsListNotNullOrEmptyConverterPage)) },
{ typeof(IsListNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsListNullOrEmptyConverterPage)) },
{ typeof(IsNotNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsNotNullOrEmptyConverterPage)) },
{ typeof(IsNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsNullOrEmptyConverterPage)) },
{ typeof(IsStringNotNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsStringNotNullOrEmptyConverterPage)) },
{ typeof(IsStringNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsStringNullOrEmptyConverterPage)) },
{ typeof(ItemSelectedEventArgsConverterViewModel), (typeof(ConvertersGalleryPage), typeof(ItemSelectedEventArgsConverterPage)) },
{ typeof(ItemTappedEventArgsConverterViewModel), (typeof(ConvertersGalleryPage), typeof(ItemTappedEventArgsConverterPage)) },
{ typeof(ListToStringConverterViewModel), (typeof(ConvertersGalleryPage), typeof(ListToStringConverterPage)) },
Expand Down
4 changes: 2 additions & 2 deletions samples/CommunityToolkit.Maui.Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static MauiApp CreateMauiApp()
builder.Services.AddTransient<EqualConverterViewModel>();
builder.Services.AddTransient<IndexToArrayItemConverterViewModel>();
builder.Services.AddTransient<IntToBoolConverterViewModel>();
builder.Services.AddTransient<IsNotNullOrEmptyConverterViewModel>();
builder.Services.AddTransient<IsNullOrEmptyConverterViewModel>();
builder.Services.AddTransient<IsStringNotNullOrEmptyConverterViewModel>();
builder.Services.AddTransient<IsStringNullOrEmptyConverterViewModel>();
builder.Services.AddTransient<ItemSelectedEventArgsConverterViewModel>();
builder.Services.AddTransient<ItemTappedEventArgsConverterViewModel>();
builder.Services.AddTransient<IsListNotNullOrEmptyConverterViewModel>();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<pages:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Converters"
x:Class="CommunityToolkit.Maui.Sample.Pages.Converters.IsStringNotNullOrEmptyConverterPage"
x:TypeArguments="vm:IsStringNotNullOrEmptyConverterViewModel">

<pages:BasePage.Resources>
<ResourceDictionary>
<mct:IsStringNotNullOrEmptyConverter x:Key="IsStringNotNullOrEmptyConverter" />
</ResourceDictionary>
</pages:BasePage.Resources>

<pages:BasePage.Content>
<VerticalStackLayout
Padding="10,10"
HorizontalOptions="Fill"
Spacing="16"
VerticalOptions="Fill">

<Label Text="The IsStringNotNullOrEmptyConverter is a converter that allows users to convert an incoming string binding to a bool value. This value represents if the incoming string binding value is not null or empty using string.IsNullOrEmpty." TextColor="{StaticResource NormalLabelTextColor}" />

<Label Text="Enter text into the Entry, below. If the text is not null or empty, the value will be true." TextColor="{StaticResource NormalLabelTextColor}" FontAttributes="Bold"/>

<Entry VerticalOptions="CenterAndExpand" HorizontalOptions="Fill" Text="{Binding Path=LabelText, Mode=OneWayToSource}" TextColor="{StaticResource NormalLabelTextColor}" />

<Label VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Text="{Binding Path=LabelText, Mode=OneWay, Converter={StaticResource IsStringNotNullOrEmptyConverter}}" />

</VerticalStackLayout>
</pages:BasePage.Content>

</pages:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CommunityToolkit.Maui.Sample.ViewModels.Converters;

namespace CommunityToolkit.Maui.Sample.Pages.Converters;

public partial class IsStringNotNullOrEmptyConverterPage : BasePage<IsStringNotNullOrEmptyConverterViewModel>
{
public IsStringNotNullOrEmptyConverterPage(IsStringNotNullOrEmptyConverterViewModel isStringNotNullOrEmptyConverterViewModel)
: base(isStringNotNullOrEmptyConverterViewModel)
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<pages:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Converters"
x:Class="CommunityToolkit.Maui.Sample.Pages.Converters.IsStringNullOrEmptyConverterPage"
x:TypeArguments="vm:IsStringNullOrEmptyConverterViewModel">

<pages:BasePage.Resources>
<ResourceDictionary>
<mct:IsStringNullOrEmptyConverter x:Key="IsStringNullOrEmptyConverter" />
</ResourceDictionary>
</pages:BasePage.Resources>

<pages:BasePage.Content>
<VerticalStackLayout
Padding="10,10"
HorizontalOptions="Fill"
Spacing="16"
VerticalOptions="Fill">

<Label Text="The IsStringNullOrEmptyConverter is a converter that allows usersc to convert an incoming string binding to a bool value. This value represents if the incoming string binding value is null or empty using string.IsNullOrEmpty." TextColor="{StaticResource NormalLabelTextColor}" />

<Label Text="Enter text into the Entry, below. If the text is null or empty, the value will be true." TextColor="{StaticResource NormalLabelTextColor}" FontAttributes="Bold" />

<Entry VerticalOptions="CenterAndExpand" HorizontalOptions="Fill" Text="{Binding Path=LabelText, Mode=OneWayToSource}" TextColor="{StaticResource NormalLabelTextColor}" />

<Label VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Text="{Binding Path=LabelText, Mode=OneWay, Converter={StaticResource IsStringNullOrEmptyConverter}}" />

</VerticalStackLayout>
</pages:BasePage.Content>

</pages:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CommunityToolkit.Maui.Sample.ViewModels.Converters;

namespace CommunityToolkit.Maui.Sample.Pages.Converters;

public partial class IsStringNullOrEmptyConverterPage : BasePage<IsStringNullOrEmptyConverterViewModel>
{
public IsStringNullOrEmptyConverterPage(IsStringNullOrEmptyConverterViewModel isStringNullOrEmptyConverterViewModel)
: base(isStringNullOrEmptyConverterViewModel)
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public ConvertersGalleryViewModel()
SectionModel.Create<BoolToObjectConverterViewModel>(nameof(BoolToObjectConverter),
"A converter that allows users to convert a bool value binding to a specific object."),

SectionModel.Create<IsNullOrEmptyConverterViewModel>(nameof(IsNullOrEmptyConverter),
SectionModel.Create<IsStringNullOrEmptyConverterViewModel>(nameof(IsStringNullOrEmptyConverter),
"A converter that allows users to convert an incoming binding to a bool value. This value represents if the incoming binding value is null or empty."),

SectionModel.Create<IsNotNullOrEmptyConverterViewModel>(nameof(IsNotNullOrEmptyConverter),
SectionModel.Create<IsStringNotNullOrEmptyConverterViewModel>(nameof(IsStringNotNullOrEmptyConverter),
"A converter that allows users to convert an incoming binding to a bool value. This value represents if the incoming binding value is Not null or empty."),

SectionModel.Create<InvertedBoolConverterViewModel>(nameof(InvertedBoolConverter),
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Windows.Input;

namespace CommunityToolkit.Maui.Sample.ViewModels.Converters;

public class IsStringNotNullOrEmptyConverterViewModel : BaseViewModel
{
string? labelText;

public string? LabelText
{
get => labelText;
set => SetProperty(ref labelText, value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Windows.Input;

namespace CommunityToolkit.Maui.Sample.ViewModels.Converters;

public class IsStringNullOrEmptyConverterViewModel : BaseViewModel
{
string? labelText;

public string? LabelText
{
get => labelText;
set => SetProperty(ref labelText, value);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Globalization;
using CommunityToolkit.Maui.Converters;
using Xunit;

namespace CommunityToolkit.Maui.UnitTests.Converters;

public class IsStringNotNullOrEmptyConverter_Tests : BaseTest
{
[Theory]
[InlineData("Test", true)]
[InlineData(null, false)]
[InlineData("", false)]
[InlineData(" ", true)]
public void IsNotNullOrEmptyConverter_ValidStringValue(string? value, bool expectedResult)
{
var isNotNullOrEmptyConverter = new IsStringNotNullOrEmptyConverter();

var result = (bool)isNotNullOrEmptyConverter.Convert(value, null, null, null);

Assert.Equal(expectedResult, result);
brminnick marked this conversation as resolved.
Show resolved Hide resolved
}

[Theory]
[InlineData(17)]
[InlineData(true)]
[InlineData('c')]
public void IsNotNullOrEmptyConverter_InvalidValue(object value)
{
var isNotNullOrEmptyConverter = new IsStringNotNullOrEmptyConverter();

Assert.Throws<InvalidCastException>(() => isNotNullOrEmptyConverter.Convert(value, null, null, null));
}
}
Loading