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

Commit d3b511d

Browse files
Fix Unit Tests (#1036)
* Enable Nullable on Unit Tests * Enable Nullable on Xamarin.CommunityToolkit.Markup * Enable Nullable on Xamarin.CommunityToolkit.Sample * Enable Nullable on Android, GTK, iOS and Tizen Samples * Enable Nullable for UWP & WPF Sample Projects * Add Nullability * Resolve Possible Null References * Removed Possible Null References * Update AppResources.Designer.cs * Handle Nullability * Updated Nullabiltiy * Update Converters & Unit Tests * Resolve MediaSource Unit Tests * Fix VariableMultiValueConverter * Fixed ImpliedOrderGridBehavior * Update NumericValidationBehavior.shared.cs
1 parent 11dd05b commit d3b511d

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Behaviors/ImpliedOrderGridBehavior.shared.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Xamarin.CommunityToolkit.Behaviors
1111
/// </summary>
1212
public class ImpliedOrderGridBehavior : BaseBehavior<Grid>
1313
{
14+
bool[][]? usedMatrix;
1415
int rowCount;
1516
int columnCount;
1617

@@ -51,21 +52,24 @@ bool[][] InitMatrix()
5152
rowCount = View.RowDefinitions.Count;
5253
if (rowCount == 0)
5354
rowCount = 1;
55+
5456
columnCount = View.ColumnDefinitions.Count;
5557
if (columnCount == 0)
5658
columnCount = 1;
59+
5760
var newMatrix = new bool[rowCount][];
5861
for (var r = 0; r < rowCount; r++)
5962
newMatrix[r] = new bool[columnCount];
63+
6064
return newMatrix;
6165
}
6266

63-
void FindNextCell(out int rowIndex, out int columnIndex, out bool[][] matrix)
67+
void FindNextCell(out int rowIndex, out int columnIndex)
6468
{
65-
matrix = InitMatrix();
69+
usedMatrix ??= InitMatrix();
6670

6771
// Find the first available row
68-
var row = matrix.FirstOrDefault(r => r.Any(c => !c));
72+
var row = usedMatrix.FirstOrDefault(r => r.Any(c => !c));
6973

7074
// If no row is found, set cell to origin and log
7175
if (row == null)
@@ -75,13 +79,13 @@ void FindNextCell(out int rowIndex, out int columnIndex, out bool[][] matrix)
7579
columnIndex = Math.Max(columnCount - 1, 0);
7680
return;
7781
}
78-
rowIndex = matrix.IndexOf(row);
82+
rowIndex = usedMatrix.IndexOf(row);
7983

8084
// Find the first available column
8185
columnIndex = row.IndexOf(row.FirstOrDefault(c => !c));
8286
}
8387

84-
void UpdateUsedCells(int row, int column, int rowSpan, int columnSpan, bool[][] usedMatrix)
88+
void UpdateUsedCells(int row, int column, int rowSpan, int columnSpan)
8589
{
8690
var rowEnd = row + rowSpan;
8791
var columnEnd = column + columnSpan;
@@ -102,8 +106,9 @@ void UpdateUsedCells(int row, int column, int rowSpan, int columnSpan, bool[][]
102106
{
103107
for (var c = column; c < columnEnd; c++)
104108
{
105-
if (usedMatrix[r][c])
109+
if (usedMatrix?[r][c] ?? throw new NullReferenceException())
106110
LogWarning($"Cell at row {r} column {c} has already been used.");
111+
107112
usedMatrix[r][c] = true;
108113
}
109114
}
@@ -114,15 +119,15 @@ void ProcessElement(BindableObject view)
114119
var columnSpan = Grid.GetColumnSpan(view);
115120
var rowSpan = Grid.GetRowSpan(view);
116121

117-
FindNextCell(out var row, out var column, out var usedMatrix);
122+
FindNextCell(out var row, out var column);
118123

119124
// Check to see if the user manually assigned a row or column
120125
if (view.IsSet(Grid.ColumnProperty))
121126
column = Grid.GetColumn(view);
122127
if (view.IsSet(Grid.RowProperty))
123128
row = Grid.GetRow(view);
124129

125-
UpdateUsedCells(row, column, rowSpan, columnSpan, usedMatrix);
130+
UpdateUsedCells(row, column, rowSpan, columnSpan);
126131

127132
// Set attributes
128133
view.SetValue(Grid.ColumnProperty, column);

src/CommunityToolkit/Xamarin.CommunityToolkit/Behaviors/Validators/NumericValidationBehavior.shared.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ public int MaximumDecimalPlaces
7878
protected override ValueTask<bool> ValidateAsync(object? value, CancellationToken token)
7979
{
8080
if (value is not string valueString)
81-
throw new ArgumentException($"Expected type string for parameter {nameof(value)}");
81+
return new ValueTask<bool>(false);
8282

8383
if (!(double.TryParse(valueString, out var numeric)
84-
&& numeric >= MinimumValue
85-
&& numeric <= MaximumValue))
84+
&& numeric >= MinimumValue
85+
&& numeric <= MaximumValue))
86+
{
8687
return new ValueTask<bool>(false);
88+
}
8789

8890
var decimalDelimeterIndex = valueString.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
8991
var hasDecimalDelimeter = decimalDelimeterIndex >= 0;

src/CommunityToolkit/Xamarin.CommunityToolkit/Converters/VariableMultiValueConverter.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public object Convert(object[]? values, Type targetType, object? parameter, Cult
4141
if (boolValues.Length != values.Length)
4242
return false;
4343

44-
var count = boolValues.Count();
44+
var count = boolValues.Count(v => v);
4545

4646
return ConditionType switch
4747
{

0 commit comments

Comments
 (0)